NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Effect/EffectPlayingData.cs

175 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Gameplay.Common;
using Gameplay.Level;
using Gameplay.Pause;
using Gameplay.Pool;
using PhxhSDK;
namespace Gameplay.Effect
{
using Framework;
using UnityEngine;
using Character;
using Gameplay.Skill;
public class EffectPlayingData
{
/// <summary>
/// pauser信息直接放这里
/// </summary>
public DataEffectPauser pauserData;
public GameUnit owner;
public GameObject rootObj;
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<GameObject>(prefabPath);
if (sampleObj == null)
{
DebugUtil.LogError("特效不存在:{0}", prefabPath);
return;
}
if (rootObj == null)
{
// 说明已经被销毁了
return;
}
var obj = await AssetManager.Instance.InstanceAsync<GameObject>(prefabPath);
if (rootObj == null)
{
// 说明已经被销毁了
obj.Destroy();
return;
}
obj.transform.SetParent(rootObj.transform);
obj.transform.ResetLocals();
state = EEffectState.Playing;
rootObj.SetLayerEx(rootObj.layer);
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.skillingUnit != 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);
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);
}
}
}