using System.Reflection; using System; using System.Collections; using System.Collections.Generic; using DragonLi.Frame; using Mirror; using Pathfinding; using UnityEngine; public class Agent : NetworkBehaviour, IDamagable { [Header("当前血量")] #if UNITY_EDITOR [DisplayOnly] #endif [SyncVar] public float health = 0f; [Header("原始血量")] #if UNITY_EDITOR [DisplayOnly] #endif [SyncVar] 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; } } /// /// This will be called every frame /// public virtual void OnUpdate() { } /// /// On entity enable, this will be called when entity was being spawned. /// [Server] public virtual void OnSpawn() { OnBorn(); } /// /// When this entity has been born /// public virtual void OnBorn() { } /// /// When agent receives damage this function will be called /// If you want to re calculate damage you can do it here. /// /// How much /// Some information about this damage you want to tell damage receiver /// Who take this damage /// public virtual float OnReceiveDamage(float value, object info, Transform _sender) { return value; } /// /// When health changed this function will be called /// /// current health public virtual void OnHeathChanged(float currentHealth) { } /// /// Add damage /// /// How much /// Some information about this damage you want to tell damage receiver /// Who take this damage [Server] public virtual void ApplyDamage(float value, object info, Transform _sender) { // Debug.Log("造成伤害" + value); if (IsAlive) { Health -= OnReceiveDamage(value, info, _sender); if (!IsAlive) { Die(info, _sender); } } } /// /// Let this entity die, and tell task system. /// public virtual void Die(object info, Transform _sender) { OnDeath(info, _sender); } /// /// On entity die, this will be called, you can write despawn functions here. /// public virtual void OnDeath(object info, Transform _sender) { } }