using System; using Gameplay.Level; using Gameplay.Pause; using Gameplay.Pool; using Gameplay.Unit; using PhxhSDK; namespace Gameplay.Effect { using Framework; using UnityEngine; using Gameplay.Skill; public class EffectPlayingData { /// /// pauser信息直接放这里 /// public DataEffectPauser pauserData; public GameUnit owner; public GameObject rootObj; public Action onLoaded; public Transform transform { get { if (rootObj == null) { return null; } return rootObj.transform; } } public float remainTime; public bool autoDestroy = false; public EEffectState state = EEffectState.Error; public bool needReturn { get { return (autoDestroy && remainTime <= 0) || state == EEffectState.Destroied || state == EEffectState.Returned; } } private BaseEffectLogic _logic; public readonly int effectId; public EffectPlayingData(int effectId) { this.effectId = effectId; } public async void Load(string prefabPath) { if (state != EEffectState.Error) return; state = EEffectState.Loading; if (SROptions.Current != null) { if (!SROptions.Current.EnableEffect) { state = EEffectState.Destroied; return; } } var sampleObj = await AssetManager.Instance.LoadAssetAsync(prefabPath); if (sampleObj == null) { DebugUtil.LogError("特效不存在:{0}", prefabPath); return; } if (rootObj == null) { // 说明已经被销毁了 return; } var obj = await AssetManager.Instance.InstanceAsync(prefabPath); if (rootObj == null) { // 说明已经被销毁了 obj.Destroy(); return; } obj.transform.SetParent(rootObj.transform); obj.transform.ResetLocals(); state = EEffectState.Playing; rootObj.SetLayerEx(rootObj.layer); if (onLoaded != null) { onLoaded(); } EventManager.Instance.Send(EventManager.EventName.EFFECT_INST_FINISHED, this); } public void AddLogic(BaseEffectLogic logic) { if (_logic != null) { ObjPoolManager.instance.Return(logic); } _logic = logic; _logic.effect = this; } public void LogicUpdate(float dt) { if (LevelManager.Instance.CurrentLevel?.isInBattle ?? false) { if (SkillManager.instance != null) { if (SkillManager.instance.inSkillingUnit != owner) { dt *= SkillManager.instance.needSkillPaused ? 0 : 1; } } } if (autoDestroy) { remainTime -= dt; } if (_logic != null) { _logic.LogicUpdate(dt); } } public void Destroy() { if (state == EEffectState.Returned || state == EEffectState.Destroied) return; state = EEffectState.Returned; EventManager.Instance.Send(EventManager.EventName.EFFECT_INST_RETURN, this); if (_logic != null) { ObjPoolManager.instance.Return(_logic); _logic = null; } EffectManager.instance.ReturnEffect(this); } public void RealDestroy() { state = EEffectState.Destroied; if (rootObj != null) { rootObj.Destroy(); rootObj = null; } } public void SetActive(bool active) { if (rootObj == null) return; rootObj.SetActive(active); } } }