using System; using UnityEngine; public class TurnOff_GO : MyCoroutine { public bool NoUseParticleTime = false; public float OffTime = 5f; public eEffectLocation e_EffectLocation; public Action act_End; Actor m_target, m_target2; ProjectileData m_ProjectileData; bool followTarget, isPS; ParticleSystem m_PS; string showEffectwhenOff; private void Awake() { m_PS = GetComponent(); isPS = m_PS; } 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(); } public void Reset_Time(float time) { OffTime = time; Set_Off(); } public bool IsMyEffect(Actor actor) { if (m_target2 == actor) return true; return false; } public void Set_EffectwhenOff(string effect) { showEffectwhenOff = effect; } void Set_Off() { Set_Coroutine_withCancel(Off_Imm, NoUseParticleTime || !isPS ? OffTime : m_PS.main.duration); } private void OnEnable() { Set_Off(); } void Update() { if (followTarget) { if (m_target) transform.position = m_ProjectileData.Get_EffectPos(m_target); else { transform.position = Vector3.right * 1000000f; gameObject.SetActive(false); } } else if (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; } public void Off_Imm() { gameObject.SetActive(false); act_End?.Invoke(); if (!string.IsNullOrEmpty(showEffectwhenOff)) InGameInfo.Ins.Show_Effect(showEffectwhenOff, transform.position); } }