Timeline入门

Timeline安装

使用 Unity 的时间轴可创建影片内容、游戏序列、音频序列和复杂的粒子效果。

安装:

image-20230507170738769

编辑器版本:

  • 2019.1 and later(推荐)

时间轴资源

创建Timeline

Assets>Create>Timeline

录制的帧动画会会保存为时间轴资源的子项

image-20230507171651913

时间轴实例

在场景中将时间轴资源与 Playable Director 组件相关联可创建时间轴实例

image-20230507172650619

时间轴编辑器窗口

image-20230507173152410

轨道属性

image-20230507173745254

  • 录制按钮,用于关键帧录制
  • 标记按钮
  • 锁轨按钮,锁住之后,当前轨道不可以编辑
  • 禁用轨道,禁用之后,当前轨道绑定的动画、声音等不会起作用
轨道类型

image-20230507174329764

Track Group

轨道打组,类似文件夹

Activation Track

控制一个物体的显示隐藏

Animation Track

动画轨道,剪辑动画片段

Audio Track

音频轨道,控制音频的播放暂停

Control Track

控制物体的显示与隐藏,控制粒子系统的播放,可以拖拽大部分场景中的物体,也可以拖拽大部分Assets目录下面的prefab

Signal Track

信号轨道,本质是一个事件发射器,需要在Assets目录下面创建Signal 资源,然后在场景中需要接收信号的对象上面添加Signal Receiver组件

一个游标,表示一个触发信号

image-20230507213436594

image-20230507181108327

Playable Track

用户自定义轨道,自定义轨道脚本是成对使用的,分别是PlayableAsset,PlayableBehaviour

PlayableAsset 负责 PlayableBehaviour对象的实例化

PlayableBehaviour 负责监听动画播放、暂停等,可以在对应的事件中编写逻辑

image-20230507180336361

[System.Serializable]
public class BoxPlayableAsset : PlayableAsset
{
    public ExposedReference<Transform> target;
    // Factory method that generates a playable based on this asset
    public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
    {
        var p = ScriptPlayable<BoxPlayableBehaviour>.Create(graph);
        p.GetBehaviour().target = target.Resolve(graph.GetResolver());
        return p;
        //return Playable.Create(graph);
    }
}
public class BoxPlayableBehaviour : PlayableBehaviour
{
    public Transform target;
    // Called when the owning graph starts playing
    public override void OnGraphStart(Playable playable)
    {
        
    }

    // Called when the owning graph stops playing
    public override void OnGraphStop(Playable playable)
    {
        
    }

    // Called when the state of the playable is set to Play
    public override void OnBehaviourPlay(Playable playable, FrameData info)
    {
        target.localPosition = new Vector3(target.localPosition.x, target.localPosition.y, -0.0014f);
        Debug.Log(target.localPosition);
    }

    // Called when the state of the playable is set to Paused
    public override void OnBehaviourPause(Playable playable, FrameData info)
    {
        
    }

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

Playable Director组件

image-20230507172650619

Playable

时间轴资源

Update Method

DSP Lock: 数字信号处理器,使用处理音频的时钟

Game Time: 与Game时间相同,受时间缩放影响

Unscaled Game Time: 与Game时间相同,不受时间缩放影响

Manual: 不使用Game时间,脚本设置

Play On Awake

启动程序时自动播放

Wrap Mode

Hold: 只播放一次,并停留在最后一帧

Loop: 循环播放

None: 只播放一次

Initial Time

时间轴开始播放的时间(以秒为单位)

Bindings

绑定的资产

设置播放速度
	using UnityEngine.Playables;
	void PlayAtSpeed(PlayableDirector playableDirector, float speed)
    {
        playableDirector.RebuildGraph(); // the graph must be created before getting the playable graph
        playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(speed);
        playableDirector.Play();
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值