Attributes.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. namespace GraphProcessor
  6. {
  7. /// <summary>
  8. /// Tell that this field is will generate an input port
  9. /// </summary>
  10. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
  11. public class InputAttribute : Attribute
  12. {
  13. public string name;
  14. public bool allowMultiple = false;
  15. /// <summary>
  16. /// Mark the field as an input port
  17. /// </summary>
  18. /// <param name="name">display name</param>
  19. /// <param name="allowMultiple">is connecting multiple edges allowed</param>
  20. public InputAttribute(string name = null, bool allowMultiple = false)
  21. {
  22. this.name = name;
  23. this.allowMultiple = allowMultiple;
  24. }
  25. }
  26. /// <summary>
  27. /// Tell that this field is will generate an output port
  28. /// </summary>
  29. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
  30. public class OutputAttribute : Attribute
  31. {
  32. public string name;
  33. public bool allowMultiple = true;
  34. /// <summary>
  35. /// Mark the field as an output port
  36. /// </summary>
  37. /// <param name="name">display name</param>
  38. /// <param name="allowMultiple">is connecting multiple edges allowed</param>
  39. public OutputAttribute(string name = null, bool allowMultiple = true)
  40. {
  41. this.name = name;
  42. this.allowMultiple = allowMultiple;
  43. }
  44. }
  45. /// <summary>
  46. /// Creates a vertical port instead of the default horizontal one
  47. /// </summary>
  48. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
  49. public class VerticalAttribute : Attribute
  50. {
  51. }
  52. /// <summary>
  53. /// Register the node in the NodeProvider class. The node will also be available in the node creation window.
  54. /// </summary>
  55. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  56. public class NodeMenuItemAttribute : Attribute
  57. {
  58. public string menuTitle;
  59. public Type onlyCompatibleWithGraph;
  60. /// <summary>
  61. /// Register the node in the NodeProvider class. The node will also be available in the node creation window.
  62. /// </summary>
  63. /// <param name="menuTitle">Path in the menu, use / as folder separators</param>
  64. public NodeMenuItemAttribute(string menuTitle = null, Type onlyCompatibleWithGraph = null)
  65. {
  66. this.menuTitle = menuTitle;
  67. this.onlyCompatibleWithGraph = onlyCompatibleWithGraph;
  68. }
  69. }
  70. /// <summary>
  71. /// Set a custom drawer for a field. It can then be created using the FieldFactory
  72. /// </summary>
  73. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
  74. [Obsolete("You can use the standard Unity CustomPropertyDrawer instead.")]
  75. public class FieldDrawerAttribute : Attribute
  76. {
  77. public Type fieldType;
  78. /// <summary>
  79. /// Register a custom view for a type in the FieldFactory class
  80. /// </summary>
  81. /// <param name="fieldType"></param>
  82. public FieldDrawerAttribute(Type fieldType)
  83. {
  84. this.fieldType = fieldType;
  85. }
  86. }
  87. /// <summary>
  88. /// Allow you to customize the input function of a port
  89. /// </summary>
  90. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  91. public class CustomPortInputAttribute : Attribute
  92. {
  93. public string fieldName;
  94. public Type inputType;
  95. public bool allowCast;
  96. /// <summary>
  97. /// Allow you to customize the input function of a port.
  98. /// See CustomPortsNode example in Samples.
  99. /// </summary>
  100. /// <param name="fieldName">local field of the node</param>
  101. /// <param name="inputType">type of input of the port</param>
  102. /// <param name="allowCast">if cast is allowed when connecting an edge</param>
  103. public CustomPortInputAttribute(string fieldName, Type inputType, bool allowCast = true)
  104. {
  105. this.fieldName = fieldName;
  106. this.inputType = inputType;
  107. this.allowCast = allowCast;
  108. }
  109. }
  110. /// <summary>
  111. /// Allow you to customize the input function of a port
  112. /// </summary>
  113. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  114. public class CustomPortOutputAttribute : Attribute
  115. {
  116. public string fieldName;
  117. public Type outputType;
  118. public bool allowCast;
  119. /// <summary>
  120. /// Allow you to customize the output function of a port.
  121. /// See CustomPortsNode example in Samples.
  122. /// </summary>
  123. /// <param name="fieldName">local field of the node</param>
  124. /// <param name="inputType">type of input of the port</param>
  125. /// <param name="allowCast">if cast is allowed when connecting an edge</param>
  126. public CustomPortOutputAttribute(string fieldName, Type outputType, bool allowCast = true)
  127. {
  128. this.fieldName = fieldName;
  129. this.outputType = outputType;
  130. this.allowCast = allowCast;
  131. }
  132. }
  133. /// <summary>
  134. /// Allow you to modify the generated port view from a field. Can be used to generate multiple ports from one field.
  135. /// </summary>
  136. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  137. public class CustomPortBehaviorAttribute : Attribute
  138. {
  139. public string fieldName;
  140. /// <summary>
  141. /// Allow you to modify the generated port view from a field. Can be used to generate multiple ports from one field.
  142. /// You must add this attribute on a function of this signature
  143. /// <code>
  144. /// IEnumerable&lt;PortData&gt; MyCustomPortFunction(List&lt;SerializableEdge&gt; edges);
  145. /// </code>
  146. /// </summary>
  147. /// <param name="fieldName">local node field name</param>
  148. public CustomPortBehaviorAttribute(string fieldName)
  149. {
  150. this.fieldName = fieldName;
  151. }
  152. }
  153. /// <summary>
  154. /// Allow to bind a method to generate a specific set of ports based on a field type in a node
  155. /// </summary>
  156. [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
  157. public class CustomPortTypeBehavior : Attribute
  158. {
  159. /// <summary>
  160. /// Target type
  161. /// </summary>
  162. public Type type;
  163. public CustomPortTypeBehavior(Type type)
  164. {
  165. this.type = type;
  166. }
  167. }
  168. /// <summary>
  169. /// Allow you to have a custom view for your stack nodes
  170. /// </summary>
  171. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
  172. public class CustomStackNodeView : Attribute
  173. {
  174. public Type stackNodeType;
  175. /// <summary>
  176. /// Allow you to have a custom view for your stack nodes
  177. /// </summary>
  178. /// <param name="stackNodeType">The type of the stack node you target</param>
  179. public CustomStackNodeView(Type stackNodeType)
  180. {
  181. this.stackNodeType = stackNodeType;
  182. }
  183. }
  184. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
  185. public class VisibleIf : Attribute
  186. {
  187. public string fieldName;
  188. public object value;
  189. public VisibleIf(string fieldName, object value)
  190. {
  191. this.fieldName = fieldName;
  192. this.value = value;
  193. }
  194. }
  195. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
  196. public class ShowInInspector : Attribute
  197. {
  198. public bool showInNode;
  199. public ShowInInspector(bool showInNode = false)
  200. {
  201. this.showInNode = showInNode;
  202. }
  203. }
  204. [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
  205. public class ShowAsDrawer : Attribute
  206. {
  207. }
  208. [AttributeUsage(AttributeTargets.Field)]
  209. public class SettingAttribute : Attribute
  210. {
  211. public string name;
  212. public SettingAttribute(string name = null)
  213. {
  214. this.name = name;
  215. }
  216. }
  217. [AttributeUsage(AttributeTargets.Method)]
  218. public class IsCompatibleWithGraph : Attribute {}
  219. }