wangguan
2020-12-10 5f6fb6dccd1330b5b0bcb2d721167a6ac062f3ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using Core.Health;
using UnityEngine;
 
namespace ActionGameFramework.Health
{
    /// <summary>
    /// A simple class for identifying enemies
    /// </summary>
    public class Targetable : DamageableBehaviour
    {
        /// <summary>
        /// The transform that will be targeted
        /// </summary>
        public Transform targetTransform;
 
        /// <summary>
        /// The position of the object
        /// </summary>
        protected Vector3 m_CurrentPosition, m_PreviousPosition;
 
        /// <summary>
        /// The velocity of the rigidbody
        /// </summary>
        public virtual Vector3 velocity { get; protected set; }
 
        /// <summary>
        /// 用于确认具体是哪一方的Agent.
        /// </summary>
        public bool opponentAgent { set; get; }
 
        /// <summary>
        /// The transform that objects target, which falls back to this object's transform if not set
        /// </summary>
        public Transform targetableTransform
        {
            get
            {
                return targetTransform == null ? transform : targetTransform;
            }
        }
 
        /// <summary>
        /// Returns our targetable's transform position
        /// </summary>
        public override Vector3 position
        {
            get { return targetableTransform.position; }
        }
 
        protected int mLiveID = 0;
        /// <summary>
        /// 用于判断延迟攻击的时候,是否是同一个Agent.
        /// </summary>
        public int liveID
        {
            protected set
            {
                mLiveID = value;
            }
            get { return this.mLiveID; }
        }
 
        /// <summary>
        /// Initialises any DamageableBehaviour logic
        /// </summary>
        protected override void Awake()
        {
            base.Awake();
            ResetPositionData();
        }
 
        /// <summary>
        /// Sets up the position data so velocity can be calculated
        /// </summary>
        protected void ResetPositionData()
        {
            m_CurrentPosition = position;
            m_PreviousPosition = position;
        }
 
        /// <summary>
        /// Calculates the velocity and updates the position
        /// </summary>
        void FixedUpdate()
        {
            m_CurrentPosition = position;
            velocity = (m_CurrentPosition - m_PreviousPosition) / Time.fixedDeltaTime;
            m_PreviousPosition = m_CurrentPosition;
        }
    }
}