【Unity】TimeLine学习笔记(一):自定义轨道(Track)

API参考

  • TrackAsset:https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Timeline.TrackAsset.html
  • TrackBindingTypeAttribute:https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Timeline.TrackBindingTypeAttribute.html
  • TrackClipTypeAttribute:
  • https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Timeline.TrackClipTypeAttribute.html
  • TrackColorAttribute:https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Timeline.TrackColorAttribute.html

解释

TrackAsset是自定义轨道时需要继承的类,类中包含多种属性和方法,涉及对轨道内容及轨道片段(TrackClip)的管理和操作。

using UnityEngine;
using UnityEngine.Timeline;

public class DialogueTrack : TrackAsset
{
    
}

TrackBindingTypeAttribute、TrackClipTypeAttribute 和 TrackColorAttribute是三个类属性,各自的作用为——

TrackBindingTypeAttribute:向轨道拖放物体时,将执行“绑定类型”的检查。比如:若物体中不含有Light组件,则在拖放物体时,自动添加绑定的组件类型。

using UnityEngine;
using UnityEngine.Timeline;

[TrackBindingType(typeof(Light), TrackBindingFlags.AllowCreateComponent)]
public class LightTrack : TrackAsset
{
    
}

TrackClipTypeAttribute:指定可以拖放以及创建(使用TrackAsset类中的方法)的片段类型(片段类型也可自定义)。

using UnityEngine;
using UnityEngine.Timeline;

[TrackClipType(typeof(DialogueClip))]
public class DialogueTrack : TrackAsset
{
   
}

TrackColorAttribute:指定轨道及其片段的颜色。不过,这只是显示边界的颜色。

using UnityEngine;
using UnityEngine.Timeline;

[TrackColor(1.0f, 0.0f, 0.0f)]            // red
public class DialogueTrack : TrackAsset
{
   
}

你可能感兴趣的:(Unity)