using System; using UnityEngine; public class TurnOff_GO : MyCoroutine { public bool NoUseParticleTime = false; public float OffTime = 5f; public Vector3 add_offset; public eEffectLocation e_EffectLocation; public Transform tf_Target; public Action act_End; Actor m_target, m_target2; ProjectileData m_ProjectileData; bool followTarget; public void Set() { gameObject.SetActive(false); gameObject.SetActive(true); } public void Set(Actor target, ProjectileData pd, float LifeTime) { followTarget = true; m_target = target; m_ProjectileData = pd; NoUseParticleTime = true; OffTime = LifeTime; transform.position = m_ProjectileData.Get_EffectPos(target); gameObject.SetActive(true); Set_Off(); } public void Set(Actor target, eEffectLocation loca, float lifetime) { m_target2 = target; e_EffectLocation = loca; OffTime = lifetime; gameObject.SetActive(true); Set_Off(); } public void Set_PrefabInfo(Actor target) { Set_Location(target); gameObject.SetActive(true); Set_Off(); } void Set_Off() { Set_Coroutine_withCancel(() => { gameObject.SetActive(false); act_End?.Invoke(); }, NoUseParticleTime ? OffTime : GetComponent().main.duration); } private void OnEnable() { Set_Off(); } protected override void Update() { if (followTarget) { if (DSUtil.CheckNull(m_target)) { transform.position = Vector3.right * 1000000f; gameObject.SetActive(false); } else { var pos = m_ProjectileData.Get_EffectPos(m_target); transform.position = pos; } } else if (!DSUtil.CheckNull(tf_Target)) transform.position = tf_Target.position + add_offset; else if (!DSUtil.CheckNull(m_target2)) Set_Location(m_target2); } void Set_Location(Actor target) { Vector3 effectPos; switch (e_EffectLocation) { case eEffectLocation.Top: effectPos = target.Get_Top_postion(); break; default: effectPos = target.Get_Center_position(); break; case eEffectLocation.Bottom: effectPos = target.Get_position(); break; } transform.position = effectPos; } }