Timeline 理解与API解读

本文对Timeline进行理解与API解读,介绍了其自有组件,如Activation Track、Animation Track等,指出Control Track和Playable Track较难理解,使用Unity2018.2.0版本有bug,Playable Track让Timeline具扩展性。还提及Timeline扩展插件,如cinemachine相机插件和Recorder录屏插件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Timeline 理解与API解读

Timeline自有组件:

  • Activation Track
  • Animation Track
  • Audio Track
  • Control Track
  • Playable Track
  • Track Group

比较有难于理解的是Control Track和Playable Track,建议不要使用Unity2018.2.0的版本,在使用Timeline的时候会遇到一些一样不到的bug。PlayableGraph提供了Timeline的可视化图形结构,暂不支持编辑功能。如图:
在这里插入图片描述
Playable Track使Timeline具备可扩展性。
在这里插入图片描述

using UnityEngine;
using UnityEngine.Playables;

[System.Serializable]
public class LightControlAsset : PlayableAsset
{
    /// <summary>
    /// 由于PlayableAsset是个资源,它不能直接引用场景中的对象。此时ExposedReference会充当一个约定,表示在调用CreatePlayable时会解析一个对象。
    /// </summary>
    public ExposedReference<Light> light;
    public Color color = Color.gray;
    public float intensity = 1f;

	// Factory method that generates a playable based on this asset
	public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
    {
        Debug.Log("CreatePlayable");
        var playable = ScriptPlayable<LightControlBehaviour>.Create(graph);
        var lightControlBehaviour = playable.GetBehaviour();
        lightControlBehaviour.light = light.Resolve(graph.GetResolver());
        lightControlBehaviour.color = color;
        lightControlBehaviour.intensity = intensity;
        return playable;
	}
}


    using UnityEngine;
using UnityEngine.Playables;

/// <summary>
/// 目的:确定需要修改Light组件的哪些属性。而且PlayableBehaviour拥有名为ProcessFrame的方法可供重写。
/// </summary>
// A behaviour that is attached to a playable
public class LightControlBehaviour : PlayableBehaviour
{
    public Light light = null;

    public Color color = Color.white;

    public float intensity = 1;

    // Called when the owning graph starts playing
    public override void OnGraphStart(Playable playable)
    {
        Debug.Log("OnGraphStart");
    }

    // Called when the owning graph stops playing
    public override void OnGraphStop(Playable playable)
    {
        Debug.Log("OnGraphStop");
    }

    // Called when the state of the playable is set to Play
    public override void OnBehaviourPlay(Playable playable, FrameData info)
    {
        Debug.Log("OnBehaviourPlay");
    }

    // Called when the state of the playable is set to Paused
    public override void OnBehaviourPause(Playable playable, FrameData info)
    {
        Debug.Log("OnBehaviourPause");

    }

    // Called each frame while the state is set to Play
    public override void PrepareFrame(Playable playable, FrameData info)
    {
        Debug.Log("PrepareFrame");
    }

    public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    {
        if (light != null)
        {
            light.color = color;
            light.intensity = intensity;
        }
        Debug.Log("ProcessFrame");
    }
}

ControlTrack暂时没有深入研究。查阅资料说明它主要用来控制与时间有关的元素,如粒子效果、Timeline等。

Timeline扩展插件

  • cinemachine (相机插件)

  • Recorder (录屏插件)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值