Trophy_UI.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class Trophy_UI : MonoBehaviour
  7. {
  8. public static void Trophy_Start(string para)
  9. {
  10. if (Trophy_UI.m_Trophy_Text == null)
  11. {
  12. Trophy_UI.m_Trophy_Text = new List<string>();
  13. }
  14. if (!Trophy_UI.m_Now_DisplayUI)
  15. {
  16. GameObject now_DisplayUI = Resources.Load<GameObject>("Prefab/TrophyGet_UI");
  17. Trophy_UI.m_Now_DisplayUI = now_DisplayUI;
  18. Trophy_UI.m_Now_DisplayUI = UnityEngine.Object.Instantiate<GameObject>(Trophy_UI.m_Now_DisplayUI);
  19. Trophy_UI.m_Now_DisplayUI.GetComponent<Trophy_UI>().Initialize(para);
  20. }
  21. Trophy_UI.m_Trophy_Text.Add(para);
  22. }
  23. private void Initialize(string val)
  24. {
  25. this.m_All_Text_Rect = new Dictionary<Text, RectTransform>();
  26. this.m_Use_String = val;
  27. this.m_All_LineCount = this.m_Use_String.Length / this.m_Line_Count;
  28. base.StartCoroutine(this.UI_Animation());
  29. }
  30. private void Set_Camera_Forward(RectTransform rect)
  31. {
  32. Vector3 position = GameMain.Instance.MainCamera.GetRealHeadTransform().position;
  33. Vector3 a = GameMain.Instance.MainCamera.GetRealHeadTransform().TransformDirection(Vector3.forward);
  34. Vector3 vector = GameMain.Instance.MainCamera.GetRealHeadTransform().TransformDirection(Vector3.down);
  35. vector.x = 0f;
  36. rect.position = position + a * this.m_Forward_Length + vector.normalized * this.m_Down_Length;
  37. Vector3 eulerAngles = GameMain.Instance.MainCamera.GetRealHeadTransform().eulerAngles;
  38. rect.eulerAngles = new Vector3(eulerAngles.x, eulerAngles.y, 0f);
  39. rect.localScale = Vector3.one;
  40. Vector2 vector2 = Vector2.one * 0.5f;
  41. rect.pivot = vector2;
  42. vector2 = vector2;
  43. rect.anchorMax = vector2;
  44. rect.anchorMin = vector2;
  45. rect.sizeDelta = Vector2.one * 100f;
  46. base.GetComponent<CanvasScaler>().dynamicPixelsPerUnit = 5f;
  47. }
  48. private void Set_Text_Pos(ref List<Vector3> first_pos, ref List<Vector3> end_pos, RectTransform bace)
  49. {
  50. int num = 0;
  51. foreach (char c in this.m_Use_String)
  52. {
  53. int num2 = num / this.m_Line_Count;
  54. Vector3 zero = Vector3.zero;
  55. GameObject gameObject = new GameObject("Text", new Type[]
  56. {
  57. typeof(RectTransform),
  58. typeof(CanvasRenderer),
  59. typeof(Text)
  60. });
  61. gameObject.layer = base.gameObject.layer;
  62. RectTransform component = gameObject.GetComponent<RectTransform>();
  63. component.SetParent(base.transform);
  64. Text component2 = gameObject.GetComponent<Text>();
  65. component2.text = c.ToString();
  66. component2.font = Resources.Load<Font>("Font/Day_Display_UI_Font");
  67. component2.color = this.m_Text_Col;
  68. component2.alignment = TextAnchor.MiddleCenter;
  69. component.sizeDelta = Vector2.one * 100f;
  70. component.localEulerAngles = Vector3.zero;
  71. gameObject.AddComponent<Outline>();
  72. Color outline_Col = this.m_Outline_Col;
  73. outline_Col.a = this.m_Outline_Alpha;
  74. gameObject.GetComponent<Outline>().effectColor = outline_Col;
  75. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  76. {
  77. gameObject.GetComponent<Outline>().effectDistance = Vector2.one * this.m_2D_Outline_Size;
  78. component2.fontSize = this.m_2D_Text_Size;
  79. RectTransform rectTransform = component;
  80. Vector2 vector = Vector2.up;
  81. component.anchorMax = vector;
  82. rectTransform.anchorMin = vector;
  83. component.pivot = Vector2.zero;
  84. component.localScale = Vector3.one;
  85. float x = (float)(num % this.m_Line_Count) * this.m_2D_Delta_Size.y - bace.localPosition.x;
  86. float y = bace.localPosition.y + (float)(num % this.m_Line_Count + this.m_All_LineCount - num2) * this.m_2D_Delta_Size.y;
  87. component.localPosition = new Vector3(x, y, 0f);
  88. zero = new Vector3(x, -this.m_2D_Down_Length + bace.localPosition.y, 0f);
  89. zero.y -= (float)num2 * this.m_2D_Delta_Size.y;
  90. }
  91. else
  92. {
  93. gameObject.GetComponent<Outline>().effectDistance = Vector2.one * this.m_Outline_Size;
  94. component.localScale = Vector3.one * 0.01f;
  95. component2.fontSize = this.m_Text_Size;
  96. component2.alignment = TextAnchor.MiddleCenter;
  97. RectTransform rectTransform2 = component;
  98. Vector2 vector = Vector2.one * 0.5f;
  99. component.pivot = vector;
  100. vector = vector;
  101. component.anchorMax = vector;
  102. rectTransform2.anchorMin = vector;
  103. float x = (float)(num % this.m_Line_Count) * this.m_Delta_Size.x * 0.01f + this.m_Width_Length;
  104. float y = (float)(-(float)num2) * this.m_Delta_Size.y * 0.01f;
  105. component.localPosition = new Vector3(x, y, 0f);
  106. zero = new Vector3(-(this.m_Width_Length + (float)Mathf.Abs(this.m_Line_Count - (num % this.m_Line_Count + 1)) * this.m_Delta_Size.x * 0.01f), y, 0f);
  107. }
  108. first_pos.Add(component.localPosition);
  109. end_pos.Add(zero);
  110. this.m_All_Text_Rect.Add(component2, component);
  111. if (c == '\n')
  112. {
  113. num += this.m_Line_Count - num % this.m_Line_Count;
  114. }
  115. else
  116. {
  117. num++;
  118. }
  119. }
  120. }
  121. private void Set_Next_UI()
  122. {
  123. Trophy_UI.m_Trophy_Text.RemoveAt(0);
  124. if (Trophy_UI.m_Trophy_Text.Count != 0)
  125. {
  126. GameObject gameObject = Resources.Load<GameObject>("Prefab/TrophyGet_UI");
  127. gameObject = UnityEngine.Object.Instantiate<GameObject>(gameObject);
  128. gameObject.GetComponent<Trophy_UI>().Initialize(Trophy_UI.m_Trophy_Text[0]);
  129. Trophy_UI.m_Now_DisplayUI = gameObject;
  130. }
  131. else
  132. {
  133. Trophy_UI.m_Now_DisplayUI = null;
  134. }
  135. UnityEngine.Object.Destroy(base.gameObject);
  136. }
  137. private IEnumerator UI_Animation()
  138. {
  139. RectTransform my_rect = null;
  140. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  141. {
  142. yield return null;
  143. my_rect = base.GetComponent<RectTransform>();
  144. }
  145. else
  146. {
  147. my_rect = base.GetComponent<RectTransform>();
  148. this.Set_Camera_Forward(my_rect);
  149. base.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
  150. base.GetComponent<Canvas>().sortingOrder = 4;
  151. }
  152. List<Vector3> start_pos = new List<Vector3>();
  153. List<Vector3> end_pos = new List<Vector3>();
  154. this.Set_Text_Pos(ref start_pos, ref end_pos, my_rect);
  155. float timer = 0f;
  156. GameMain.Instance.SoundMgr.PlaySe("SE015.ogg", false);
  157. for (;;)
  158. {
  159. timer += Time.deltaTime;
  160. int count = 0;
  161. int text_no = 0;
  162. float all_anime_time = 0f;
  163. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  164. {
  165. all_anime_time = this.m_Anime_Bace + this.m_Anime_Lag * (float)(this.m_All_Text_Rect.Count - 1);
  166. }
  167. else
  168. {
  169. all_anime_time = this.m_VR_AnimeTime;
  170. }
  171. foreach (KeyValuePair<Text, RectTransform> keyValuePair in this.m_All_Text_Rect)
  172. {
  173. int num = count / this.m_Line_Count;
  174. float num2;
  175. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  176. {
  177. num2 = this.m_Anime_Bace + (float)(count % this.m_Line_Count + this.m_All_LineCount - num) * this.m_Anime_Lag;
  178. }
  179. else
  180. {
  181. num2 = this.m_VR_AnimeTime;
  182. }
  183. if (timer <= num2)
  184. {
  185. float num3 = 90f * (timer / num2);
  186. float num4 = Mathf.Sin(0.0174532924f * num3);
  187. keyValuePair.Value.localPosition = start_pos[text_no] * (1f - num4) + end_pos[text_no] * num4;
  188. }
  189. if (keyValuePair.Key.text == "\n")
  190. {
  191. count += this.m_Line_Count - count % this.m_Line_Count;
  192. }
  193. else
  194. {
  195. count++;
  196. }
  197. text_no++;
  198. }
  199. if (timer >= all_anime_time)
  200. {
  201. break;
  202. }
  203. yield return null;
  204. }
  205. yield return new WaitForSeconds(this.m_Wait_Time);
  206. base.StartCoroutine(this.Fade_Out());
  207. yield break;
  208. yield break;
  209. }
  210. private IEnumerator Fade_Out()
  211. {
  212. Color set_color = this.m_Text_Col;
  213. float timer = 0f;
  214. for (;;)
  215. {
  216. timer += Time.deltaTime;
  217. set_color.a = 1f - timer / this.m_Fade_Time;
  218. foreach (Text text in this.m_All_Text_Rect.Keys)
  219. {
  220. text.color = set_color;
  221. }
  222. if (timer >= this.m_Fade_Time)
  223. {
  224. break;
  225. }
  226. yield return null;
  227. }
  228. yield return new WaitForSeconds(this.m_Next_Time);
  229. this.Set_Next_UI();
  230. yield break;
  231. yield break;
  232. }
  233. private const string m_TrophyGet_UI_Path = "Prefab/TrophyGet_UI";
  234. private const string m_Font_Path = "Font/Day_Display_UI_Font";
  235. private const string m_SE_Name = "SE015.ogg";
  236. private static GameObject m_Now_DisplayUI;
  237. private static List<string> m_Trophy_Text;
  238. [SerializeField]
  239. [Header("この文字数で改行")]
  240. private int m_Line_Count = 15;
  241. [SerializeField]
  242. private Color m_Text_Col = Color.white;
  243. [SerializeField]
  244. [Header("外枠色")]
  245. private Color m_Outline_Col = Color.black;
  246. [SerializeField]
  247. [Header("外枠透明度")]
  248. [Range(0f, 1f)]
  249. private float m_Outline_Alpha = 0.5f;
  250. [SerializeField]
  251. [Header("2D用")]
  252. [Header("文字サイズ")]
  253. private int m_2D_Text_Size = 25;
  254. [SerializeField]
  255. [Header("文字設置間隔(X:横、Y:縦)")]
  256. private Vector2 m_2D_Delta_Size = new Vector2(25f, 25f);
  257. [SerializeField]
  258. [Header("どの位置まで下げるか")]
  259. private float m_2D_Down_Length = 75f;
  260. [SerializeField]
  261. [Header("外枠サイズ")]
  262. private float m_2D_Outline_Size = 2f;
  263. [SerializeField]
  264. [Header("VR用")]
  265. [Header("前方距離")]
  266. private float m_Forward_Length = 1f;
  267. [SerializeField]
  268. [Header("横距離")]
  269. private float m_Width_Length = 0.75f;
  270. [SerializeField]
  271. [Header("下位置")]
  272. private float m_Down_Length = 0.35f;
  273. [SerializeField]
  274. [Header("文字設置間隔(X:横、Y:縦)")]
  275. private Vector2 m_Delta_Size = new Vector2(15f, 15f);
  276. [SerializeField]
  277. [Header("文字サイズ")]
  278. private int m_Text_Size = 15;
  279. [SerializeField]
  280. [Header("外枠サイズ")]
  281. private float m_Outline_Size = 1f;
  282. [SerializeField]
  283. [Header("アニメーション関連(全般)")]
  284. private float m_Wait_Time = 2f;
  285. [SerializeField]
  286. private float m_Fade_Time = 0.5f;
  287. [SerializeField]
  288. [Header("アニメーション関連(2D)")]
  289. private float m_Anime_Bace = 1f;
  290. [SerializeField]
  291. private float m_Anime_Lag = 0.1f;
  292. [SerializeField]
  293. [Header("アニメーション関連(VR)")]
  294. private float m_VR_AnimeTime = 7f;
  295. [SerializeField]
  296. [Header("連続して呼ばれた場合次のトロフィー用UIを出すまでの待機時間")]
  297. private float m_Next_Time = 0.5f;
  298. private string m_Use_String = string.Empty;
  299. private int m_All_LineCount;
  300. private Dictionary<Text, RectTransform> m_All_Text_Rect;
  301. private GameObject m_Text_Plate;
  302. }