unity Timeline的Playable脚本
来源:互联网 发布:linux命令行复制文件 编辑:程序博客网 时间:2024/05/20 11:25
Playabl脚本不使用MonoBehaviour而是BasicPlayableBehaviour,
名字域需要:using UnityEngine.Playables和using UnityEngine.Timeline
Playable中提供有8种方法:
1,OnGraphStart(Playable playable);
2,OnGraphStop(Playable playable);
3,PrepareFrame(Playable playable, FrameData info);
4,ProcessFrame(Playable playable, FrameData info, object playerData);
5,OnBehaviourPlay(Playable playable, FrameData info);
6,OnBehaviourPause(Playable playable, FrameData info);
7,OnPlayableCreate(Playable playable);
8,OnPlayableDestroy(Playable playable);
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.Playables;using UnityEngine.Timeline;public class SimpleCustomPlayable : BasicPlayableBehaviour{ public override void OnGraphStart(Playable playable) { Debug.Log("Graph start"); } public override void OnGraphStop(Playable playable) { Debug.Log("Graph stop"); } public override void PrepareFrame(Playable playable, FrameData info) { Debug.Log("1"); } public override void ProcessFrame(Playable playable, FrameData info, object playerData) { Debug.Log("2"); } public override void OnBehaviourPlay(Playable playable, FrameData info){ Debug.Log("Play State Playing"); } public override void OnBehaviourPause(Playable playable, FrameData info){ Debug.Log("Play State Paused"); }}
OnBehaviourPlay和OnBehaviourPause分别为时间进度进入短条和离开短条所触发的方法。
OnGraphStart相当于一个初始化的方法,只有在Play之后才会调用
PrepareFrame和ProcessFrame调用与帧有关,两个方法调用的次数是一样的,只有时间进度进入短条后,这两个方法才会每帧调用。
要在Playable中控制外围对象不适用public这种,而是用public ExposedReference<GameObject>相当于public GameObject;
public ExposedReference<Transform>相当于public Transform;
还有一种切换继承对象的用法:public ExposedReference<MonoBehaviour> Component;相当于这个component是在MonoBehaviour下运行的;
public ExposedReference<EventTrigger>相当于EventTrigger;
所有这些方法都是先public ExposedReference然后在private一个<>里的结构,最后在OnGraphStart()中把private对象使用Resolve(playable.GetGraph().GetResolver());方法实例化使用。Resolve(playable.GetGraph().GetResolver())相当于把对象扔到Timeline里处理的意思。
using UnityEngine;using UnityEngine.Playables;using UnityEngine.Timeline;public class ToggleComponentPlayable : BasicPlayableBehaviour{public ExposedReference<MonoBehaviour> Component;private MonoBehaviour _component;public bool EnabledOnStart;public bool EnabledOnEnd;private GameObject m_GameObject;public override void OnGraphStart(Playable playable) {_component = Component.Resolve(playable.GetGraph().GetResolver());}public override void OnBehaviourPlay(Playable playable, FrameData info) { if (_component != null) {_component.enabled = EnabledOnStart;} } public override void OnBehaviourPause(Playable playable, FrameData info){if (_component != null) {_component.enabled = EnabledOnEnd;}}}
我微信公众号:
公众号已接入智能回复,欢迎怼我
- unity Timeline的Playable脚本
- Unity的TimeLine设计相关
- unity Timeline
- <划重点的Unity2017>Playable相关
- unity timeline使用手册
- Unity脚本的属性
- Unity抛物线的脚本
- Unity脚本的生命周期
- unity 陀螺仪的脚本
- Unity脚本的生命周期
- Unity 脚本的生命周期
- Unity脚本的生命周期
- 我读书的TIMELINE
- 关于pyclutter的timeline
- TimeLine
- Timeline
- [Unity-10] Unity脚本的生命周期
- [Unity基础]unity脚本的生命周期
- MapReduce总结
- 前端遇坑记录(三)——axios请求的参数自动拼接到url后面
- python的多线程使用setDaemon有什么意义?
- Shell常用骚操作
- redis持久化 RDB 和 AOF对比 redis容灾备份
- unity Timeline的Playable脚本
- visual studio 2017 git 插件上传动态链接库
- postgresql 坐标距离操作
- Unity_设计模式_UML类图_03
- 字符串替换!为每个字符添加单引号!
- sublime 中文乱码
- sourceTree load不出来项目
- class Merging DataFrames with pandas
- flex布局(2)