TimeLine其强大的地方就在于其扩展性,其中ChineCamera就是支持其扩展。默认只支持以下几个有限的功能。大部分还是需要我们自己进行扩展,才能发挥出TimeLine的潜力。

本文以一个简单的Rotate 的Playalbe 为例:

PlayableAsset代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;//version 0.5[System.Serializable]
public class RotatePlayable : PlayableAsset
{public ExposedReference<GameObject> Target;public float Speed = 1;public Vector3 Axis = Vector3.up;// Factory method that generates a playable based on this assetpublic override Playable CreatePlayable(PlayableGraph graph, GameObject go) {var scriptPlayable = ScriptPlayable<RotatePlayableBehaviour>.Create(graph);//从ExposedReference中获取我们需要的控件scriptPlayable.GetBehaviour().Target = Target.Resolve(graph.GetResolver());//对指定的PlayableBehaviour中的属性进行赋值scriptPlayable.GetBehaviour().Axis = Axis;scriptPlayable.GetBehaviour().Speed = Speed;return scriptPlayable;}
}

大概过程:

1. 先建立一个PlayableTrack,它是自定义扩展的载体

2. 右键就会显示我们扩展的组件。

3. 选择后可以在右侧inspector里进行配置。(本例Speed就是Rotate一圈需要的时间)

4. 在CreatePlayable中把面板中的配置项传入到PlayableBehaviour中。

5. PrepareFrame中(类似Update)中进行对应的动作,本例就是Rotate。

PlayableBehaviour代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;//version 0.5// A behaviour that is attached to a playable
public class RotatePlayableBehaviour : PlayableBehaviour
{public GameObject Target;public float Speed;public Vector3 Axis;private float offsetPS;// Called when the owning graph starts playingpublic override void OnGraphStart(Playable playable) {base.OnGraphStart(playable);}// Called when the owning graph stops playingpublic override void OnGraphStop(Playable playable) {base.OnGraphStop(playable);}// Called when the state of the playable is set to Playpublic override void OnBehaviourPlay(Playable playable, FrameData info) {base.OnBehaviourPlay(playable, info);offsetPS = 360.0f / Speed; }// Called when the state of the playable is set to Pausedpublic override void OnBehaviourPause(Playable playable, FrameData info) {base.OnBehaviourPause(playable, info);}// Called each frame while the state is set to Playpublic override void PrepareFrame(Playable playable, FrameData info) {base.PrepareFrame(playable, info);Target.transform.Rotate(Axis, offsetPS * info.deltaTime);}
}

注意TimeLine的特性:

1. Time.TimeScale会影响Timeline的运行。可以根据其来实现一些暂停的功能。

https://docs.unity3d.com/ScriptReference/Playables.DirectorUpdateMode.html

可以根据以上进行修改,不受Scale的影响。

2.没有OnBehaviourStop方法,可以通过Asset获取到对应的duration,做个Timer进行相关的Stop操作

3.就像其名字一样,只支持串行时间管理,如果要循环比如本例的一些Rotate的过程,需要自己实现。

4.由于Timeline是种静态的资源,普通的Public定义不能绑定到Runtime即Hierarchy窗口中的对象。如果在支持绑定需要使用ExposedReference模板进行定义。

5. Stop再进行Play会重新开始播放

6. 在调节动画时,如果Scale变化了,再通过修改Position和Rotate会出问题,修改后,下一帧自动变为Scale后的变化,应该是BUG。

