MouseExposition.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. }
  157. }
  158. public string text
  159. {
  160. get
  161. {
  162. return this.label_.text;
  163. }
  164. set
  165. {
  166. this.label_.text = value;
  167. this.label_.width = 0;
  168. this.label_.MakePixelPerfect();
  169. this.sprite_.width = this.label_.width + 15;
  170. if (!this.visible_)
  171. {
  172. return;
  173. }
  174. iTween.Stop(base.gameObject);
  175. iTween[] components = base.GetComponents<iTween>();
  176. for (int i = 0; i < components.Length; i++)
  177. {
  178. UnityEngine.Object.DestroyImmediate(components[i]);
  179. }
  180. }
  181. }
  182. public bool visible
  183. {
  184. get
  185. {
  186. return base.gameObject.activeSelf;
  187. }
  188. set
  189. {
  190. this.visible_ = value;
  191. if (!this.visible_)
  192. {
  193. iTween.Stop(base.gameObject);
  194. iTween[] componentsInChildren = base.GetComponentsInChildren<iTween>();
  195. for (int i = 0; i < componentsInChildren.Length; i++)
  196. {
  197. UnityEngine.Object.DestroyImmediate(componentsInChildren[i]);
  198. }
  199. this.UpdateAlpha(0f);
  200. }
  201. }
  202. }
  203. private void UpdateAlpha(float value)
  204. {
  205. this.sprite_.alpha = value;
  206. this.label_.alpha = value;
  207. float num = wf.Math.RoundMinMax(0.5f + value, 0f, 1f);
  208. this.sprite_.transform.localScale = new Vector2(num, num);
  209. }
  210. private static float kFadeTime = 0.3f;
  211. private Camera camera_;
  212. private UISprite sprite_;
  213. private UILabel label_;
  214. private bool visible_;
  215. private GameObject dummy_object_;
  216. }