SelectMessage_UI.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class SelectMessage_UI : MonoBehaviour
  6. {
  7. public static void Message_Start(string message)
  8. {
  9. if (SelectMessage_UI.m_Now_MessageUI)
  10. {
  11. UnityEngine.Object.Destroy(SelectMessage_UI.m_Now_MessageUI);
  12. }
  13. GameObject original = Resources.Load<GameObject>("Prefab/SelectMessage_UI");
  14. SelectMessage_UI.m_Now_MessageUI = UnityEngine.Object.Instantiate<GameObject>(original);
  15. SelectMessage_UI.m_Now_MessageUI.GetComponent<SelectMessage_UI>().Initialize(message);
  16. }
  17. private void Initialize(string messsage)
  18. {
  19. GameObject gameObject = base.GetComponent<RectTransform>().Find("Image").gameObject;
  20. GameObject gameObject2 = base.GetComponent<RectTransform>().Find("Text").gameObject;
  21. this.m_MyText = gameObject2.GetComponent<Text>();
  22. this.m_MyText.text = messsage;
  23. this.m_MyImage = gameObject.GetComponent<Image>();
  24. if (this.Is_ImageDisplay())
  25. {
  26. this.m_Slide_Rect = gameObject.GetComponent<RectTransform>();
  27. this.m_Slide_Rect.sizeDelta = this.m_Image_Size;
  28. this.m_Slide_Rect.localPosition += Vector3.up * this.m_Image_Up + Vector3.right * this.m_Image_Size.x / 2f;
  29. this.m_MyText.enabled = false;
  30. this.m_MyImage.sprite = Resources.Load<Sprite>("SceneVRCommunication/Tablet/Sprite/LOOK_alpha");
  31. }
  32. else
  33. {
  34. this.m_Slide_Rect = gameObject2.GetComponent<RectTransform>();
  35. this.m_Slide_Rect.sizeDelta = Vector2.right * (float)this.m_Text_Size * (float)messsage.Length + Vector2.up * (float)this.m_Text_Size * 2f;
  36. this.m_MyImage.enabled = false;
  37. this.m_MyText.font = Resources.Load<Font>("Font/mplus-TESTFLIGHT-059/mplus-1mn-regular");
  38. this.m_MyText.fontSize = this.m_Text_Size;
  39. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  40. {
  41. this.m_MyText.fontSize = this.m_Text_Size;
  42. this.m_Slide_Rect.localPosition += Vector3.up * this.m_Text_Up + Vector3.right * (float)this.m_Text_Size * ((float)messsage.Length / 2f);
  43. }
  44. else
  45. {
  46. this.Set_Camera_Forward(base.GetComponent<RectTransform>());
  47. this.m_MyText.fontSize = this.m_Text_VRSize;
  48. RectTransform slide_Rect = this.m_Slide_Rect;
  49. Vector2 vector = Vector2.one * 0.5f;
  50. this.m_Slide_Rect.anchorMax = vector;
  51. vector = vector;
  52. this.m_Slide_Rect.anchorMin = vector;
  53. slide_Rect.pivot = vector;
  54. this.m_Slide_Rect.localPosition = Vector3.right * this.m_Right_Length;
  55. this.m_Slide_Rect.localEulerAngles = Vector3.zero;
  56. this.m_Slide_Rect.localScale = Vector3.one * 0.01f;
  57. gameObject2.GetComponent<Outline>().effectDistance = Vector2.one * this.m_OutLine_size;
  58. }
  59. }
  60. base.StartCoroutine(this.FrameIn());
  61. }
  62. private bool Is_ImageDisplay()
  63. {
  64. bool result = false;
  65. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON && (this.m_MyText.text == string.Empty || this.m_MyText.text == null))
  66. {
  67. result = true;
  68. }
  69. return result;
  70. }
  71. private void Set_Camera_Forward(RectTransform rect)
  72. {
  73. base.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
  74. base.GetComponent<Canvas>().sortingOrder = 4;
  75. Vector3 position = GameMain.Instance.MainCamera.GetRealHeadTransform().position;
  76. Vector3 a = GameMain.Instance.MainCamera.GetRealHeadTransform().TransformDirection(Vector3.forward);
  77. Vector3 vector = GameMain.Instance.MainCamera.GetRealHeadTransform().TransformDirection(Vector3.down);
  78. vector.x = 0f;
  79. rect.position = position + a * this.m_Forward_Length + vector.normalized * this.m_Down_Length;
  80. Vector3 eulerAngles = GameMain.Instance.MainCamera.GetRealHeadTransform().eulerAngles;
  81. rect.eulerAngles = new Vector3(eulerAngles.x, eulerAngles.y, 0f);
  82. rect.localScale = Vector3.one;
  83. rect.sizeDelta = Vector2.one * 100f;
  84. Vector2 vector2 = Vector2.one * 0.5f;
  85. rect.pivot = vector2;
  86. vector2 = vector2;
  87. rect.anchorMax = vector2;
  88. rect.anchorMin = vector2;
  89. base.GetComponent<CanvasScaler>().dynamicPixelsPerUnit = 5f;
  90. }
  91. private IEnumerator FrameIn()
  92. {
  93. float timer = 0f;
  94. Vector3 start_pos = this.m_Slide_Rect.localPosition;
  95. Vector3 end_pos = this.m_Slide_Rect.localPosition;
  96. if (this.m_MyImage.enabled)
  97. {
  98. end_pos.x = start_pos.x - (this.m_Image_Size.x + this.m_Image_Margin);
  99. }
  100. else if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  101. {
  102. end_pos.x = start_pos.x - ((float)(this.m_Text_Size * this.m_MyText.text.Length) + this.m_Text_Margin);
  103. }
  104. else
  105. {
  106. end_pos.x = 0f;
  107. }
  108. for (;;)
  109. {
  110. timer += Time.deltaTime;
  111. float angle = timer / this.m_Anime_Time * 90f;
  112. float rate = Mathf.Sin(0.0174532924f * angle);
  113. this.m_Slide_Rect.localPosition = (1f - rate) * start_pos + rate * end_pos;
  114. if (timer >= this.m_Anime_Time)
  115. {
  116. break;
  117. }
  118. yield return null;
  119. }
  120. yield return new WaitForSeconds(this.m_Display_Time);
  121. base.StartCoroutine(this.FadeOut());
  122. yield break;
  123. yield break;
  124. }
  125. private IEnumerator FadeOut()
  126. {
  127. float timer = 0f;
  128. Color text_color = this.m_MyText.color;
  129. Color image_color = this.m_MyImage.color;
  130. for (;;)
  131. {
  132. timer += Time.deltaTime;
  133. image_color.a = (text_color.a = 1f - timer / this.m_Fade_Time);
  134. if (this.m_MyImage.enabled)
  135. {
  136. this.m_MyImage.color = image_color;
  137. }
  138. else
  139. {
  140. this.m_MyText.color = text_color;
  141. }
  142. if (timer >= this.m_Fade_Time)
  143. {
  144. break;
  145. }
  146. yield return null;
  147. }
  148. UnityEngine.Object.Destroy(base.gameObject);
  149. yield break;
  150. yield break;
  151. }
  152. private const string m_MessageUI_ObjPath = "Prefab/SelectMessage_UI";
  153. private const string m_Font_Path = "Font/mplus-TESTFLIGHT-059/mplus-1mn-regular";
  154. private const string m_Image_Path = "SceneVRCommunication/Tablet/Sprite/LOOK_alpha";
  155. [SerializeField]
  156. private float m_Anime_Time = 1f;
  157. [SerializeField]
  158. private float m_Display_Time = 3f;
  159. [SerializeField]
  160. private float m_Fade_Time = 0.5f;
  161. [SerializeField]
  162. private int m_Text_Size = 25;
  163. [SerializeField]
  164. private Vector2 m_Image_Size = new Vector2(200f, 112.5f);
  165. [SerializeField]
  166. [Header("画像位置をどのくらい上に補正するか")]
  167. private float m_Image_Up = 70f;
  168. [SerializeField]
  169. private float m_Image_Margin = 16.5f;
  170. [SerializeField]
  171. [Header("文字位置をどのくらい上に補正するか")]
  172. private float m_Text_Up = 30f;
  173. [SerializeField]
  174. private float m_Text_Margin = 25f;
  175. [SerializeField]
  176. [Header("VR時用変数")]
  177. private float m_Right_Length = 3f;
  178. [SerializeField]
  179. private float m_Down_Length = 0.25f;
  180. [SerializeField]
  181. private float m_Forward_Length = 0.5f;
  182. [SerializeField]
  183. private int m_Text_VRSize = 5;
  184. [SerializeField]
  185. private float m_OutLine_size = 0.25f;
  186. private Text m_MyText;
  187. private Image m_MyImage;
  188. private RectTransform m_Slide_Rect;
  189. private static GameObject m_Now_MessageUI;
  190. }