自定义TimeLine相关推荐

  1. 【Unity游戏开发】TimelinePlayable结合使用,Track自定义Timeline轨道

    宇宙第一小正太\ (o)/-萌量爆表求带飞=≡Σ((( つo)つ~ dalao们点个关注呗- 三大继承类: (1)PlayableTrack (2)PlayableBehavior (3)Playab ...

  2. 如何在Timeline中创建自定义轨道?

    你好,我是跟着大智学Unity的萌新,我叫小新,这是我本周的学习总结报告哦. 用过一段时间Timeline后,我问大智:"Timeline中只有这么几个轨道么?我发现有的需求这些轨道根本没办 ...

  3. Unity - Timeline 自定义剪辑,轨道,混合轨道,Inspector属性显示(使用Default Playables辅助工具)

    Timeline中,可以通过脚本扩展自定义的剪辑,轨道,混合轨道,Inspector属性显示器. 我这里参考了官方的 Default Playables的一个节点扩展方式,它也提供了一个辅助工具,非常 ...

  4. 【Unity】创建自定义Playable,使用Timeline控制Particle System的参数

    Timeline功能强大,但可控的参数还是较少,官方提供了自定义编写Playable的方法,用于扩展Timeline,使其更加强大. 上一篇我们介绍了一些官方发布到Asset Store上的免费Pla ...

  5. timeline,一个简单精美的自定义时间轴

    H-Express Library--------timeline 这是母项目 H-Express 中的那个自定义时间轴view,现抽取出来分享给大家,这个自定义view比较简单,作为学习自定义vie ...

  6. Timeline以及自定义轨道(对话轨道)

    目录 创建Timeline 添加Track 添加Animation Track 添加Activation Track 添加Audio Track 添加对话轨道(自定义轨道) 可以同时操作多个模型的动画 ...

  7. 【unity】Timeline自定义轨道

    Timeline结构 Track轨道类         (轨道类,主要指定了轨道片段类.轨道关联对象类型.指定并创建轨道逻辑类)         继承之TrackAsset         例如Act ...

  8. android自定义离线地图,MapBox GL Android:已下载但未使用的自定义磁贴源的离线地图...

    对于我们的应用程序,我目前正在将地图框与自定义地图图块集成(如 here所述).使用OfflineManager和OfflineTilePyramidRegionDefinition,一切都运行正常, ...

  9. android自定义尺子收集demo

    demo合集: https://github.com/dalong982242260/AndroidRuler 1.直尺(测量距离) github:https://github.com/1149863 ...

  10. 使用Chrome的timeline工具分析web应用性能

    Development tool的timeLine功能,可以用来做前端的性能分析. 例如我们想分析frontend Opportunity点了Note tab的性能: 因为我们用的是UI5 frame ...

最新文章

  1. Curl中的参数知多少
  2. 好好学python·运算符和流程控制
  3. 编译原理 之 解释器
  4. android 音乐播放器 获取sd卡所有音乐文件,Android Studio音乐播放器无法读取SD卡,只有内部存储器...
  5. Java 对象的序列化和反序列化
  6. [Leedcode][JAVA][第5题][最长回文子串][数组][动态规划]
  7. Java基础篇:什么是线程优先级?
  8. IntelliJ IDEA 打包Maven 构建的 Java 项目
  9. 2022 github新建账号技巧
  10. python运算符_零基础学习 Python 之运算符
  11. 小米路由器挂php,小米路由器mini 安装openWrt+更新源+挂载U盘+安装python
  12. 备考通信复试过程中的一些知识点总结梳理——移动通信系统Ⅰ
  13. 在win10 LTSB版本中使用UWF组件,实现影子保护功能,提供稳定,高速的开发环境...
  14. java 数组和集合的区别
  15. 【论文笔记】covid-19肺部感染区域分割基准
  16. 2018 rust卡石头教程_rust地上的石头怎么捡 | 手游网游页游攻略大全
  17. LeetCode-1694. 重新格式化电话号码【字符串,分块】
  18. 有道字典 Chrome Extension
  19. Winform像菜单一样弹出自定义内容实现示例
  20. Docker教程(一):docker安装及运行原理

热门文章

  1. DAC0832数模转换芯片介绍及使用教程
  2. System32与SysWow64的区别
  3. 荣事达Royalstar无叶暖风机——功能逻辑与能耗分析
  4. 三创赛优秀作品_厉害了!珠海这所学校的大学生夺得“三创赛”全国总决赛一等奖...
  5. 【软件需求工程】北理的恶龙们04——项目成果总结
  6. 北漂人的独白,是否有所共鸣
  7. Mono.Cecil说明文档翻译
  8. 待办事项列表,敏捷项目管理的核心工件
  9. java项目 无法重命名_无法重命名数据库?
  10. 编写README文档(Markdown)