using Core.Health;
using UnityEngine;
namespace ActionGameFramework.Health
{
///
/// A simple class for identifying enemies
///
public class Targetable : DamageableBehaviour
{
///
/// The transform that will be targeted
///
public Transform targetTransform;
///
/// The position of the object
///
protected Vector3 m_CurrentPosition, m_PreviousPosition;
///
/// The velocity of the rigidbody
///
public virtual Vector3 velocity { get; protected set; }
///
/// 用于确认具体是哪一方的Agent.
///
public bool opponentAgent { set; get; }
///
/// The transform that objects target, which falls back to this object's transform if not set
///
public Transform targetableTransform
{
get
{
return targetTransform == null ? transform : targetTransform;
}
}
///
/// Returns our targetable's transform position
///
public override Vector3 position
{
get { return targetableTransform.position; }
}
protected int mLiveID = 0;
///
/// 用于判断延迟攻击的时候,是否是同一个Agent.
///
public int liveID
{
protected set
{
mLiveID = value;
}
get { return this.mLiveID; }
}
///
/// Initialises any DamageableBehaviour logic
///
protected override void Awake()
{
base.Awake();
ResetPositionData();
}
///
/// Sets up the position data so velocity can be calculated
///
protected void ResetPositionData()
{
m_CurrentPosition = position;
m_PreviousPosition = position;
}
///
/// Calculates the velocity and updates the position
///
void FixedUpdate()
{
m_CurrentPosition = position;
velocity = (m_CurrentPosition - m_PreviousPosition) / Time.fixedDeltaTime;
m_PreviousPosition = m_CurrentPosition;
}
}
}