using Core.Utilities; using UnityEngine; namespace Core.Health { /// /// Simple class to instantiate a ParticleSystem on a given Damageable's death /// 这个类只有一个功能,播放死亡特效。 /// 这个类的函数附加到Damageable的died Action上. /// public class DeathEffect : MonoBehaviour { /// /// The DamageableBehaviour that will be used to assign the damageable /// [Tooltip("This field does not need to be populated here, it can be set up in code using AssignDamageable")] public DamageableBehaviour damageableBehaviour; /// /// Death particle system /// public ParticleSystem deathParticleSystemPrefab; /// /// World space offset of the position /// public Vector3 deathEffectOffset; /// /// The damageable /// protected Damageable m_Damageable; /// /// Subscribes to the damageable's died event /// /// public void AssignDamageable(Damageable damageable) { if (m_Damageable != null) { m_Damageable.died -= OnDied; } m_Damageable = damageable; m_Damageable.died += OnDied; } /// /// If damageableBehaviour is populated, assigns the damageable /// protected virtual void Awake () { if (damageableBehaviour != null) { AssignDamageable(damageableBehaviour.configuration); } } /// /// Instantiate a death particle system /// void OnDied(HealthChangeInfo healthChangeInfo) { if (deathParticleSystemPrefab == null) { return; } var pfx = Poolable.TryGetPoolable(deathParticleSystemPrefab.gameObject); pfx.transform.position = transform.position + deathEffectOffset; // TEST CODE TO DELTE: ATTENTION TO OPP: 加入更加成熟的机制来加强效果: //pfx.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); pfx.Simulate(1.2f); // TEST CODE TO DELETE: pfx.Play(); } } }