170 lines
3.9 KiB
C#
170 lines
3.9 KiB
C#
using System;
|
|
using Gameplay.Level;
|
|
using Gameplay.Pause;
|
|
using Gameplay.Pool;
|
|
using Gameplay.Unit;
|
|
|
|
namespace Gameplay.Effect
|
|
{
|
|
using Framework;
|
|
using UnityEngine;
|
|
using Skill;
|
|
|
|
public class EffectPlayingData
|
|
{
|
|
|
|
/// <summary>
|
|
/// pauser信息直接放这里
|
|
/// </summary>
|
|
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 { get; private set; }
|
|
|
|
public bool autoDestroy;
|
|
|
|
public bool isLoaded { get; private set; }
|
|
|
|
public bool needReturn
|
|
{
|
|
get
|
|
{
|
|
return (autoDestroy && remainTime <= 0) || _forceDestroy;
|
|
}
|
|
}
|
|
|
|
private BaseEffectLogic _logic;
|
|
private bool _forceDestroy;
|
|
|
|
public readonly int effectId;
|
|
|
|
public EffectPlayingData(int effectId)
|
|
{
|
|
this.effectId = effectId;
|
|
isLoaded = false;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
_forceDestroy = false;
|
|
}
|
|
|
|
public async void Load(string prefabPath)
|
|
{
|
|
if (isLoaded) return;
|
|
isLoaded = true;
|
|
|
|
var sampleObj = await EffectManager.instance.orderCacher._LoadEffect(prefabPath);
|
|
if (sampleObj == null)
|
|
{
|
|
DebugUtil.LogError("特效不存在:{0}", prefabPath);
|
|
return;
|
|
}
|
|
|
|
if (rootObj == null)
|
|
{
|
|
// 说明已经被销毁了
|
|
return;
|
|
}
|
|
|
|
var obj = Object.Instantiate(sampleObj, rootObj.transform);
|
|
obj.transform.ResetLocals();
|
|
|
|
rootObj.SetLayerEx(rootObj.layer);
|
|
|
|
if (onLoaded != null)
|
|
{
|
|
onLoaded();
|
|
}
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.EFFECT_INST_FINISHED, this);
|
|
}
|
|
|
|
public void SetRemainTime(float setTime)
|
|
{
|
|
remainTime = setTime;
|
|
autoDestroy = remainTime > 0;
|
|
}
|
|
|
|
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()
|
|
{
|
|
_forceDestroy = true;
|
|
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()
|
|
{
|
|
_forceDestroy = true;
|
|
if (rootObj != null)
|
|
{
|
|
rootObj.Destroy();
|
|
rootObj = null;
|
|
}
|
|
}
|
|
|
|
public void SetActive(bool active)
|
|
{
|
|
if (rootObj == null) return;
|
|
rootObj.SetActive(active);
|
|
}
|
|
|
|
}
|
|
}
|