123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.UI;
- public class SelectMessage_UI : MonoBehaviour
- {
- public static void Message_Start(string message)
- {
- if (SelectMessage_UI.m_Now_MessageUI)
- {
- UnityEngine.Object.Destroy(SelectMessage_UI.m_Now_MessageUI);
- }
- GameObject original = Resources.Load<GameObject>("Prefab/SelectMessage_UI");
- SelectMessage_UI.m_Now_MessageUI = UnityEngine.Object.Instantiate<GameObject>(original);
- SelectMessage_UI.m_Now_MessageUI.GetComponent<SelectMessage_UI>().Initialize(message);
- }
- private void Initialize(string messsage)
- {
- GameObject gameObject = base.GetComponent<RectTransform>().Find("Image").gameObject;
- GameObject gameObject2 = base.GetComponent<RectTransform>().Find("Text").gameObject;
- this.m_MyText = gameObject2.GetComponent<Text>();
- this.m_MyText.text = messsage;
- this.m_MyImage = gameObject.GetComponent<Image>();
- if (this.Is_ImageDisplay())
- {
- this.m_Slide_Rect = gameObject.GetComponent<RectTransform>();
- this.m_Slide_Rect.sizeDelta = this.m_Image_Size;
- this.m_Slide_Rect.localPosition += Vector3.up * this.m_Image_Up + Vector3.right * this.m_Image_Size.x / 2f;
- this.m_MyText.enabled = false;
- this.m_MyImage.sprite = Resources.Load<Sprite>("SceneVRCommunication/Tablet/Sprite/LOOK_alpha");
- }
- else
- {
- this.m_Slide_Rect = gameObject2.GetComponent<RectTransform>();
- this.m_Slide_Rect.sizeDelta = Vector2.right * (float)this.m_Text_Size * (float)messsage.Length + Vector2.up * (float)this.m_Text_Size * 2f;
- this.m_MyImage.enabled = false;
- this.m_MyText.font = Resources.Load<Font>("Font/mplus-TESTFLIGHT-059/mplus-1mn-regular");
- this.m_MyText.fontSize = this.m_Text_Size;
- if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
- {
- this.m_MyText.fontSize = this.m_Text_Size;
- this.m_Slide_Rect.localPosition += Vector3.up * this.m_Text_Up + Vector3.right * (float)this.m_Text_Size * ((float)messsage.Length / 2f);
- }
- else
- {
- this.Set_Camera_Forward(base.GetComponent<RectTransform>());
- this.m_MyText.fontSize = this.m_Text_VRSize;
- RectTransform slide_Rect = this.m_Slide_Rect;
- Vector2 vector = Vector2.one * 0.5f;
- this.m_Slide_Rect.anchorMax = vector;
- vector = vector;
- this.m_Slide_Rect.anchorMin = vector;
- slide_Rect.pivot = vector;
- this.m_Slide_Rect.localPosition = Vector3.right * this.m_Right_Length;
- this.m_Slide_Rect.localEulerAngles = Vector3.zero;
- this.m_Slide_Rect.localScale = Vector3.one * 0.01f;
- gameObject2.GetComponent<Outline>().effectDistance = Vector2.one * this.m_OutLine_size;
- }
- }
- base.StartCoroutine(this.FrameIn());
- }
- private bool Is_ImageDisplay()
- {
- bool result = false;
- if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON && (this.m_MyText.text == string.Empty || this.m_MyText.text == null))
- {
- result = true;
- }
- return result;
- }
- private void Set_Camera_Forward(RectTransform rect)
- {
- base.GetComponent<Canvas>().renderMode = RenderMode.WorldSpace;
- base.GetComponent<Canvas>().sortingOrder = 4;
- Vector3 position = GameMain.Instance.MainCamera.GetRealHeadTransform().position;
- Vector3 a = GameMain.Instance.MainCamera.GetRealHeadTransform().TransformDirection(Vector3.forward);
- Vector3 vector = GameMain.Instance.MainCamera.GetRealHeadTransform().TransformDirection(Vector3.down);
- vector.x = 0f;
- rect.position = position + a * this.m_Forward_Length + vector.normalized * this.m_Down_Length;
- Vector3 eulerAngles = GameMain.Instance.MainCamera.GetRealHeadTransform().eulerAngles;
- rect.eulerAngles = new Vector3(eulerAngles.x, eulerAngles.y, 0f);
- rect.localScale = Vector3.one;
- rect.sizeDelta = Vector2.one * 100f;
- Vector2 vector2 = Vector2.one * 0.5f;
- rect.pivot = vector2;
- vector2 = vector2;
- rect.anchorMax = vector2;
- rect.anchorMin = vector2;
- base.GetComponent<CanvasScaler>().dynamicPixelsPerUnit = 5f;
- }
- private IEnumerator FrameIn()
- {
- float timer = 0f;
- Vector3 start_pos = this.m_Slide_Rect.localPosition;
- Vector3 end_pos = this.m_Slide_Rect.localPosition;
- if (this.m_MyImage.enabled)
- {
- end_pos.x = start_pos.x - (this.m_Image_Size.x + this.m_Image_Margin);
- }
- else if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
- {
- end_pos.x = start_pos.x - ((float)(this.m_Text_Size * this.m_MyText.text.Length) + this.m_Text_Margin);
- }
- else
- {
- end_pos.x = 0f;
- }
- for (;;)
- {
- timer += Time.deltaTime;
- float angle = timer / this.m_Anime_Time * 90f;
- float rate = Mathf.Sin(0.0174532924f * angle);
- this.m_Slide_Rect.localPosition = (1f - rate) * start_pos + rate * end_pos;
- if (timer >= this.m_Anime_Time)
- {
- break;
- }
- yield return null;
- }
- yield return new WaitForSeconds(this.m_Display_Time);
- base.StartCoroutine(this.FadeOut());
- yield break;
- yield break;
- }
- private IEnumerator FadeOut()
- {
- float timer = 0f;
- Color text_color = this.m_MyText.color;
- Color image_color = this.m_MyImage.color;
- for (;;)
- {
- timer += Time.deltaTime;
- image_color.a = (text_color.a = 1f - timer / this.m_Fade_Time);
- if (this.m_MyImage.enabled)
- {
- this.m_MyImage.color = image_color;
- }
- else
- {
- this.m_MyText.color = text_color;
- }
- if (timer >= this.m_Fade_Time)
- {
- break;
- }
- yield return null;
- }
- UnityEngine.Object.Destroy(base.gameObject);
- yield break;
- yield break;
- }
- private const string m_MessageUI_ObjPath = "Prefab/SelectMessage_UI";
- private const string m_Font_Path = "Font/mplus-TESTFLIGHT-059/mplus-1mn-regular";
- private const string m_Image_Path = "SceneVRCommunication/Tablet/Sprite/LOOK_alpha";
- [SerializeField]
- private float m_Anime_Time = 1f;
- [SerializeField]
- private float m_Display_Time = 3f;
- [SerializeField]
- private float m_Fade_Time = 0.5f;
- [SerializeField]
- private int m_Text_Size = 25;
- [SerializeField]
- private Vector2 m_Image_Size = new Vector2(200f, 112.5f);
- [SerializeField]
- [Header("画像位置をどのくらい上に補正するか")]
- private float m_Image_Up = 70f;
- [SerializeField]
- private float m_Image_Margin = 16.5f;
- [SerializeField]
- [Header("文字位置をどのくらい上に補正するか")]
- private float m_Text_Up = 30f;
- [SerializeField]
- private float m_Text_Margin = 25f;
- [SerializeField]
- [Header("VR時用変数")]
- private float m_Right_Length = 3f;
- [SerializeField]
- private float m_Down_Length = 0.25f;
- [SerializeField]
- private float m_Forward_Length = 0.5f;
- [SerializeField]
- private int m_Text_VRSize = 5;
- [SerializeField]
- private float m_OutLine_size = 0.25f;
- private Text m_MyText;
- private Image m_MyImage;
- private RectTransform m_Slide_Rect;
- private static GameObject m_Now_MessageUI;
- }
|