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("Prefab/SelectMessage_UI"); SelectMessage_UI.m_Now_MessageUI = UnityEngine.Object.Instantiate(original); SelectMessage_UI.m_Now_MessageUI.GetComponent().Initialize(message); } private void Initialize(string messsage) { GameObject gameObject = base.GetComponent().Find("Image").gameObject; GameObject gameObject2 = base.GetComponent().Find("Text").gameObject; this.m_MyText = gameObject2.GetComponent(); this.m_MyText.text = messsage; this.m_MyImage = gameObject.GetComponent(); if (this.Is_ImageDisplay()) { this.m_Slide_Rect = gameObject.GetComponent(); 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("SceneVRCommunication/Tablet/Sprite/LOOK_alpha"); } else { this.m_Slide_Rect = gameObject2.GetComponent(); 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/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()); 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().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().renderMode = RenderMode.WorldSpace; base.GetComponent().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().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.017453292f * 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; }