本文主要是介绍Timeline调用实质,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文地址:https://blog.csdn.net/t163361/article/details/114371261
最近准备申请新星创作者,需要2000个粉丝关注,觉得文章有用的,请点一下左侧边栏的关注,谢谢。
19年左右调研Timeline的相关文档
PlayableDirector:
导演,控制timeline的播放,停止等等,
PlayableDirector.playableAsset:
播放资产,outputs
PlayableBinding :
绑定,记录的是outputs,以上三者的关系就是 Director 含有一个资产,资产上有一些列绑定,其实就是 一个timeline上有好多绑定,存在一个资产上
Playable:
Playable是一个可以扩展的一个概念,大概的意思就是一个track就是一个playable
包括一些内置的和自定义的
自定义的类似这些一样的,
有用的代码:
从一个playable里提取数据并进行存储
public void Init(string name, PlayableDirector director, PlayableAsset asset)
{
director.playableAsset = asset;
this.name = name;
this.director = director;
this.asset = asset;
bindings = new Dictionary<string, PlayableBinding>();clips = new Dictionary<string, Dictionary<string, PlayableAsset>>();foreach (var o in asset.outputs){var trackName = o.streamName;bindings.Add(trackName, o);var track = o.sourceObject as TrackAsset;var clipList = track.GetClips();foreach (var c in clipList){if (!clips.ContainsKey(trackName)){clips[trackName] = new Dictionary<string, PlayableAsset>();}var name2Clips = clips[trackName];if (!name2Clips.ContainsKey(c.displayName)){name2Clips.Add(c.displayName, c.asset as PlayableAsset);}}}
}设置bindingpublic void SetBinding(string trackName, Object o)
{director.SetGenericBinding(bindings[trackName].sourceObject, o);
}
获取
public T GetTrack(string trackName) where T : TrackAsset
{
return bindings[trackName].sourceObject as T;
}
public T GetClip<T>(string trackName, string clipName) where T : PlayableAsset
{if (clips.ContainsKey(trackName)){var track = clips[trackName];if (track.ContainsKey(clipName)){return track[clipName] as T;}else{Debug.LogError("GetClip Error, Track does not contain clip, trackName: " + trackName + ", clipName: " + clipName);}}else{Debug.LogError("GetClip Error, Track does not contain clip, trackName: " + trackName + ", clipName: " + clipName);}return null;
}
这篇关于Timeline调用实质的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!