123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.UI;
- public class VRSelectorMenu : MonoBehaviour
- {
- public static VRSelectorMenu CreateSelector()
- {
- if (VRSelectorMenu.m_Instance == null)
- {
- VRSelectorMenu.m_Instance = UnityEngine.Object.FindObjectOfType<VRSelectorMenu>();
- }
- return VRSelectorMenu.m_Instance;
- }
- private void Start()
- {
- if (VRSelectorMenu.m_Instance != null)
- {
- }
- VRSelectorMenu.m_Instance = this;
- base.gameObject.SetActive(false);
- }
- public void Open()
- {
- for (int i = 0; i < this.m_ParentButtonArea.childCount; i++)
- {
- this.m_ParentButtonArea.GetChild(i).gameObject.SetActive(false);
- }
- VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.NONE);
- UICanvasFade component = base.GetComponent<UICanvasFade>();
- component.FadeIn();
- }
- public void Close(UnityAction callback = null)
- {
- UICanvasFade component = base.GetComponent<UICanvasFade>();
- component.FadeOut(component.fadeTime, component.isTimeScaling, callback);
- VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
- }
- public void SelectStart(List<VRChoices.SelectPair> choices, UnityAction<VRChoices.SelectPair> callback)
- {
- VRSelectorMenu.m_Instance.Open();
- for (int i = 0; i < choices.Count; i++)
- {
- VRChoices.SelectPair choice = choices[i];
- GameObject gameObject;
- if (this.m_ParentButtonArea.childCount > i)
- {
- gameObject = this.m_ParentButtonArea.GetChild(i).gameObject;
- }
- else
- {
- gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_PrefabSelectorButton);
- gameObject.transform.SetParent(this.m_ParentButtonArea, false);
- }
- gameObject.SetActive(true);
- Button component = gameObject.GetComponent<Button>();
- Text componentInChildren = gameObject.GetComponentInChildren<Text>();
- component.onClick.RemoveAllListeners();
- componentInChildren.text = choice.strText;
- if (callback != null)
- {
- component.onClick.AddListener(delegate
- {
- callback(choice);
- });
- }
- }
- }
- public void SetSelectType(VRChoices.SelectPair.Type type)
- {
- if (type == VRChoices.SelectPair.Type.Look)
- {
- if (this.m_ImageSelectLook)
- {
- this.m_ImageSelectLook.SetActive(true);
- }
- if (this.m_ImageSelectTouch)
- {
- this.m_ImageSelectTouch.SetActive(false);
- }
- if (this.m_ParentButtonArea)
- {
- this.m_ParentButtonArea.gameObject.SetActive(false);
- }
- }
- else if (type == VRChoices.SelectPair.Type.Touch)
- {
- if (this.m_ImageSelectLook)
- {
- this.m_ImageSelectLook.SetActive(false);
- }
- if (this.m_ImageSelectTouch)
- {
- this.m_ImageSelectTouch.SetActive(true);
- }
- if (this.m_ParentButtonArea)
- {
- this.m_ParentButtonArea.gameObject.SetActive(false);
- }
- }
- else if (type == VRChoices.SelectPair.Type.Text)
- {
- if (this.m_ImageSelectLook)
- {
- this.m_ImageSelectLook.SetActive(false);
- }
- if (this.m_ImageSelectTouch)
- {
- this.m_ImageSelectTouch.SetActive(false);
- }
- if (this.m_ParentButtonArea)
- {
- this.m_ParentButtonArea.gameObject.SetActive(true);
- }
- }
- }
- public void SelectFinalize(UnityAction callback = null)
- {
- this.Close(callback);
- }
- private static VRSelectorMenu m_Instance;
- [SerializeField]
- private RectTransform m_ParentButtonArea;
- [SerializeField]
- private GameObject m_PrefabSelectorButton;
- [SerializeField]
- [Tooltip("見て決めるタイプの選択肢の説明イメージ")]
- private GameObject m_ImageSelectLook;
- [SerializeField]
- [Tooltip("触って決めるタイプの選択肢の説明イメージ")]
- private GameObject m_ImageSelectTouch;
- }
|