自定义TimeLine
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相关推荐
- 【Unity游戏开发】TimelinePlayable结合使用,Track自定义Timeline轨道
宇宙第一小正太\ (o)/-萌量爆表求带飞=≡Σ((( つo)つ~ dalao们点个关注呗- 三大继承类: (1)PlayableTrack (2)PlayableBehavior (3)Playab ...
- 如何在Timeline中创建自定义轨道?
你好,我是跟着大智学Unity的萌新,我叫小新,这是我本周的学习总结报告哦. 用过一段时间Timeline后,我问大智:"Timeline中只有这么几个轨道么?我发现有的需求这些轨道根本没办 ...
- Unity - Timeline 自定义剪辑,轨道,混合轨道,Inspector属性显示(使用Default Playables辅助工具)
Timeline中,可以通过脚本扩展自定义的剪辑,轨道,混合轨道,Inspector属性显示器. 我这里参考了官方的 Default Playables的一个节点扩展方式,它也提供了一个辅助工具,非常 ...
- 【Unity】创建自定义Playable,使用Timeline控制Particle System的参数
Timeline功能强大,但可控的参数还是较少,官方提供了自定义编写Playable的方法,用于扩展Timeline,使其更加强大. 上一篇我们介绍了一些官方发布到Asset Store上的免费Pla ...
- timeline,一个简单精美的自定义时间轴
H-Express Library--------timeline 这是母项目 H-Express 中的那个自定义时间轴view,现抽取出来分享给大家,这个自定义view比较简单,作为学习自定义vie ...
- Timeline以及自定义轨道(对话轨道)
目录 创建Timeline 添加Track 添加Animation Track 添加Activation Track 添加Audio Track 添加对话轨道(自定义轨道) 可以同时操作多个模型的动画 ...
- 【unity】Timeline自定义轨道
Timeline结构 Track轨道类 (轨道类,主要指定了轨道片段类.轨道关联对象类型.指定并创建轨道逻辑类) 继承之TrackAsset 例如Act ...
- android自定义离线地图,MapBox GL Android:已下载但未使用的自定义磁贴源的离线地图...
对于我们的应用程序,我目前正在将地图框与自定义地图图块集成(如 here所述).使用OfflineManager和OfflineTilePyramidRegionDefinition,一切都运行正常, ...
- android自定义尺子收集demo
demo合集: https://github.com/dalong982242260/AndroidRuler 1.直尺(测量距离) github:https://github.com/1149863 ...
- 使用Chrome的timeline工具分析web应用性能
Development tool的timeLine功能,可以用来做前端的性能分析. 例如我们想分析frontend Opportunity点了Note tab的性能: 因为我们用的是UI5 frame ...
最新文章
- Curl中的参数知多少
- 好好学python·运算符和流程控制
- 编译原理 之 解释器
- android 音乐播放器 获取sd卡所有音乐文件,Android Studio音乐播放器无法读取SD卡,只有内部存储器...
- Java 对象的序列化和反序列化
- [Leedcode][JAVA][第5题][最长回文子串][数组][动态规划]
- Java基础篇:什么是线程优先级?
- IntelliJ IDEA 打包Maven 构建的 Java 项目
- 2022 github新建账号技巧
- python运算符_零基础学习 Python 之运算符
- 小米路由器挂php,小米路由器mini 安装openWrt+更新源+挂载U盘+安装python
- 备考通信复试过程中的一些知识点总结梳理——移动通信系统Ⅰ
- 在win10 LTSB版本中使用UWF组件,实现影子保护功能,提供稳定,高速的开发环境...
- java 数组和集合的区别
- 【论文笔记】covid-19肺部感染区域分割基准
- 2018 rust卡石头教程_rust地上的石头怎么捡 | 手游网游页游攻略大全
- LeetCode-1694. 重新格式化电话号码【字符串,分块】
- 有道字典 Chrome Extension
- Winform像菜单一样弹出自定义内容实现示例
- Docker教程(一):docker安装及运行原理