123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- public class FreeScene_UI : MonoBehaviour
- {
- public static void FreeScene_Start(string para, Action end_action = null)
- {
- if (FreeScene_UI.m_Now_UI)
- {
- UnityEngine.Object.Destroy(FreeScene_UI.m_Now_UI);
- }
- GameObject original = Resources.Load<GameObject>("Prefab/FreeScene_UI");
- FreeScene_UI.m_Now_UI = UnityEngine.Object.Instantiate<GameObject>(original);
- FreeScene_UI.m_Now_UI.GetComponent<FreeScene_UI>().Initialize(para, end_action);
- }
- private void Initialize(string para, Action end_action)
- {
- this.m_Use_String = para;
- this.m_End_Action = end_action;
- this.m_All_Text_Rect = new Dictionary<Text, RectTransform>();
- base.StartCoroutine(this.UI_Animation());
- }
- private void Set_Camera_Forward(RectTransform rect)
- {
- Vector3 position = GameMain.Instance.MainCamera.GetRealHeadTransform().position;
- Vector3 a = GameMain.Instance.MainCamera.GetRealHeadTransform().TransformDirection(Vector3.forward);
- rect.position = position + a * this.m_Forward_Length;
- Vector3 eulerAngles = GameMain.Instance.MainCamera.GetRealHeadTransform().eulerAngles;
- rect.eulerAngles = new Vector3(eulerAngles.x, eulerAngles.y, 0f);
- rect.localScale = Vector3.one;
- Vector2 vector = Vector2.one * 0.5f;
- rect.pivot = vector;
- vector = vector;
- rect.anchorMax = vector;
- rect.anchorMin = vector;
- base.GetComponent<CanvasScaler>().dynamicPixelsPerUnit = 5f;
- }
- private void Set_Text_Pos(ref List<Vector3> first_pos, ref List<Vector3> end_pos, RectTransform bace)
- {
- int num = 0;
- int max_count = 0;
- foreach (char c in this.m_Use_String)
- {
- int num2 = num / this.m_Line_Count;
- GameObject gameObject = new GameObject("Text", new Type[]
- {
- typeof(RectTransform),
- typeof(CanvasRenderer),
- typeof(Text),
- typeof(Outline)
- });
- RectTransform component = gameObject.GetComponent<RectTransform>();
- component.SetParent(base.transform);
- component.localEulerAngles = Vector3.zero;
- component.sizeDelta = Vector2.one * 100f;
- RectTransform rectTransform = component;
- Vector2 vector = Vector2.one * 0.5f;
- component.pivot = vector;
- vector = vector;
- component.anchorMax = vector;
- rectTransform.anchorMin = vector;
- Text component2 = gameObject.GetComponent<Text>();
- component2.font = Resources.Load<Font>("Font/FreeScene_UI_Font");
- component2.color = Color.white;
- component2.text = c.ToString();
- component2.alignment = TextAnchor.MiddleCenter;
- Color black = Color.black;
- black.a = 0.5f;
- gameObject.GetComponent<Outline>().effectColor = black;
- Vector3 localPosition;
- Vector3 item;
- if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
- {
- float x = bace.sizeDelta.x / 2f + component.sizeDelta.x / 2f + (float)(this.m_2D_Text_Size * (num % this.m_Line_Count));
- float y = (float)(-(float)num2 * this.m_2D_Text_Size);
- component.localPosition = new Vector3(x, y, 0f);
- component.localScale = Vector3.one;
- component2.fontSize = this.m_2D_Text_Size;
- gameObject.GetComponent<Outline>().effectDistance = Vector2.one * this.m_2D_Outline_Size;
- item = (localPosition = component.localPosition);
- 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)));
- }
- else
- {
- float x = this.m_Width_Length + (float)(this.m_Text_Size * (num % this.m_Line_Count)) * 0.01f;
- float y = (float)(-(float)num2 * this.m_Text_Size) * 0.01f;
- component.localScale = Vector3.one * 0.01f;
- component.localPosition = new Vector3(x, y, 0f);
- component2.fontSize = this.m_Text_Size;
- gameObject.GetComponent<Outline>().effectDistance = Vector2.one * this.m_Outline_Size;
- item = (localPosition = component.localPosition);
- item.x = -(this.m_Width_Length + (float)(this.m_Text_Size * (this.m_Line_Count - num % this.m_Line_Count)) * 0.01f);
- }
- first_pos.Add(localPosition);
- end_pos.Add(item);
- this.m_All_Text_Rect.Add(component2, component);
- if (c == '\n')
- {
- num += this.m_Line_Count - num % this.m_Line_Count;
- }
- else
- {
- num++;
- }
- if (num % this.m_Line_Count > max_count)
- {
- max_count = num % this.m_Line_Count;
- }
- }
- List<Vector3> source = new List<Vector3>(first_pos);
- List<Vector3> source2 = new List<Vector3>(end_pos);
- float center = (float)((this.m_Use_String.Length - 1) / max_count) * 0.5f;
- if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
- {
- first_pos = (from e in source
- select e += Vector3.up * center * (float)this.m_2D_Text_Size).ToList<Vector3>();
- source2 = (from e in source2
- select e += Vector3.up * center * (float)this.m_2D_Text_Size).ToList<Vector3>();
- end_pos = (from e in source2
- select e += Vector3.right * (float)(this.m_Line_Count - max_count) * (float)this.m_2D_Text_Size).ToList<Vector3>();
- }
- else
- {
- first_pos = (from e in source
- select e += Vector3.up * center * (float)this.m_Text_Size * 0.01f).ToList<Vector3>();
- source2 = (from e in source2
- select e += Vector3.up * center * (float)this.m_Text_Size * 0.01f).ToList<Vector3>();
- end_pos = (from e in source2
- select e += Vector3.right * (float)(this.m_Line_Count - max_count) * (float)this.m_Text_Size * 0.01f).ToList<Vector3>();
- }
- }
- private IEnumerator UI_Animation()
- {
- RectTransform my_rect = base.GetComponent<RectTransform>();
- if (GameMain.Instance.VRDeviceTypeID != GameMain.VRDeviceType.NON)
- {
- this.Set_Camera_Forward(my_rect);
- base.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
- base.GetComponent<Canvas>().sortingOrder = 4;
- }
- List<Vector3> start_pos = new List<Vector3>();
- List<Vector3> end_pos = new List<Vector3>();
- this.Set_Text_Pos(ref start_pos, ref end_pos, my_rect);
- float timer = 0f;
- for (;;)
- {
- timer += Time.deltaTime;
- int count = 0;
- int string_count = 0;
- bool is_end = true;
- foreach (KeyValuePair<Text, RectTransform> keyValuePair in this.m_All_Text_Rect)
- {
- float num = this.m_Anime_Time + this.m_Anime_Lag * (float)(string_count % this.m_Line_Count);
- float num2 = timer;
- if (timer >= num / 2f + this.m_Stop_Time)
- {
- num2 -= this.m_Stop_Time;
- }
- if (num2 <= num)
- {
- is_end = false;
- float num3 = 180f * (num2 / num);
- float num4 = 1f - Mathf.Abs(Mathf.Sin(num3 * 0.0174532924f));
- Vector3 vector = 0.5f * start_pos[count] + 0.5f * end_pos[count];
- Vector3 a = vector;
- if (timer < num / 2f)
- {
- a = start_pos[count];
- }
- else if (timer >= num / 2f + this.m_Stop_Time)
- {
- a = end_pos[count];
- }
- keyValuePair.Value.localPosition = num4 * a + (1f - num4) * vector;
- }
- if (keyValuePair.Key.text == "\n")
- {
- string_count += this.m_Line_Count - string_count % this.m_Line_Count;
- }
- else
- {
- string_count++;
- }
- count++;
- }
- if (is_end)
- {
- break;
- }
- yield return null;
- }
- if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
- {
- if (this.m_End_Action != null)
- {
- this.m_End_Action();
- }
- FreeScene_UI.m_Now_UI = null;
- UnityEngine.Object.Destroy(base.gameObject);
- }
- else
- {
- yield return new WaitForSeconds(this.m_Wait_Time);
- base.StartCoroutine(this.Fade_Out());
- }
- yield break;
- yield break;
- }
- private IEnumerator Fade_Out()
- {
- float timer = 0f;
- Color text_col = Color.white;
- for (;;)
- {
- timer += Time.deltaTime;
- text_col.a = 1f - timer / this.m_Fade_Time;
- foreach (Text text in this.m_All_Text_Rect.Keys)
- {
- text.color = text_col;
- }
- if (timer >= this.m_Fade_Time)
- {
- break;
- }
- yield return null;
- }
- if (this.m_End_Action != null)
- {
- this.m_End_Action();
- }
- FreeScene_UI.m_Now_UI = null;
- UnityEngine.Object.Destroy(base.gameObject);
- yield break;
- yield break;
- }
- private const string m_FreeScene_UI_Path = "Prefab/FreeScene_UI";
- private const string m_Font_Path = "Font/FreeScene_UI_Font";
- private const string m_SE_Name = "SE015.ogg";
- [SerializeField]
- [Header("この文字数で改行")]
- private int m_Line_Count = 15;
- [SerializeField]
- [Header("2D用")]
- [Header("文字サイズ")]
- private int m_2D_Text_Size = 25;
- [SerializeField]
- [Header("外枠サイズ")]
- private float m_2D_Outline_Size = 2f;
- [SerializeField]
- [Header("VR用")]
- [Header("前方距離")]
- private float m_Forward_Length = 1f;
- [SerializeField]
- [Header("横位置")]
- private float m_Width_Length = 0.75f;
- [SerializeField]
- [Header("文字サイズ")]
- private int m_Text_Size = 15;
- [SerializeField]
- [Header("外枠サイズ")]
- private float m_Outline_Size = 1f;
- [SerializeField]
- [Header("アニメーション関連")]
- private float m_Anime_Time = 2f;
- [SerializeField]
- private float m_Anime_Lag = 0.25f;
- [SerializeField]
- private float m_Wait_Time = 2f;
- [SerializeField]
- private float m_Stop_Time = 1f;
- [SerializeField]
- private float m_Fade_Time = 0.5f;
- private string m_Use_String = string.Empty;
- private Dictionary<Text, RectTransform> m_All_Text_Rect;
- private Action m_End_Action;
- private static GameObject m_Now_UI;
- }
|