using System; using System.Collections; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; public class VRChangeBackGroundMenu : MonoBehaviour, InterfaceVRCanvas { private void Awake() { this.m_StageButtonDataArray = new VRChangeBackGroundMenu.StageButtonData[this.m_ButtonArray.Length]; for (int i = 0; i < this.m_ButtonArray.Length; i++) { this.m_StageButtonDataArray[i] = new VRChangeBackGroundMenu.StageButtonData(this.m_ButtonArray[i], this.m_ButtonArray[i].GetComponentInChildren(), false); } } private void Start() { this.OnUpdateCanvas(); } private void Update() { if (this.m_StageButtonDataArray == null) { return; } for (int i = 0; i < this.m_StageButtonDataArray.Length; i++) { VRChangeBackGroundMenu.StageButtonData stageButtonData = this.m_StageButtonDataArray[i]; Vector3 vector = stageButtonData.text.rectTransform.anchoredPosition3D; Color color = stageButtonData.text.color; if (stageButtonData.isPointerStay) { vector = Vector3.Lerp(vector, Vector3.down * 50f, 0.2f); color.a += (1f - color.a) * 0.2f; } else { vector = Vector3.Lerp(vector, Vector3.up * 50f, 0.2f); color.a += (0f - color.a) * 0.2f; } stageButtonData.text.rectTransform.anchoredPosition3D = vector; stageButtonData.text.color = color; } } public void OnUpdateCanvas() { SceneVRCommunication instance = SceneVRCommunication.Instance; if (instance == null) { return; } SceneVRCommunication.VR_TIME nowTime = instance.GetNowTime(); this.ChangeButtonIcon(nowTime); } private void ChangeButtonIcon(SceneVRCommunication.VR_TIME nowTime) { if (this.m_StageButtonDataArray == null) { return; } if (!base.gameObject.activeInHierarchy) { return; } for (int i = 0; i < this.m_StageButtonDataArray.Length; i++) { VRChangeBackGroundMenu.StageButtonData buttonData = this.m_StageButtonDataArray[i]; Button button = buttonData.button; Image image = button.GetComponent(); int number = i + 1; string text = "vr_stage_select_" + number.ToString(); if (nowTime == SceneVRCommunication.VR_TIME.NIGHT) { text += "_night"; } string path = this.m_uGUIAtlasPath + text; base.StartCoroutine(this.Coroutine_Load(path, delegate(ResourceRequest req) { image.sprite = (req.asset as Sprite); })); button.onClick.RemoveAllListeners(); button.onClick.AddListener(delegate() { buttonData.isPointerStay = false; VRExternalFileLoader.Event_CloseMovie(); UICanvasFade component2 = this.GetComponent(); component2.FadeOut(component2.fadeTime, component2.isTimeScaling, delegate() { VRCanvasManager.Instance.OpenBeforeVRCanvas(); }); GameMain.Instance.ScriptMgr.LoadAdvScenarioScript("HAN_main_000" + number.ToString() + ".ks", string.Empty); GameMain.Instance.ScriptMgr.adv_kag.Exec(); }); EventTrigger component = button.GetComponent(); component.triggers.Clear(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerEnter; entry.callback.AddListener(delegate(BaseEventData data) { buttonData.isPointerStay = true; }); component.triggers.Add(entry); entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerExit; entry.callback.AddListener(delegate(BaseEventData data) { buttonData.isPointerStay = false; }); component.triggers.Add(entry); } } private IEnumerator Coroutine_Load(string path, UnityAction callback) where T : UnityEngine.Object { ResourceRequest res = Resources.LoadAsync(path); while (!res.isDone) { yield return null; } callback(res); yield break; } private void OnEnable() { this.OnUpdateCanvas(); } [SerializeField] [Tooltip("移動先のボタン")] private Button[] m_ButtonArray; private VRChangeBackGroundMenu.StageButtonData[] m_StageButtonDataArray; private string m_uGUIAtlasPath = "SceneVRCommunication\\Tablet\\Sprite\\"; private class StageButtonData { public StageButtonData(Button button_, Text text_, bool isPointerStay_) { this.button = button_; this.text = text_; this.isPointerStay = isPointerStay_; } public Button button; public Text text; public bool isPointerStay; } }