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

GenericControl.cs 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Path.GUIFramework
  4. {
  5. /// <summary>
  6. /// Represents a generic UI control.
  7. /// </summary>
  8. public class GenericControl : Control
  9. {
  10. /// <summary>
  11. /// Func for OnBeginLayout
  12. /// </summary>
  13. public Func<IGUIState, LayoutData> onBeginLayout;
  14. /// <summary>
  15. /// Action for OnEndLayout
  16. /// </summary>
  17. public Action<IGUIState> onEndLayout;
  18. /// <summary>
  19. /// Action for OnRepaint
  20. /// </summary>
  21. public Action<IGUIState, Control, int> onRepaint;
  22. /// <summary>
  23. /// Func for GetCount
  24. /// </summary>
  25. public Func<int> count;
  26. /// <summary>
  27. /// Func for GetPosition
  28. /// </summary>
  29. public Func<int, Vector3> position;
  30. /// <summary>
  31. /// Func for GetDistance
  32. /// </summary>
  33. public Func<IGUIState, int, float> distance;
  34. /// <summary>
  35. /// Func for GetForward
  36. /// </summary>
  37. public Func<int, Vector3> forward;
  38. /// <summary>
  39. /// Func for GetUp
  40. /// </summary>
  41. public Func<int, Vector3> up;
  42. /// <summary>
  43. /// Func for GetRight
  44. /// </summary>
  45. public Func<int, Vector3> right;
  46. /// <summary>
  47. /// Func for GetUserData
  48. /// </summary>
  49. public Func<int, object> userData;
  50. /// <summary>
  51. /// Initializes and returns an instance of GenericControl
  52. /// </summary>
  53. /// <param name="name">The name of the generic control.</param>
  54. public GenericControl(string name) : base(name)
  55. {
  56. }
  57. /// <summary>
  58. /// Gets the number of sub-controllers.
  59. /// </summary>
  60. /// <remarks>
  61. /// By default, this is `1`. If you implement your own controller and want to use multiple sub-controllers within it, you can assign getCount to a function that returns the number of sub-controllers.
  62. /// </remarks>
  63. /// <returns>Returns the number of sub-controllers. If you do not assign getCount, this returns 1.</returns>
  64. protected override int GetCount()
  65. {
  66. if (count != null)
  67. return count();
  68. return base.GetCount();
  69. }
  70. /// <summary>
  71. /// Called when the control ends its layout.
  72. /// </summary>
  73. /// <param name="guiState">The current state of the custom editor.</param>
  74. protected override void OnEndLayout(IGUIState guiState)
  75. {
  76. if (onEndLayout != null)
  77. onEndLayout(guiState);
  78. }
  79. /// <summary>
  80. /// Called when the control repaints its contents.
  81. /// </summary>
  82. /// <param name="guiState">The current state of the custom editor.</param>
  83. /// <param name="index">Current Index</param>
  84. protected override void OnRepaint(IGUIState guiState, int index)
  85. {
  86. if (onRepaint != null)
  87. onRepaint(guiState, this, index);
  88. }
  89. /// <summary>
  90. /// Called when the control begins its layout.
  91. /// </summary>
  92. /// <param name="data">The layout data.</param>
  93. /// <param name="guiState">The current state of the custom editor.</param>
  94. /// <returns>The LayoutData</returns>
  95. protected override LayoutData OnBeginLayout(LayoutData data, IGUIState guiState)
  96. {
  97. if (onBeginLayout != null)
  98. return onBeginLayout(guiState);
  99. return data;
  100. }
  101. /// <summary>
  102. /// Gets the position of the control.
  103. /// </summary>
  104. /// <param name="guiState">The current state of the custom editor.</param>
  105. /// <param name="index">The Index</param>
  106. /// <returns>The position</returns>
  107. protected override Vector3 GetPosition(IGUIState guiState, int index)
  108. {
  109. if (position != null)
  110. return position(index);
  111. return base.GetPosition(guiState,index);
  112. }
  113. /// <summary>
  114. /// Gets the distance from the Scene view camera to the control.
  115. /// </summary>
  116. /// <param name="guiState">The current state of the custom editor.</param>
  117. /// <param name="index">The Index</param>
  118. /// <returns>Returns the distance from the Scene view camera to the control.</returns>
  119. protected override float GetDistance(IGUIState guiState, int index)
  120. {
  121. if (distance != null)
  122. return distance(guiState, index);
  123. return base.GetDistance(guiState, index);
  124. }
  125. /// <summary>
  126. /// Gets the forward vector of the control.
  127. /// </summary>
  128. /// <param name="guiState">The current state of the custom editor.</param>
  129. /// <param name="index">The Index</param>
  130. /// <returns>Returns the generic control's forward vector.</returns>
  131. protected override Vector3 GetForward(IGUIState guiState, int index)
  132. {
  133. if (forward != null)
  134. return forward(index);
  135. return base.GetForward(guiState,index);
  136. }
  137. /// <summary>
  138. /// Gets the up vector of the control.
  139. /// </summary>
  140. /// <param name="guiState">The current state of the custom editor.</param>
  141. /// <param name="index">The Index</param>
  142. /// <returns>Returns the generic control's up vector.</returns>
  143. protected override Vector3 GetUp(IGUIState guiState, int index)
  144. {
  145. if (up != null)
  146. return up(index);
  147. return base.GetUp(guiState,index);
  148. }
  149. /// <summary>
  150. /// Gets the right vector of the control.
  151. /// </summary>
  152. /// <param name="guiState">The current state of the custom editor.</param>
  153. /// <param name="index">The Index</param>
  154. /// <returns>Returns the generic control's right vector.</returns>
  155. protected override Vector3 GetRight(IGUIState guiState, int index)
  156. {
  157. if (right != null)
  158. return right(index);
  159. return base.GetRight(guiState,index);
  160. }
  161. /// <summary>
  162. /// Override for GetUserData
  163. /// </summary>
  164. /// <param name="guiState">The current state of the custom editor.</param>
  165. /// <param name="index">The Index</param>
  166. /// <returns>Return the user data</returns>
  167. protected override object GetUserData(IGUIState guiState, int index)
  168. {
  169. if (userData != null)
  170. return userData(index);
  171. return base.GetUserData(guiState,index);
  172. }
  173. }
  174. }