loudixvmuniu/Assets/TimeLine/PlayableTest.cs
2025-01-19 13:45:40 +08:00

49 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
// A behaviour that is attached to a playable
public class PlayableTest : PlayableBehaviour
{
public string testName;
public int testInt;
public Material _mat;
// 当开始运行Timeline的时候
public override void OnGraphStart(Playable playable)
{
Debug.Log("TimeLine 开始播放");
}
// 当停止运行Timeline的时候
public override void OnGraphStop(Playable playable)
{
Debug.Log("TimeLine 停止播放");
}
// 当进入区域内触发Play
public override void OnBehaviourPlay(Playable playable, FrameData info)
{
Debug.Log($"进入滑块区域内{testName},Int:{testInt},mat:{_mat.name}");
}
// 当出了区域触发,或者开始的时候触发,或者停止运行的时候
public override void OnBehaviourPause(Playable playable, FrameData info)
{
Debug.Log($"Pause{testName},Int:{testInt}");
}
// 在区域内每个Frame地方都会触发
public override void PrepareFrame(Playable playable, FrameData info)
{
double all = playable.GetDuration();
double currentTime = playable.GetTime(); // 获取当前播放时间
//float framesPerSecond = info.playable.GetGraph().GetFrameRate(); // 获取每秒帧数
_mat.SetVector("_Value1", new Vector2(0.86f, (float)(currentTime * 0.04f / all)));
Debug.Log($"{all}:Current Time: {currentTime}:cur:{(float)(currentTime * 0.04f / all)}");
}
}