MouseExposition.cs 5.0 KB

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