TimelineAttributes.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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>
  69. /// using UnityEngine;
  70. /// using UnityEngine.Timeline;
  71. /// [TrackBindingType(typeof(Light), TrackBindingFlags.AllowCreateComponent)]
  72. /// public class LightTrack : TrackAsset
  73. /// {
  74. /// }
  75. /// </code>
  76. /// </example>
  77. /// <remarks>
  78. /// Use this attribute when creating Custom Tracks to specify the type of object the track requires a binding to.
  79. /// </remarks>
  80. [AttributeUsage(AttributeTargets.Class)]
  81. public class TrackBindingTypeAttribute : Attribute
  82. {
  83. /// <summary>
  84. /// The type of binding for the associate track
  85. /// </summary>
  86. public readonly Type type;
  87. /// <summary>
  88. /// Options for the the track binding
  89. /// </summary>
  90. public readonly TrackBindingFlags flags;
  91. public TrackBindingTypeAttribute(Type type)
  92. {
  93. this.type = type;
  94. this.flags = TrackBindingFlags.All;
  95. }
  96. public TrackBindingTypeAttribute(Type type, TrackBindingFlags flags)
  97. {
  98. this.type = type;
  99. this.flags = flags;
  100. }
  101. }
  102. // indicates that child tracks are permitted on a track
  103. // internal because not fully supported on custom classes yet
  104. [AttributeUsage(AttributeTargets.Class, Inherited = false)]
  105. class SupportsChildTracksAttribute : Attribute
  106. {
  107. public readonly Type childType;
  108. public readonly int levels;
  109. public SupportsChildTracksAttribute(Type childType = null, int levels = Int32.MaxValue)
  110. {
  111. this.childType = childType;
  112. this.levels = levels;
  113. }
  114. }
  115. // indicates that the type should not be put on a PlayableTrack
  116. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
  117. class IgnoreOnPlayableTrackAttribute : System.Attribute {}
  118. // used to flag properties as using a time field (second/frames) display
  119. class TimeFieldAttribute : PropertyAttribute
  120. {
  121. public enum UseEditMode
  122. {
  123. None,
  124. ApplyEditMode
  125. }
  126. public UseEditMode useEditMode { get; }
  127. public TimeFieldAttribute(UseEditMode useEditMode = UseEditMode.ApplyEditMode)
  128. {
  129. this.useEditMode = useEditMode;
  130. }
  131. }
  132. /// <summary>
  133. /// Use this attribute to hide a class from Timeline menus.
  134. /// </summary>
  135. [AttributeUsage(AttributeTargets.Class, Inherited = false)]
  136. public class HideInMenuAttribute : Attribute {}
  137. ///<summary>
  138. /// Use this attribute to customize the appearance of a Marker.
  139. /// </summary>
  140. /// Specify the style to use to draw a Marker.
  141. /// <example>
  142. /// [CustomStyle("MyStyle")]
  143. /// public class MyMarker : UnityEngine.Timeline.Marker {}
  144. /// </example>
  145. /// How to create a custom style rule:
  146. /// 1) Create a 'common.uss' USS file in an Editor folder in a StyleSheets/Extensions folder hierarchy.
  147. /// Example of valid folder paths:
  148. /// - Assets/Editor/StyleSheets/Extensions
  149. /// - Assets/Editor/Markers/StyleSheets/Extensions
  150. /// - Assets/Timeline/Editor/MyMarkers/StyleSheets/Extensions
  151. /// Rules in 'dark.uss' are used if you use the Pro Skin and rules in 'light.uss' are used otherwise.
  152. ///
  153. /// 2)In the USS file, create a styling rule to customize the appearance of the marker.
  154. /// <example>
  155. /// MyStyle
  156. /// {
  157. /// /* Specify the appearance of the marker in the collapsed state here. */
  158. /// }
  159. ///
  160. /// MyStyle:checked
  161. /// {
  162. /// /* Specify the appearance of the marker in the expanded state here. */
  163. /// }
  164. ///
  165. /// MyStyle:focused:checked
  166. /// {
  167. /// /* Specify the appearance of the marker in the selected state here. */
  168. /// }
  169. /// </example>
  170. /// <seealso cref="UnityEngine.Timeline.Marker"/>
  171. [AttributeUsage(AttributeTargets.Class)]
  172. public class CustomStyleAttribute : Attribute
  173. {
  174. /// <summary>
  175. /// The name of the USS style.
  176. /// </summary>
  177. public readonly string ussStyle;
  178. /// <param name="ussStyle">The name of the USS style.</param>
  179. public CustomStyleAttribute(string ussStyle)
  180. {
  181. this.ussStyle = ussStyle;
  182. }
  183. }
  184. /// <summary>
  185. /// Use this attribute to assign a clip, marker or track to a category in a submenu
  186. /// </summary>
  187. [AttributeUsage(AttributeTargets.Class)]
  188. internal class MenuCategoryAttribute : Attribute
  189. {
  190. /// <summary>
  191. /// The menu name of the category
  192. /// </summary>
  193. public readonly string category;
  194. public MenuCategoryAttribute(string category)
  195. {
  196. this.category = category ?? string.Empty;
  197. }
  198. }
  199. }