API_Module_Tooltip.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using SC.XR.Unity.Module_Tooltip;
  5. public class API_Module_Tooltip
  6. {
  7. /// <summary>
  8. /// Return whether the tooltip is activie.
  9. /// </summary>
  10. /// <param name="tooltip">GameObject of Tooltip.</param>
  11. /// <returns></returns>
  12. public static bool IsActivie(GameObject tooltip)
  13. {
  14. return tooltip.activeSelf;
  15. }
  16. /// <summary>
  17. /// Set active of the tooltip.
  18. /// </summary>
  19. /// <param name="tooltip">GameObject of Tooltip.</param>
  20. /// <param name="state">True to set active and false to set inactive.</param>
  21. public static void SetActive(GameObject tooltip, bool state)
  22. {
  23. tooltip.SetActive(state);
  24. }
  25. /// <summary>
  26. /// Return the position of target.
  27. /// </summary>
  28. /// <param name="tooltip">GameObject of Tooltip.</param>
  29. /// <param name="isWorldPosition">True to return worldPosition,false to return localPosition.</param>
  30. /// <returns></returns>
  31. public static Vector3 GetTargetPosition(GameObject tooltip, bool isWorldPosition)
  32. {
  33. return tooltip.GetComponent<Modules_TooltipLineRenderer>().API_GetTargetPosition(isWorldPosition);
  34. }
  35. /// <summary>
  36. /// Set new position of target.
  37. /// </summary>
  38. /// <param name="tooltip">GameObject of Tooltip.</param>
  39. /// <param name="newPosition">New position of targer.</param>
  40. /// <param name="isWorldPosition">Whether new position is a world position or a local position.</param>
  41. public static void SetTargetPosition(GameObject tooltip, Vector3 newPosition, bool isWorldPosition)
  42. {
  43. tooltip.GetComponent<Modules_TooltipLineRenderer>().API_SetTargetPosition(newPosition, isWorldPosition);
  44. }
  45. /// <summary>
  46. /// Return he position of lable.
  47. /// </summary>
  48. /// <param name="tooltip">GameObject of Tooltip.</param>
  49. /// <param name="isWorldPosition">Whether new position is a world position or a local position.</param>
  50. /// <returns></returns>
  51. public static Vector3 GetLablePosition(GameObject tooltip, bool isWorldPosition)
  52. {
  53. return tooltip.GetComponent<Modules_TooltipLineRenderer>().API_GetLablePosition(isWorldPosition);
  54. }
  55. /// <summary>
  56. /// Set new position of lable.
  57. /// </summary>
  58. /// <param name="tooltip">GameObject of Tooltip.</param>
  59. /// <param name="newPosition">New position of lable.</param>
  60. /// <param name="isWorldPosition">Whether new position is a world position or a local position.</param>
  61. public static void SetLablePosition(GameObject tooltip, Vector3 newPosition, bool isWorldPosition)
  62. {
  63. tooltip.GetComponent<Modules_TooltipLineRenderer>().API_SetLablePosition(newPosition, isWorldPosition);
  64. }
  65. /// <summary>
  66. /// Return the type of TooltipStartPointLocation.
  67. /// </summary>
  68. /// <param name="tooltip">GameObject of Tooltip.</param>
  69. /// <returns></returns>
  70. public static Modules_TooltipLineRenderer.TooltipStartPointLocation GetStartPoint(GameObject tooltip)
  71. {
  72. return tooltip.GetComponent<Modules_TooltipLineRenderer>().API_GetStartPoint();
  73. }
  74. /// <summary>
  75. /// Set the type of TooltipStartPointLocation.
  76. /// </summary>
  77. /// <param name="tooltip">GameObject of Tooltip.</param>
  78. /// <param name="tooltipStartPoint">Type of TooltipStartPointLocation.</param>
  79. public static void SetStartPoint(GameObject tooltip, Modules_TooltipLineRenderer.TooltipStartPointLocation tooltipStartPoint)
  80. {
  81. tooltip.GetComponent<Modules_TooltipLineRenderer>().API_SetStartPoint(tooltipStartPoint);
  82. }
  83. /// <summary>
  84. /// Return the position of startpoint.
  85. /// </summary>
  86. /// <param name="tooltip">GameObject of Tooltip.</param>
  87. /// <param name="isWorldPosition">Whether new position is a world position or a local position.</param>
  88. /// <returns></returns>
  89. public static Vector3 GetStartPointPosition(GameObject tooltip, bool isWorldPosition)
  90. {
  91. return tooltip.GetComponent<Modules_TooltipLineRenderer>().API_GetStartPointPosition(isWorldPosition);
  92. }
  93. /// <summary>
  94. /// Set the width of line.(Range(0, 0.01))
  95. /// </summary>
  96. /// <param name="tooltip">GameObject of Tooltip.</param>
  97. /// <param name="width">Width of line.</param>
  98. public static void SetLineWidth(GameObject tooltip, float width)
  99. {
  100. tooltip.GetComponent<Modules_TooltipLineRenderer>().API_SetLineWidth(width);
  101. }
  102. /// <summary>
  103. /// Return the text of lable.
  104. /// </summary>
  105. /// <param name="tooltip">GameObject of Tooltip.</param>
  106. /// <returns></returns>
  107. public static string GetLableText(GameObject tooltip)
  108. {
  109. return tooltip.GetComponent<Modules_TooltipUI>().API_GetLableText();
  110. }
  111. /// <summary>
  112. /// Set text of lable.
  113. /// </summary>
  114. /// <param name="tooltip">GameObject of Tooltip.</param>
  115. /// <param name="newText">Text to set.</param>
  116. public static void SetLableText(GameObject tooltip, string newText)
  117. {
  118. tooltip.GetComponent<Modules_TooltipUI>().API_SetLableText(newText);
  119. }
  120. /// <summary>
  121. /// Set color of text.
  122. /// </summary>
  123. /// <param name="tooltip">GameObject of Tooltip.</param>
  124. /// <param name="color">Color to set.</param>
  125. public static void SetLableTextColor(GameObject tooltip, Color color)
  126. {
  127. tooltip.GetComponent<Modules_TooltipUI>().API_SetLableTextColor(color);
  128. }
  129. /// <summary>
  130. /// Set size of text.
  131. /// </summary>
  132. /// <param name="tooltip">GameObject of Tooltip.</param>
  133. /// <param name="size">Size to set.</param>
  134. public static void SetLableTextSize(GameObject tooltip, float size)
  135. {
  136. tooltip.GetComponent<Modules_TooltipUI>().API_SetLableTextSize(size);
  137. }
  138. /// <summary>
  139. /// Set size of lable(background and text).
  140. /// </summary>
  141. /// <param name="tooltip">GameObject of Tooltip.</param>
  142. /// <param name="width">Width of lable.</param>
  143. /// <param name="height">Height of lable.</param>
  144. public static void SetLableSize(GameObject tooltip, float width, float height)
  145. {
  146. tooltip.GetComponent<Modules_TooltipUI>().API_SetLableSize(width, height);
  147. }
  148. /// <summary>
  149. /// Set scale of lable.(Range(0, 0.01))
  150. /// </summary>
  151. /// <param name="tooltip">GameObject of Tooltip.</param>
  152. /// <param name="scale">Scale size.</param>
  153. public static void SetLableScale(GameObject tooltip, float scale)
  154. {
  155. tooltip.GetComponent<Modules_TooltipUI>().API_SetLableScale(scale);
  156. }
  157. /// <summary>
  158. /// Set whether the startpoint is visible.
  159. /// </summary>
  160. /// <param name="tooltip">GameObject of Tooltip.</param>
  161. /// <param name="state">Whether the startpoint is visible.</param>
  162. public static void SetStartPointVisible(GameObject tooltip, bool state)
  163. {
  164. tooltip.GetComponent<Modules_TooltipLineRenderer>().API_SetStartPointVisible(state);
  165. }
  166. /// <summary>
  167. /// Set whether the line is visible.
  168. /// </summary>
  169. /// <param name="tooltip">GameObject of Tooltip.</param>
  170. /// <param name="state">Whether the line is visible.</param>
  171. public static void SetLineVisible(GameObject tooltip, bool state)
  172. {
  173. tooltip.GetComponent<Modules_TooltipLineRenderer>().API_SetLineVisible(state);
  174. }
  175. /// <summary>
  176. /// Return the type of TooltipRotationAxis whitch lable rotates.
  177. /// </summary>
  178. /// <param name="tooltip">GameObject of Tooltip.</param>
  179. /// <returns></returns>
  180. public static Modules_Tooltip.TooltipRotationAxis GetTooltipRotationAxis(GameObject tooltip)
  181. {
  182. return tooltip.GetComponent<Modules_Tooltip>().API_GetTooltipRotationAxis();
  183. }
  184. /// <summary>
  185. /// Set the type of TooltipRotationAxis whitch lable rotates.
  186. /// </summary>
  187. /// <param name="tooltip">GameObject of Tooltip.</param>
  188. /// <param name="tooltipRotationAxis"></param>
  189. public static void SetTooltipRotationAxis(GameObject tooltip, Modules_Tooltip.TooltipRotationAxis tooltipRotationAxis)
  190. {
  191. tooltip.GetComponent<Modules_Tooltip>().API_SetTooltipRotationAxis(tooltipRotationAxis);
  192. }
  193. /// <summary>
  194. /// Change the target of TooltipRotationAxis whitch lable rotates.
  195. /// </summary>
  196. /// <param name="tooltip">GameObject of Tooltip.</param>
  197. /// <param name="target">New target of TooltipRotationAxis whitch lable rotates.</param>
  198. public static void SetTooltipRotationAxisTarget(GameObject tooltip, Transform target)
  199. {
  200. tooltip.GetComponent<Modules_Tooltip>().API_SetTooltipRotationAxisTarget(target);
  201. }
  202. public static Modules_TooltipCtrl.TooltipShowTrigger GetTooltipShowTrigger(Modules_TooltipCtrl aimObject, GameObject tooltip)
  203. {
  204. return aimObject.API_GetTooltipShowTrigger(tooltip);
  205. }
  206. /// <summary>
  207. /// Set TooltipShowTrigger of the tooltip.(The tooltip should be created by Modules_TooltipCtrl.)
  208. /// </summary>
  209. /// <param name="aimObject">The parent gameobject of tooltip with Modules_TooltipCtrl.</param>
  210. /// <param name="tooltip">GameObject of Tooltip.</param>
  211. /// <param name="showTrigger">When will the tooltip show.</param>
  212. public static void SetTooltipShowTrigger(Modules_TooltipCtrl aimObject, GameObject tooltip, Modules_TooltipCtrl.TooltipShowTrigger showTrigger)
  213. {
  214. aimObject.API_SetTooltipShowTrigger(tooltip, showTrigger);
  215. }
  216. /// <summary>
  217. /// Add a new tooltip as chlid of aimObject.
  218. /// </summary>
  219. /// <param name="aimObject">The parent gameobject of new tooltip.</param>
  220. /// <param name="showTrigger">When will the tooltip show.</param>
  221. /// <param name="text">Text of lable.</param>
  222. /// <returns></returns>
  223. public static GameObject AddNewTooltip(GameObject parentObject, Modules_TooltipCtrl.TooltipShowTrigger showTrigger, string text)
  224. {
  225. if (parentObject.GetComponent<Modules_TooltipCtrl>())
  226. {
  227. return parentObject.GetComponent<Modules_TooltipCtrl>().API_AddNewTooltip(showTrigger, text);
  228. }
  229. else
  230. {
  231. if (!parentObject.GetComponent<Collider>())
  232. {
  233. parentObject.AddComponent<BoxCollider>();
  234. }
  235. parentObject.AddComponent<Modules_TooltipCtrl>();
  236. return parentObject.GetComponent<Modules_TooltipCtrl>().API_AddNewTooltip(showTrigger, text);
  237. }
  238. }
  239. /// <summary>
  240. /// Delete the tooltip whitch as a child gameobject.(The tooltip should be created by Modules_TooltipCtrl.)
  241. /// </summary>
  242. /// <param name="aimObject">The parent gameobject of tooltip with Modules_TooltipCtrl.</param>
  243. /// <param name="tooltip">GameObject of Tooltip.</param>
  244. public static void DelTooltip(Modules_TooltipCtrl parentObject, GameObject tooltip)
  245. {
  246. parentObject.API_DelTooltip(tooltip);
  247. }
  248. }