using System.Reflection; using System; using System.Collections; using System.Collections.Generic; using DragonLi.Frame; using Mirror; using Pathfinding; using UnityEngine; public class Agent : MonoBehaviour, Damagable { [Header("当前血量")] #if UNITY_EDITOR [DisplayOnly] #endif public float health = 0f; [Header("原始血量")] #if UNITY_EDITOR [DisplayOnly] #endif public float originHealth = 0f; /// /// 血量 /// public float Health { get { return health; } set { health = value; health = Mathf.Clamp(health, 0f, originHealth); OnHeathChanged(health); } } /// /// 是否存活 /// public bool isAlive => Health > 0f; private Animator animatorComponent; /// /// 动画组件 /// public Animator AnimatorComponent { get { if (animatorComponent == null) { animatorComponent = GetComponentInChildren(); } return animatorComponent; } } private Collider colliderComponent; /// /// 碰撞组件 /// public Collider ColliderComponent { get { if (colliderComponent == null) { colliderComponent = GetComponentInChildren(); } return colliderComponent; } } private Rigidbody rigidbodyComponent; /// /// 刚体组件 /// public Rigidbody RigidbodyComponent { get { if (rigidbodyComponent == null) { rigidbodyComponent = GetComponentInChildren(); } return rigidbodyComponent; } } public virtual void OnUpdate() { } public virtual void OnSpawn() { OnBorn(); } public virtual void OnBorn() { } public virtual float OnReceiveDamage(float value, int ownerIndex, Vector3 hitPos, Transform _sender) { return value; } public virtual void OnHeathChanged(float currentHealth) { } public virtual void ApplyDamage(float value, int ownerIndex, Vector3 hitPos, Transform sender) { // Debug.Log("造成伤害" + value); if (isAlive) { Health -= OnReceiveDamage(value, ownerIndex, hitPos, sender); if (!isAlive) { Die(ownerIndex, sender); } } } public virtual void Die(object info, Transform sender) { OnDeath(info, sender); } public virtual void OnDeath(object info, Transform sender) { } }