暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TimelineAttributes.cs 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEngine.Timeline
  4. {
  5. /// <summary>
  6. /// Specifies the type of PlayableAsset that a TrackAsset derived class can create clips of.
  7. /// </summary>
  8. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  9. public class TrackClipTypeAttribute : Attribute
  10. {
  11. /// <summary>
  12. /// The type of the clip class associate with this track
  13. /// </summary>
  14. public readonly Type inspectedType;
  15. /// <summary>
  16. /// Whether to allow automatic creation of these types.
  17. /// </summary>
  18. public readonly bool allowAutoCreate; // true will make it show up in menus
  19. /// <summary>
  20. /// </summary>
  21. /// <param name="clipClass">The type of the clip class to associate with this track. Must derive from PlayableAsset.</param>
  22. public TrackClipTypeAttribute(Type clipClass)
  23. {
  24. inspectedType = clipClass;
  25. allowAutoCreate = true;
  26. }
  27. /// <summary>
  28. /// </summary>
  29. /// <param name="clipClass">The type of the clip class to associate with this track. Must derive from PlayableAsset.</param>
  30. /// <param name="allowAutoCreate">Whether to allow automatic creation of these types. Default value is true.</param>
  31. /// <remarks>Setting allowAutoCreate to false will cause Timeline to not show menu items for creating clips of this type.</remarks>
  32. public TrackClipTypeAttribute(Type clipClass, bool allowAutoCreate)
  33. {
  34. inspectedType = clipClass;
  35. allowAutoCreate = false;
  36. }
  37. }
  38. /// <summary>
  39. /// Apply this to a PlayableBehaviour class or field to indicate that it is not animatable.
  40. /// </summary>
  41. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Class)]
  42. public class NotKeyableAttribute : Attribute
  43. {
  44. }
  45. /// <summary>
  46. /// Options for track binding
  47. /// </summary>
  48. [Flags]
  49. public enum TrackBindingFlags
  50. {
  51. /// <summary>
  52. /// No options specified
  53. /// </summary>
  54. None = 0,
  55. /// <summary>
  56. /// Allow automatic creating of component during gameObject drag and drop
  57. /// </summary>
  58. AllowCreateComponent = 1,
  59. /// <summary>
  60. /// All options specified
  61. /// </summary>
  62. All = AllowCreateComponent
  63. }
  64. /// <summary>
  65. /// Specifies the type of object that should be bound to a TrackAsset.
  66. /// </summary>
  67. /// <example>
  68. /// <code source="../DocCodeExamples/TimelineAttributesExamples.cs" region="declare-sampleTrackBindingAttr" title="SampleTrackBindingAttr"/>
  69. /// </example>
  70. /// <remarks>
  71. /// Use this attribute when creating Custom Tracks to specify the type of object the track requires a binding to.
  72. /// </remarks>
  73. [AttributeUsage(AttributeTargets.Class)]
  74. public class TrackBindingTypeAttribute : Attribute
  75. {
  76. /// <summary>
  77. /// The type of binding for the associate track.
  78. /// </summary>
  79. public readonly Type type;
  80. /// <summary>
  81. /// Options for the the track binding
  82. /// </summary>
  83. public readonly TrackBindingFlags flags;
  84. /// <summary>
  85. /// Creates a new TrackBindingTypeAttribute.
  86. /// </summary>
  87. /// <param name="type"><inheritdoc cref="TrackBindingTypeAttribute.type"/></param>
  88. public TrackBindingTypeAttribute(Type type)
  89. {
  90. this.type = type;
  91. this.flags = TrackBindingFlags.All;
  92. }
  93. /// <summary>
  94. /// Creates a new TrackBindingTypeAttribute.
  95. /// </summary>
  96. /// <param name="type"><inheritdoc cref="TrackBindingTypeAttribute.type"/></param>
  97. /// <param name="flags"><inheritdoc cref="TrackBindingTypeAttribute.flags"/></param>
  98. public TrackBindingTypeAttribute(Type type, TrackBindingFlags flags)
  99. {
  100. this.type = type;
  101. this.flags = flags;
  102. }
  103. }
  104. // indicates that child tracks are permitted on a track
  105. // internal because not fully supported on custom classes yet
  106. [AttributeUsage(AttributeTargets.Class, Inherited = false)]
  107. class SupportsChildTracksAttribute : Attribute
  108. {
  109. public readonly Type childType;
  110. public readonly int levels;
  111. public SupportsChildTracksAttribute(Type childType = null, int levels = Int32.MaxValue)
  112. {
  113. this.childType = childType;
  114. this.levels = levels;
  115. }
  116. }
  117. // indicates that the type should not be put on a PlayableTrack
  118. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
  119. class IgnoreOnPlayableTrackAttribute : System.Attribute { }
  120. // used to flag properties as using a time field (second/frames) display
  121. class TimeFieldAttribute : PropertyAttribute
  122. {
  123. public enum UseEditMode
  124. {
  125. None,
  126. ApplyEditMode
  127. }
  128. public UseEditMode useEditMode { get; }
  129. public TimeFieldAttribute(UseEditMode useEditMode = UseEditMode.ApplyEditMode)
  130. {
  131. this.useEditMode = useEditMode;
  132. }
  133. }
  134. class FrameRateFieldAttribute : PropertyAttribute { }
  135. /// <summary>
  136. /// Use this attribute to hide a class from Timeline menus.
  137. /// </summary>
  138. [AttributeUsage(AttributeTargets.Class, Inherited = false)]
  139. public class HideInMenuAttribute : Attribute { }
  140. ///<summary>
  141. /// Use this attribute to customize the appearance of a Marker.
  142. /// </summary>
  143. /// Specify the style to use to draw a Marker.
  144. /// <example>
  145. /// <code source="../DocCodeExamples/TimelineAttributesExamples.cs" region="declare-customStyleMarkerAttr" title="CustomStyleMarkerAttr"/>
  146. /// </example>
  147. /// How to create a custom style rule:
  148. /// 1) Create a 'common.uss' USS file in an Editor folder in a StyleSheets/Extensions folder hierarchy.
  149. /// Example of valid folder paths:
  150. /// - Assets/Editor/StyleSheets/Extensions
  151. /// - Assets/Editor/Markers/StyleSheets/Extensions
  152. /// - Assets/Timeline/Editor/MyMarkers/StyleSheets/Extensions
  153. /// Rules in 'dark.uss' are used if you use the Pro Skin and rules in 'light.uss' are used otherwise.
  154. ///
  155. /// 2)In the USS file, create a styling rule to customize the appearance of the marker.
  156. /// <example>
  157. /// <code>
  158. /// MyStyle
  159. /// {
  160. /// /* Specify the appearance of the marker in the collapsed state here. */
  161. /// }
  162. ///
  163. /// MyStyle:checked
  164. /// {
  165. /// /* Specify the appearance of the marker in the expanded state here. */
  166. /// }
  167. ///
  168. /// MyStyle:focused:checked
  169. /// {
  170. /// /* Specify the appearance of the marker in the selected state here. */
  171. /// }
  172. /// </code>
  173. /// </example>
  174. /// <seealso cref="UnityEngine.Timeline.Marker"/>
  175. [AttributeUsage(AttributeTargets.Class)]
  176. public class CustomStyleAttribute : Attribute
  177. {
  178. /// <summary>
  179. /// The name of the USS style.
  180. /// </summary>
  181. public readonly string ussStyle;
  182. /// <summary>
  183. /// Creates a new CustomStyleAttribute.
  184. /// </summary>
  185. /// <param name="ussStyle"><inheritdoc cref="CustomStyleAttribute.ussStyle"/></param>
  186. public CustomStyleAttribute(string ussStyle)
  187. {
  188. this.ussStyle = ussStyle;
  189. }
  190. }
  191. /// <summary>
  192. /// Use this attribute to assign a clip, marker or track to a category in a submenu
  193. /// </summary>
  194. [AttributeUsage(AttributeTargets.Class)]
  195. internal class MenuCategoryAttribute : Attribute
  196. {
  197. /// <summary>
  198. /// The menu name of the category
  199. /// </summary>
  200. public readonly string category;
  201. public MenuCategoryAttribute(string category)
  202. {
  203. this.category = category ?? string.Empty;
  204. }
  205. }
  206. }