VRChangeBackGroundMenu.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.UI;
  7. public class VRChangeBackGroundMenu : MonoBehaviour, InterfaceVRCanvas
  8. {
  9. private void Awake()
  10. {
  11. this.m_StageButtonDataArray = new VRChangeBackGroundMenu.StageButtonData[this.m_ButtonArray.Length];
  12. for (int i = 0; i < this.m_ButtonArray.Length; i++)
  13. {
  14. this.m_StageButtonDataArray[i] = new VRChangeBackGroundMenu.StageButtonData(this.m_ButtonArray[i], this.m_ButtonArray[i].GetComponentInChildren<Text>(), false);
  15. }
  16. }
  17. private void Start()
  18. {
  19. this.OnUpdateCanvas();
  20. }
  21. private void Update()
  22. {
  23. if (this.m_StageButtonDataArray == null)
  24. {
  25. return;
  26. }
  27. for (int i = 0; i < this.m_StageButtonDataArray.Length; i++)
  28. {
  29. VRChangeBackGroundMenu.StageButtonData stageButtonData = this.m_StageButtonDataArray[i];
  30. Vector3 vector = stageButtonData.text.rectTransform.anchoredPosition3D;
  31. Color color = stageButtonData.text.color;
  32. if (stageButtonData.isPointerStay)
  33. {
  34. vector = Vector3.Lerp(vector, Vector3.down * 50f, 0.2f);
  35. color.a += (1f - color.a) * 0.2f;
  36. }
  37. else
  38. {
  39. vector = Vector3.Lerp(vector, Vector3.up * 50f, 0.2f);
  40. color.a += (0f - color.a) * 0.2f;
  41. }
  42. stageButtonData.text.rectTransform.anchoredPosition3D = vector;
  43. stageButtonData.text.color = color;
  44. }
  45. }
  46. public void OnUpdateCanvas()
  47. {
  48. SceneVRCommunication instance = SceneVRCommunication.Instance;
  49. if (instance == null)
  50. {
  51. return;
  52. }
  53. SceneVRCommunication.VR_TIME nowTime = instance.GetNowTime();
  54. this.ChangeButtonIcon(nowTime);
  55. }
  56. private void ChangeButtonIcon(SceneVRCommunication.VR_TIME nowTime)
  57. {
  58. if (this.m_StageButtonDataArray == null)
  59. {
  60. return;
  61. }
  62. if (!base.gameObject.activeInHierarchy)
  63. {
  64. return;
  65. }
  66. for (int i = 0; i < this.m_StageButtonDataArray.Length; i++)
  67. {
  68. VRChangeBackGroundMenu.StageButtonData buttonData = this.m_StageButtonDataArray[i];
  69. Button button = buttonData.button;
  70. Image image = button.GetComponent<Image>();
  71. int number = i + 1;
  72. string text = "vr_stage_select_" + number.ToString();
  73. if (nowTime == SceneVRCommunication.VR_TIME.NIGHT)
  74. {
  75. text += "_night";
  76. }
  77. string path = this.m_uGUIAtlasPath + text;
  78. base.StartCoroutine(this.Coroutine_Load<Sprite>(path, delegate(ResourceRequest req)
  79. {
  80. image.sprite = (req.asset as Sprite);
  81. }));
  82. button.onClick.RemoveAllListeners();
  83. button.onClick.AddListener(delegate()
  84. {
  85. buttonData.isPointerStay = false;
  86. VRExternalFileLoader.Event_CloseMovie();
  87. UICanvasFade component2 = this.GetComponent<UICanvasFade>();
  88. component2.FadeOut(component2.fadeTime, component2.isTimeScaling, delegate()
  89. {
  90. VRCanvasManager.Instance.OpenBeforeVRCanvas();
  91. });
  92. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript("HAN_main_000" + number.ToString() + ".ks", string.Empty);
  93. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  94. });
  95. EventTrigger component = button.GetComponent<EventTrigger>();
  96. component.triggers.Clear();
  97. EventTrigger.Entry entry = new EventTrigger.Entry();
  98. entry.eventID = EventTriggerType.PointerEnter;
  99. entry.callback.AddListener(delegate(BaseEventData data)
  100. {
  101. buttonData.isPointerStay = true;
  102. });
  103. component.triggers.Add(entry);
  104. entry = new EventTrigger.Entry();
  105. entry.eventID = EventTriggerType.PointerExit;
  106. entry.callback.AddListener(delegate(BaseEventData data)
  107. {
  108. buttonData.isPointerStay = false;
  109. });
  110. component.triggers.Add(entry);
  111. }
  112. }
  113. private IEnumerator Coroutine_Load<T>(string path, UnityAction<ResourceRequest> callback) where T : UnityEngine.Object
  114. {
  115. ResourceRequest res = Resources.LoadAsync<T>(path);
  116. while (!res.isDone)
  117. {
  118. yield return null;
  119. }
  120. callback(res);
  121. yield break;
  122. }
  123. private void OnEnable()
  124. {
  125. this.OnUpdateCanvas();
  126. }
  127. [SerializeField]
  128. [Tooltip("移動先のボタン")]
  129. private Button[] m_ButtonArray;
  130. private VRChangeBackGroundMenu.StageButtonData[] m_StageButtonDataArray;
  131. private string m_uGUIAtlasPath = "SceneVRCommunication\\Tablet\\Sprite\\";
  132. private class StageButtonData
  133. {
  134. public StageButtonData(Button button_, Text text_, bool isPointerStay_)
  135. {
  136. this.button = button_;
  137. this.text = text_;
  138. this.isPointerStay = isPointerStay_;
  139. }
  140. public Button button;
  141. public Text text;
  142. public bool isPointerStay;
  143. }
  144. }