FreeScene_UI.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class FreeScene_UI : MonoBehaviour
  8. {
  9. public static void FreeScene_Start(string para, Action end_action = null)
  10. {
  11. if (FreeScene_UI.m_Now_UI)
  12. {
  13. UnityEngine.Object.Destroy(FreeScene_UI.m_Now_UI);
  14. }
  15. GameObject original = Resources.Load<GameObject>("Prefab/FreeScene_UI");
  16. FreeScene_UI.m_Now_UI = UnityEngine.Object.Instantiate<GameObject>(original);
  17. FreeScene_UI.m_Now_UI.GetComponent<FreeScene_UI>().Initialize(para, end_action);
  18. }
  19. private void Initialize(string para, Action end_action)
  20. {
  21. this.m_Use_String = para;
  22. this.m_End_Action = end_action;
  23. this.m_All_Text_Rect = new Dictionary<Text, RectTransform>();
  24. base.StartCoroutine(this.UI_Animation());
  25. }
  26. private void Set_Camera_Forward(RectTransform rect)
  27. {
  28. Vector3 position = GameMain.Instance.MainCamera.GetRealHeadTransform().position;
  29. Vector3 a = GameMain.Instance.MainCamera.GetRealHeadTransform().TransformDirection(Vector3.forward);
  30. rect.position = position + a * this.m_Forward_Length;
  31. Vector3 eulerAngles = GameMain.Instance.MainCamera.GetRealHeadTransform().eulerAngles;
  32. rect.eulerAngles = new Vector3(eulerAngles.x, eulerAngles.y, 0f);
  33. rect.localScale = Vector3.one;
  34. Vector2 vector = Vector2.one * 0.5f;
  35. rect.pivot = vector;
  36. vector = vector;
  37. rect.anchorMax = vector;
  38. rect.anchorMin = vector;
  39. base.GetComponent<CanvasScaler>().dynamicPixelsPerUnit = 5f;
  40. }
  41. private void Set_Text_Pos(ref List<Vector3> first_pos, ref List<Vector3> end_pos, RectTransform bace)
  42. {
  43. int num = 0;
  44. int max_count = 0;
  45. foreach (char c in this.m_Use_String)
  46. {
  47. int num2 = num / this.m_Line_Count;
  48. GameObject gameObject = new GameObject("Text", new Type[]
  49. {
  50. typeof(RectTransform),
  51. typeof(CanvasRenderer),
  52. typeof(Text),
  53. typeof(Outline)
  54. });
  55. RectTransform component = gameObject.GetComponent<RectTransform>();
  56. component.SetParent(base.transform);
  57. component.localEulerAngles = Vector3.zero;
  58. component.sizeDelta = Vector2.one * 100f;
  59. RectTransform rectTransform = component;
  60. Vector2 vector = Vector2.one * 0.5f;
  61. component.pivot = vector;
  62. vector = vector;
  63. component.anchorMax = vector;
  64. rectTransform.anchorMin = vector;
  65. Text component2 = gameObject.GetComponent<Text>();
  66. component2.font = Resources.Load<Font>("Font/FreeScene_UI_Font");
  67. component2.color = Color.white;
  68. component2.text = c.ToString();
  69. component2.alignment = TextAnchor.MiddleCenter;
  70. Color black = Color.black;
  71. black.a = 0.5f;
  72. gameObject.GetComponent<Outline>().effectColor = black;
  73. Vector3 localPosition;
  74. Vector3 item;
  75. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  76. {
  77. float x = bace.sizeDelta.x / 2f + component.sizeDelta.x / 2f + (float)(this.m_2D_Text_Size * (num % this.m_Line_Count));
  78. float y = (float)(-(float)num2 * this.m_2D_Text_Size);
  79. component.localPosition = new Vector3(x, y, 0f);
  80. component.localScale = Vector3.one;
  81. component2.fontSize = this.m_2D_Text_Size;
  82. gameObject.GetComponent<Outline>().effectDistance = Vector2.one * this.m_2D_Outline_Size;
  83. item = (localPosition = component.localPosition);
  84. item.x = -(bace.sizeDelta.x / 2f + component.sizeDelta.x / 2f + (float)(this.m_2D_Text_Size * (this.m_Line_Count - num % this.m_Line_Count)));
  85. }
  86. else
  87. {
  88. float x = this.m_Width_Length + (float)(this.m_Text_Size * (num % this.m_Line_Count)) * 0.01f;
  89. float y = (float)(-(float)num2 * this.m_Text_Size) * 0.01f;
  90. component.localScale = Vector3.one * 0.01f;
  91. component.localPosition = new Vector3(x, y, 0f);
  92. component2.fontSize = this.m_Text_Size;
  93. gameObject.GetComponent<Outline>().effectDistance = Vector2.one * this.m_Outline_Size;
  94. item = (localPosition = component.localPosition);
  95. item.x = -(this.m_Width_Length + (float)(this.m_Text_Size * (this.m_Line_Count - num % this.m_Line_Count)) * 0.01f);
  96. }
  97. first_pos.Add(localPosition);
  98. end_pos.Add(item);
  99. this.m_All_Text_Rect.Add(component2, component);
  100. if (c == '\n')
  101. {
  102. num += this.m_Line_Count - num % this.m_Line_Count;
  103. }
  104. else
  105. {
  106. num++;
  107. }
  108. if (num % this.m_Line_Count > max_count)
  109. {
  110. max_count = num % this.m_Line_Count;
  111. }
  112. }
  113. List<Vector3> source = new List<Vector3>(first_pos);
  114. List<Vector3> source2 = new List<Vector3>(end_pos);
  115. float center = (float)((this.m_Use_String.Length - 1) / max_count) * 0.5f;
  116. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  117. {
  118. first_pos = (from e in source
  119. select e += Vector3.up * center * (float)this.m_2D_Text_Size).ToList<Vector3>();
  120. source2 = (from e in source2
  121. select e += Vector3.up * center * (float)this.m_2D_Text_Size).ToList<Vector3>();
  122. end_pos = (from e in source2
  123. select e += Vector3.right * (float)(this.m_Line_Count - max_count) * (float)this.m_2D_Text_Size).ToList<Vector3>();
  124. }
  125. else
  126. {
  127. first_pos = (from e in source
  128. select e += Vector3.up * center * (float)this.m_Text_Size * 0.01f).ToList<Vector3>();
  129. source2 = (from e in source2
  130. select e += Vector3.up * center * (float)this.m_Text_Size * 0.01f).ToList<Vector3>();
  131. end_pos = (from e in source2
  132. select e += Vector3.right * (float)(this.m_Line_Count - max_count) * (float)this.m_Text_Size * 0.01f).ToList<Vector3>();
  133. }
  134. }
  135. private IEnumerator UI_Animation()
  136. {
  137. RectTransform my_rect = base.GetComponent<RectTransform>();
  138. if (GameMain.Instance.VRDeviceTypeID != GameMain.VRDeviceType.NON)
  139. {
  140. this.Set_Camera_Forward(my_rect);
  141. base.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
  142. base.GetComponent<Canvas>().sortingOrder = 4;
  143. }
  144. List<Vector3> start_pos = new List<Vector3>();
  145. List<Vector3> end_pos = new List<Vector3>();
  146. this.Set_Text_Pos(ref start_pos, ref end_pos, my_rect);
  147. float timer = 0f;
  148. for (;;)
  149. {
  150. timer += Time.deltaTime;
  151. int count = 0;
  152. int string_count = 0;
  153. bool is_end = true;
  154. foreach (KeyValuePair<Text, RectTransform> keyValuePair in this.m_All_Text_Rect)
  155. {
  156. float num = this.m_Anime_Time + this.m_Anime_Lag * (float)(string_count % this.m_Line_Count);
  157. float num2 = timer;
  158. if (timer >= num / 2f + this.m_Stop_Time)
  159. {
  160. num2 -= this.m_Stop_Time;
  161. }
  162. if (num2 <= num)
  163. {
  164. is_end = false;
  165. float num3 = 180f * (num2 / num);
  166. float num4 = 1f - Mathf.Abs(Mathf.Sin(num3 * 0.0174532924f));
  167. Vector3 vector = 0.5f * start_pos[count] + 0.5f * end_pos[count];
  168. Vector3 a = vector;
  169. if (timer < num / 2f)
  170. {
  171. a = start_pos[count];
  172. }
  173. else if (timer >= num / 2f + this.m_Stop_Time)
  174. {
  175. a = end_pos[count];
  176. }
  177. keyValuePair.Value.localPosition = num4 * a + (1f - num4) * vector;
  178. }
  179. if (keyValuePair.Key.text == "\n")
  180. {
  181. string_count += this.m_Line_Count - string_count % this.m_Line_Count;
  182. }
  183. else
  184. {
  185. string_count++;
  186. }
  187. count++;
  188. }
  189. if (is_end)
  190. {
  191. break;
  192. }
  193. yield return null;
  194. }
  195. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  196. {
  197. if (this.m_End_Action != null)
  198. {
  199. this.m_End_Action();
  200. }
  201. FreeScene_UI.m_Now_UI = null;
  202. UnityEngine.Object.Destroy(base.gameObject);
  203. }
  204. else
  205. {
  206. yield return new WaitForSeconds(this.m_Wait_Time);
  207. base.StartCoroutine(this.Fade_Out());
  208. }
  209. yield break;
  210. yield break;
  211. }
  212. private IEnumerator Fade_Out()
  213. {
  214. float timer = 0f;
  215. Color text_col = Color.white;
  216. for (;;)
  217. {
  218. timer += Time.deltaTime;
  219. text_col.a = 1f - timer / this.m_Fade_Time;
  220. foreach (Text text in this.m_All_Text_Rect.Keys)
  221. {
  222. text.color = text_col;
  223. }
  224. if (timer >= this.m_Fade_Time)
  225. {
  226. break;
  227. }
  228. yield return null;
  229. }
  230. if (this.m_End_Action != null)
  231. {
  232. this.m_End_Action();
  233. }
  234. FreeScene_UI.m_Now_UI = null;
  235. UnityEngine.Object.Destroy(base.gameObject);
  236. yield break;
  237. yield break;
  238. }
  239. private const string m_FreeScene_UI_Path = "Prefab/FreeScene_UI";
  240. private const string m_Font_Path = "Font/FreeScene_UI_Font";
  241. private const string m_SE_Name = "SE015.ogg";
  242. [SerializeField]
  243. [Header("この文字数で改行")]
  244. private int m_Line_Count = 15;
  245. [SerializeField]
  246. [Header("2D用")]
  247. [Header("文字サイズ")]
  248. private int m_2D_Text_Size = 25;
  249. [SerializeField]
  250. [Header("外枠サイズ")]
  251. private float m_2D_Outline_Size = 2f;
  252. [SerializeField]
  253. [Header("VR用")]
  254. [Header("前方距離")]
  255. private float m_Forward_Length = 1f;
  256. [SerializeField]
  257. [Header("横位置")]
  258. private float m_Width_Length = 0.75f;
  259. [SerializeField]
  260. [Header("文字サイズ")]
  261. private int m_Text_Size = 15;
  262. [SerializeField]
  263. [Header("外枠サイズ")]
  264. private float m_Outline_Size = 1f;
  265. [SerializeField]
  266. [Header("アニメーション関連")]
  267. private float m_Anime_Time = 2f;
  268. [SerializeField]
  269. private float m_Anime_Lag = 0.25f;
  270. [SerializeField]
  271. private float m_Wait_Time = 2f;
  272. [SerializeField]
  273. private float m_Stop_Time = 1f;
  274. [SerializeField]
  275. private float m_Fade_Time = 0.5f;
  276. private string m_Use_String = string.Empty;
  277. private Dictionary<Text, RectTransform> m_All_Text_Rect;
  278. private Action m_End_Action;
  279. private static GameObject m_Now_UI;
  280. }