123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- 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<Text>(), 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<Image>();
- 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<Sprite>(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<UICanvasFade>();
- 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<EventTrigger>();
- 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<T>(string path, UnityAction<ResourceRequest> callback) where T : UnityEngine.Object
- {
- ResourceRequest res = Resources.LoadAsync<T>(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;
- }
- }
|