52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Playables;
|
|||
|
|
|
|||
|
|
namespace GameWrapper.Timeline.CommonAction
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 通用动作混合器行为
|
|||
|
|
/// 处理轨道级别的逻辑和多个Clip的混合
|
|||
|
|
/// </summary>
|
|||
|
|
public class CommonActionMixerBehaviour : PlayableBehaviour
|
|||
|
|
{
|
|||
|
|
private GameObject boundObject;
|
|||
|
|
|
|||
|
|
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
|
|||
|
|
{
|
|||
|
|
// 获取绑定的GameObject
|
|||
|
|
if (boundObject == null && playerData is GameObject go)
|
|||
|
|
{
|
|||
|
|
boundObject = go;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (boundObject == null)
|
|||
|
|
return;
|
|||
|
|
|
|||
|
|
// 遍历所有输入的Clip,找到当前正在播放的
|
|||
|
|
int inputCount = playable.GetInputCount();
|
|||
|
|
|
|||
|
|
for (int i = 0; i < inputCount; i++)
|
|||
|
|
{
|
|||
|
|
float weight = playable.GetInputWeight(i);
|
|||
|
|
|
|||
|
|
// 只处理权重大于0的输入(正在播放的Clip)
|
|||
|
|
if (weight > 0)
|
|||
|
|
{
|
|||
|
|
ScriptPlayable<CommonActionBehaviour> inputPlayable =
|
|||
|
|
(ScriptPlayable<CommonActionBehaviour>)playable.GetInput(i);
|
|||
|
|
|
|||
|
|
CommonActionBehaviour behaviour = inputPlayable.GetBehaviour();
|
|||
|
|
|
|||
|
|
// 这里可以添加混合逻辑
|
|||
|
|
// 例如:处理多个Clip同时作用于同一对象的情况
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void OnPlayableDestroy(Playable playable)
|
|||
|
|
{
|
|||
|
|
boundObject = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|