MouseExposition.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using UnityEngine;
  3. using wf;
  4. public class MouseExposition : MonoBehaviour
  5. {
  6. public static MouseExposition GetObject()
  7. {
  8. if (GameObject.Find("UI Root/MouseExposition") != null)
  9. {
  10. return GameObject.Find("UI Root/MouseExposition").GetComponent<MouseExposition>();
  11. }
  12. GameObject gameObject = Utility.CreatePrefab(GameObject.Find("UI Root"), "System/Prefab/MouseExposition", true);
  13. gameObject.name = gameObject.name.Replace("(Clone)", string.Empty);
  14. MouseExposition component = gameObject.GetComponent<MouseExposition>();
  15. component.text = string.Empty;
  16. component.visible = true;
  17. GameObject gameObject2 = new GameObject();
  18. gameObject2.transform.SetParent(gameObject.transform);
  19. component.dummy_object_ = gameObject2;
  20. return gameObject.GetComponent<MouseExposition>();
  21. }
  22. private void Awake()
  23. {
  24. if (this.sprite_ != null)
  25. {
  26. return;
  27. }
  28. this.camera_ = GameObject.Find("UI Root/Camera").GetComponent<Camera>();
  29. this.sprite_ = base.GetComponentInChildren<UISprite>();
  30. this.label_ = base.GetComponentInChildren<UILabel>();
  31. this.visible_ = true;
  32. this.UpdateAlpha(0f);
  33. }
  34. public void Update()
  35. {
  36. if (!GameMain.Instance.VRMode)
  37. {
  38. Vector3 vector = this.camera_.ScreenToWorldPoint(Input.mousePosition);
  39. vector = base.transform.parent.InverseTransformPoint(vector);
  40. vector.z = 0f;
  41. vector.y -= (float)(this.sprite_.height + 15);
  42. vector.x += 10f;
  43. base.transform.localPosition = vector;
  44. }
  45. else
  46. {
  47. base.transform.localPosition = Vector3.zero;
  48. }
  49. if (!string.IsNullOrEmpty(this.label_.text) && this.sprite_.alpha < 1f)
  50. {
  51. if (base.GetComponent<iTween>() == null)
  52. {
  53. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  54. {
  55. "easetype",
  56. iTween.EaseType.easeOutCubic,
  57. "from",
  58. this.sprite_.alpha,
  59. "to",
  60. 1,
  61. "time",
  62. MouseExposition.kFadeTime,
  63. "onupdate",
  64. "UpdateAlpha"
  65. }));
  66. }
  67. }
  68. else if (string.IsNullOrEmpty(this.label_.text) && 0f < this.sprite_.alpha && base.GetComponent<iTween>() == null)
  69. {
  70. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  71. {
  72. "easetype",
  73. iTween.EaseType.easeOutCubic,
  74. "from",
  75. this.sprite_.alpha,
  76. "to",
  77. 0,
  78. "time",
  79. MouseExposition.kFadeTime,
  80. "onupdate",
  81. "UpdateAlpha"
  82. }));
  83. }
  84. }
  85. public void SetText(string draw_text, float time)
  86. {
  87. this.text = draw_text;
  88. if (!string.IsNullOrEmpty(this.label_.text) && this.sprite_.alpha < 1f)
  89. {
  90. if (base.GetComponent<iTween>() == null)
  91. {
  92. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  93. {
  94. "easetype",
  95. iTween.EaseType.easeOutCubic,
  96. "from",
  97. this.sprite_.alpha,
  98. "to",
  99. 1,
  100. "time",
  101. MouseExposition.kFadeTime,
  102. "onupdate",
  103. "UpdateAlpha"
  104. }));
  105. }
  106. }
  107. else if (string.IsNullOrEmpty(this.label_.text) && 0f < this.sprite_.alpha && base.GetComponent<iTween>() == null)
  108. {
  109. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  110. {
  111. "easetype",
  112. iTween.EaseType.easeOutCubic,
  113. "from",
  114. this.sprite_.alpha,
  115. "to",
  116. 0,
  117. "time",
  118. MouseExposition.kFadeTime,
  119. "onupdate",
  120. "UpdateAlpha"
  121. }));
  122. }
  123. iTween.ValueTo(base.gameObject, iTween.Hash(new object[]
  124. {
  125. "easetype",
  126. iTween.EaseType.linear,
  127. "from",
  128. 0,
  129. "to",
  130. 1,
  131. "time",
  132. time,
  133. "onUpdate",
  134. "OnUpdateDummy",
  135. "onComplete",
  136. "OnComplete"
  137. }));
  138. }
  139. public void OnUpdateDummy()
  140. {
  141. }
  142. public void OnComplete()
  143. {
  144. this.text = string.Empty;
  145. }
  146. public string text
  147. {
  148. get
  149. {
  150. return this.label_.text;
  151. }
  152. set
  153. {
  154. this.label_.text = value;
  155. this.label_.width = 0;
  156. this.label_.MakePixelPerfect();
  157. this.sprite_.width = this.label_.width + 15;
  158. if (!this.visible_)
  159. {
  160. return;
  161. }
  162. iTween.Stop(base.gameObject);
  163. iTween[] components = base.GetComponents<iTween>();
  164. for (int i = 0; i < components.Length; i++)
  165. {
  166. UnityEngine.Object.DestroyImmediate(components[i]);
  167. }
  168. }
  169. }
  170. public bool visible
  171. {
  172. get
  173. {
  174. return base.gameObject.activeSelf;
  175. }
  176. set
  177. {
  178. this.visible_ = value;
  179. if (!this.visible_)
  180. {
  181. iTween.Stop(base.gameObject);
  182. iTween[] componentsInChildren = base.GetComponentsInChildren<iTween>();
  183. for (int i = 0; i < componentsInChildren.Length; i++)
  184. {
  185. UnityEngine.Object.DestroyImmediate(componentsInChildren[i]);
  186. }
  187. this.UpdateAlpha(0f);
  188. }
  189. }
  190. }
  191. private void UpdateAlpha(float value)
  192. {
  193. this.sprite_.alpha = value;
  194. this.label_.alpha = value;
  195. float num = wf.Math.RoundMinMax(0.5f + value, 0f, 1f);
  196. this.sprite_.transform.localScale = new Vector2(num, num);
  197. }
  198. private static float kFadeTime = 0.3f;
  199. private Camera camera_;
  200. private UISprite sprite_;
  201. private UILabel label_;
  202. private bool visible_;
  203. private GameObject dummy_object_;
  204. }