Unity的Timeline如何在clip激活的第一帧执行自定义代码
using System; using UnityEngine; using UnityEngine.Playables; using UnityEngine.Timeline; public class LightControlMixerBehaviour : PlayableBehaviour { private float[] weights; private bool initWeight; public override void PrepareFrame(Playable playable, FrameData info) { base.PrepareFrame(playable, info); int inputCount = playable.GetInputCount (); if (!initWeight && inputCount > 0) { weights = new float[inputCount]; initWeight = true; } for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable<LightControlBehaviour> inputPlayable = (ScriptPlayable<LightControlBehaviour>)playable.GetInput(i); LightControlBehaviour input = inputPlayable.GetBehaviour ();
if (weights[i] > 0 && inputWeight == 0)
{ input.OnStart(); Debug.Log(inputWeight); } weights[i] = inputWeight; } } }
在PrepareFrame里记录上一帧的inputWeight