NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/PlayerSkill/Logic/PlayerSkillLogic03.cs

95 lines
3.1 KiB
C#
Raw Normal View History

using Cysharp.Threading.Tasks;
using Framework;
2023-12-12 12:49:49 +08:00
using Gameplay.Area;
using Gameplay.Bullet;
using Gameplay.Effect;
using Gameplay.PlayerSkill.Cmp;
using UnityEngine;
using UnityEngine.Playables;
2023-12-12 12:49:49 +08:00
namespace Gameplay.PlayerSkill.Logic
{
/// <summary>
/// 逻辑:
/// 在指定格子位置创建一个带timeline的特效
/// 等待timeline触发事件,接收到该事件后像该位置发射一发子弹
/// 逻辑参数 [特效id, 子弹id]
/// </summary>
public class PlayerSkillLogic03 : BasePlayerSkillLogic
{
private int _cacheBulletId;
private int _cacheReleaseCellIndex;
private EffectPlayingData _cacheEffectData;
2023-12-12 12:49:49 +08:00
protected override void _OnInit()
{
base._OnInit();
var effectId = owner.ReadParamInt(0);
var bulletId = owner.ReadParamInt(1);
_cacheBulletId = bulletId;
var releaseCellIndex = owner.selectedCellIndex;
_cacheReleaseCellIndex = releaseCellIndex;
2024-11-15 14:32:41 +08:00
var releasePos = AreaManager.instance.GetWorldPosByIndex(releaseCellIndex);
_InitEffect(effectId, releasePos);
2023-12-12 12:49:49 +08:00
EventManager.Instance.Register(EventManager.EventName.INFIGHT_PLAYER_SKILL_VIEW_TRIGGER, _OnEffectEvent);
}
2023-12-12 12:49:49 +08:00
protected override void _OnDispose()
{
base._OnDispose();
_cacheEffectData.onLoaded = null;
2023-12-12 12:49:49 +08:00
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_PLAYER_SKILL_VIEW_TRIGGER, _OnEffectEvent);
}
private void _InitEffect(int effectId, Vector3 releasePos)
{
_cacheEffectData = EffectManager.instance.PlayEffectById(effectId, releasePos);
_cacheEffectData.onLoaded = _OnEffectLoaded;
}
private void _OnEffectLoaded()
{
var effectObj = _cacheEffectData.rootObj;
var timeLine = effectObj.GetComponentInChildren<PlayableDirector>();
if (timeLine == null)
{
DebugUtil.LogError("该模式下的特效必须包含timeline");
isFinished = true;
return;
}
// 设置timeline的signal receiver
// 获取bindings
var isSet = false;
var bindings = timeLine.playableAsset.outputs;
foreach (var binding in bindings)
{
if (binding.streamName == "Signal Track")
{
timeLine.SetGenericBinding(binding.sourceObject, CmpPlayerSkillEventWrapper.instance.m_SignalReceiver);
isSet = true;
break;
}
}
if (!isSet)
{
DebugUtil.LogError("该模式下的timeline必须包含signal track");
isFinished = true;
return;
}
timeLine.Play();
}
2023-12-12 12:49:49 +08:00
private void _OnEffectEvent()
{
BulletManager.instance.EmitBullet(_cacheBulletId, _cacheReleaseCellIndex, owner.playerUnit);
isFinished = true;
2023-12-12 12:49:49 +08:00
}
}
}