using CriWare; using UnityEngine; public class Effect : MonoBehaviour { private EffectMgr.EffectType m_Type; private GameObject m_GameObjIns; private ParticleSystem m_ParticleSystem; private Vector3 m_Pos; private bool m_Use; private GameObject m_ChaseObjIns; private GameObject m_LookAtObject; private bool _buff; private CriAtomSource m_EffectSeSource; private Camera _lookAtCamera; private bool _isFollowScale; public Effect() { m_Type = EffectMgr.EffectType.NONE; m_GameObjIns = null; m_Use = false; m_Pos = new Vector3(0f, 0f, -3f); _buff = false; } public void Init(EffectMgr.EffectType type, bool isCommon = false, string SePath = "", bool isFollowScale = false) { m_Type = type; if (!string.IsNullOrEmpty(SePath)) { m_EffectSeSource = base.gameObject.GetComponent(); m_EffectSeSource.use3dPositioning = true; m_EffectSeSource.playOnStart = false; } m_GameObjIns = base.gameObject; m_ParticleSystem = m_GameObjIns.GetComponent(); m_ParticleSystem.GetComponent().sortingOrder = 4; if (isCommon) { m_ParticleSystem.Stop(); } _isFollowScale = isFollowScale; } public void Play(Vector3 Pos, Quaternion Rot) { m_Pos = Pos; m_GameObjIns.transform.position = m_Pos; m_GameObjIns.transform.rotation = Rot; On(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); if (m_EffectSeSource != null) { m_EffectSeSource.Play(); } } public void Play(Vector3 Pos) { m_Pos = Pos; m_GameObjIns.transform.position = m_Pos; On(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); if (m_EffectSeSource != null) { m_EffectSeSource.Play(); } } public void Play(Vector3 Pos, GameObject obj) { m_ChaseObjIns = obj; if (obj != null) { _buff = true; } m_Pos = Pos; m_GameObjIns.transform.position = m_Pos; On(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); if (m_EffectSeSource != null) { m_EffectSeSource.Play(); } } public void Play(float PosX, float PosY, float PosZ) { m_Pos.x = PosX; m_Pos.y = PosY; m_Pos.z = PosZ; m_GameObjIns.transform.position = m_Pos; On(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); if (m_EffectSeSource != null) { m_EffectSeSource.Play(); } } public void Play(float PosX, float PosY) { m_Pos.x = PosX; m_Pos.y = PosY; m_GameObjIns.transform.position = m_Pos; On(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); if (m_EffectSeSource != null) { m_EffectSeSource.Play(); } } public void Play() { On(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); } public void FadeOut() { m_ParticleSystem.Stop(); } public void FadeIn() { On(); m_ParticleSystem.Play(); } public void Stop() { Off(); m_GameObjIns.SetActive(value: false); m_ParticleSystem.Stop(); } public void PlayBuff(GameObject obj) { m_Pos = obj.transform.position; m_GameObjIns.transform.position = m_Pos; m_ChaseObjIns = obj; _buff = true; On(); UpdatePositionAndRotation(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); } public void StopBuff() { m_ChaseObjIns = null; _buff = false; Off(); m_GameObjIns.SetActive(value: false); m_ParticleSystem.Stop(); } public void StartLookAtEffect(GameObject fromObject, GameObject toObject) { m_ChaseObjIns = fromObject; m_LookAtObject = toObject; _buff = true; On(); UpdatePositionAndRotation(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); } public void StartLookAtCameraEffect(GameObject fromObject, Camera toCamera) { m_ChaseObjIns = fromObject; _lookAtCamera = toCamera; _buff = true; On(); UpdatePositionAndRotation(); m_GameObjIns.SetActive(value: true); m_ParticleSystem.Play(); } public void StopLookAtEffect() { m_ChaseObjIns = null; m_LookAtObject = null; _buff = false; Off(); m_GameObjIns.SetActive(value: false); m_ParticleSystem.Stop(); } private void UpdatePositionAndRotation() { m_GameObjIns.transform.position = m_ChaseObjIns.transform.position; m_GameObjIns.transform.rotation = CalculateRotation(); } private void UpdateScale() { m_GameObjIns.transform.localScale = m_ChaseObjIns.transform.localScale; } private Quaternion CalculateRotation() { if (m_LookAtObject != null) { Vector3 position = m_ChaseObjIns.transform.position; Vector3 position2 = m_LookAtObject.transform.position; float z = Mathf.Atan2(position2.y - position.y, position2.x - position.x) * 57.29578f - 90f; return Quaternion.Euler(0f, 0f, z); } if (_lookAtCamera != null) { Vector3 position3 = m_ChaseObjIns.transform.position; Vector3 position4 = _lookAtCamera.transform.position; return Quaternion.FromToRotation(Vector3.forward, position3 - position4); } return m_ChaseObjIns.transform.rotation; } private void Update() { if (!_buff) { return; } if (m_ChaseObjIns != null) { if (_isFollowScale) { UpdateScale(); } UpdatePositionAndRotation(); } else { StopBuff(); } } public void On() { m_Use = true; } public void Off() { m_Use = false; } public void Change() { m_Use = !m_Use; } public void ChangeParticleColor(Color color) { MotionUtils.ChangeParticleSystemColor(m_ParticleSystem.gameObject, color); } public EffectMgr.EffectType GetEffectType() { return m_Type; } public GameObject GetGameObjIns() { return m_GameObjIns; } public bool IsOn() { return m_Use; } public bool IsPlay() { if (m_ParticleSystem.isPlaying || m_ParticleSystem.isPaused || m_ParticleSystem.IsAlive()) { return true; } return false; } public GameObject GetChaseObjIns() { return m_ChaseObjIns; } }