[Unity] Playables学习整理 - 2 (Timel

2023-04-13  本文已影响0人  _Walker__

环境

1、TML对象(Playable)的创建过程

时序图

1.1

  个人推测,整个创建过程是由PlayableDirector发起的,依据如下:

/*PlayableDirector反编译的代码*/

public PlayableAsset playableAsset
{
  get => this.Internal_GetPlayableAsset() as PlayableAsset;
  set => this.SetPlayableAsset((ScriptableObject) value);
}

public void Play(PlayableAsset asset)
{
  if ((UnityEngine.Object) asset == (UnityEngine.Object) null)
    throw new ArgumentNullException(nameof (asset));
  this.Play(asset, this.extrapolationMode);
}

public void Play(PlayableAsset asset, DirectorWrapMode mode)
{
  this.playableAsset = !((UnityEngine.Object) asset == (UnityEngine.Object) null) ? asset : throw new ArgumentNullException(nameof (asset));
  this.extrapolationMode = mode;
  this.Play();
}

[NativeThrows]
[MethodImpl(MethodImplOptions.InternalCall)]
public extern void Play();

1.2

  通过上面的时序图,可以大致看出TimelineAsset、Track、Clip、Mixer、Playable这些元素间的关系。

2、TML的(类)结构

TML类图-Asset部分 TML类图-Clip部分

  为了理解TML的机制,以及TML跟Playable的关系,下面几个类需要重点关注:RuntimeClipTimelineClipTimelineAssetTrackAssetTimelinePlayable 这些类可以大致分为三组:

1)TimelineAsset

  这里我有个很疑惑的点,TimelinePlayable的输出只有一个(playable.GetOutputCount()=0),但它却关联了多个PlayableOutput的实例。从图中能看到,它应该是通过“SourceOutputPort”来区分的,但这个Port的概念是什么无从得知。从PlayableTraversalMode.Passthrough这个枚举值的注释中可以推测:OutputPort跟InputPort是一一对应的,若[SourceOutputPort=3],它的输入应该是,TimelinePlayable中[Input 3]对应的Playable。

Causes the Playable to act as a passthrough for PrepareFrame and ProcessFrame.
If the PlayableOutput being processed is connected to the n-th input port of the Playable, the Playable only propagates the n-th output port.
Use this enum value in conjunction with PlayableOutput SetSourceOutputPort.

这种只有一个Output却产生多个PlayableOutput结果的设定,让我很不解,如果有大佬明白这里的设计思路,还请不吝赐教!!!!

2)TrackAsset

3)TimelineClip

4)RuntimeClip

5)TimelinePlayable

上一篇 下一篇

猜你喜欢

热点阅读