Project_WL/Assets/Script/Util/TurnOff_GO.cs

108 lines
2.8 KiB
C#
Raw Normal View History

2024-12-15 01:39:39 +00:00
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;
2025-02-12 07:21:10 +00:00
bool followTarget, isPS;
ParticleSystem m_PS;
2025-04-07 23:18:30 +00:00
string showEffectwhenOff;
2025-02-12 07:21:10 +00:00
private void Awake()
{
m_PS = GetComponent<ParticleSystem>();
isPS = m_PS;
}
2024-12-15 01:39:39 +00:00
public void Set() { gameObject.SetActive(false); gameObject.SetActive(true); }
public void Set(Actor target, ProjectileData pd, float LifeTime)
2024-12-15 01:39:39 +00:00
{
followTarget = true;
m_target = target;
m_ProjectileData = pd;
NoUseParticleTime = true;
OffTime = LifeTime;
transform.position = m_ProjectileData.Get_EffectPos(target);
2024-12-15 01:39:39 +00:00
gameObject.SetActive(true);
Set_Off();
2024-12-15 01:39:39 +00:00
}
public void Set(Actor target, eEffectLocation loca, float lifetime)
2024-12-15 01:39:39 +00:00
{
m_target2 = target;
2024-12-15 01:39:39 +00:00
e_EffectLocation = loca;
OffTime = lifetime;
2024-12-15 01:39:39 +00:00
gameObject.SetActive(true);
Set_Off();
2024-12-15 01:39:39 +00:00
}
public void Set_PrefabInfo(Actor target)
{
Set_Location(target);
gameObject.SetActive(true);
Set_Off();
2024-12-15 01:39:39 +00:00
}
public void Reset_Time(float time)
2025-02-11 07:09:38 +00:00
{
OffTime = time;
Set_Off();
}
public bool IsMyEffect(Actor actor)
{
if (m_target2 == actor)
return true;
return false;
2025-02-11 07:09:38 +00:00
}
2025-04-07 23:18:30 +00:00
public void Set_EffectwhenOff(string effect) { showEffectwhenOff = effect; }
2025-02-11 07:09:38 +00:00
void Set_Off()
{
2025-02-12 07:21:10 +00:00
Set_Coroutine_withCancel(Off_Imm, NoUseParticleTime || !isPS ? OffTime : m_PS.main.duration);
}
2025-02-11 07:09:38 +00:00
private void OnEnable()
2024-12-15 01:39:39 +00:00
{
Set_Off();
2024-12-15 01:39:39 +00:00
}
void Update()
2024-12-15 01:39:39 +00:00
{
if (followTarget)
{
if (m_target)
transform.position = m_ProjectileData.Get_EffectPos(m_target);
else
2024-12-15 01:39:39 +00:00
{
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)
2025-02-11 07:09:38 +00:00
{
case eEffectLocation.Top: effectPos = target.Get_Top_postion(); break;
default: effectPos = target.Get_Center_position(); break;
case eEffectLocation.Bottom: effectPos = target.Get_position(); break;
2025-02-11 07:09:38 +00:00
}
transform.position = effectPos;
2024-12-15 01:39:39 +00:00
}
2025-02-11 07:09:38 +00:00
public void Off_Imm()
2024-12-15 01:39:39 +00:00
{
gameObject.SetActive(false);
act_End?.Invoke();
2025-04-07 23:18:30 +00:00
if (!string.IsNullOrEmpty(showEffectwhenOff))
InGameInfo.Ins.Show_Effect(showEffectwhenOff, transform.position);
2024-12-15 01:39:39 +00:00
}
}