【Unity】TimeLine的使用

// 获取timeLine中的所有track,并进行动态的绑定对象
using UnityEngine;
using UnityEngine.Playables;

[ExecuteInEditMode]
public class TimelineController : MonoBehaviour
{

    public PlayableDirector playableDirector;


    private void  Start()
    {
        foreach (PlayableBinding item in playableDirector.playableAsset.outputs)
        {
            // 所有track的名字
            //Debug.Log(item.streamName);
            if (item.streamName == "Animation Track1")
            {
                // 绑定一个对象,绑定到该Track
                playableDirector.SetGenericBinding(item.sourceObject, playableDirector.gameObject);
                // 从第5s开始播放
                playableDirector.time = 5;
            }
        }
    }
}

你可能感兴趣的:(【Unity】)