VRSelectorMenu.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using UnityEngine.UI;
  6. public class VRSelectorMenu : MonoBehaviour
  7. {
  8. public static VRSelectorMenu CreateSelector()
  9. {
  10. if (VRSelectorMenu.m_Instance == null)
  11. {
  12. VRSelectorMenu.m_Instance = UnityEngine.Object.FindObjectOfType<VRSelectorMenu>();
  13. }
  14. return VRSelectorMenu.m_Instance;
  15. }
  16. private void Start()
  17. {
  18. if (VRSelectorMenu.m_Instance != null)
  19. {
  20. }
  21. VRSelectorMenu.m_Instance = this;
  22. base.gameObject.SetActive(false);
  23. }
  24. public void Open()
  25. {
  26. for (int i = 0; i < this.m_ParentButtonArea.childCount; i++)
  27. {
  28. this.m_ParentButtonArea.GetChild(i).gameObject.SetActive(false);
  29. }
  30. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.NONE);
  31. UICanvasFade component = base.GetComponent<UICanvasFade>();
  32. component.FadeIn();
  33. }
  34. public void Close(UnityAction callback = null)
  35. {
  36. UICanvasFade component = base.GetComponent<UICanvasFade>();
  37. component.FadeOut(component.fadeTime, component.isTimeScaling, callback);
  38. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  39. }
  40. public void SelectStart(List<VRChoices.SelectPair> choices, UnityAction<VRChoices.SelectPair> callback)
  41. {
  42. VRSelectorMenu.m_Instance.Open();
  43. for (int i = 0; i < choices.Count; i++)
  44. {
  45. VRChoices.SelectPair choice = choices[i];
  46. GameObject gameObject;
  47. if (this.m_ParentButtonArea.childCount > i)
  48. {
  49. gameObject = this.m_ParentButtonArea.GetChild(i).gameObject;
  50. }
  51. else
  52. {
  53. gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_PrefabSelectorButton);
  54. gameObject.transform.SetParent(this.m_ParentButtonArea, false);
  55. }
  56. gameObject.SetActive(true);
  57. Button component = gameObject.GetComponent<Button>();
  58. Text componentInChildren = gameObject.GetComponentInChildren<Text>();
  59. component.onClick.RemoveAllListeners();
  60. componentInChildren.text = choice.strText;
  61. if (callback != null)
  62. {
  63. component.onClick.AddListener(delegate
  64. {
  65. callback(choice);
  66. });
  67. }
  68. }
  69. }
  70. public void SetSelectType(VRChoices.SelectPair.Type type)
  71. {
  72. if (type == VRChoices.SelectPair.Type.Look)
  73. {
  74. if (this.m_ImageSelectLook)
  75. {
  76. this.m_ImageSelectLook.SetActive(true);
  77. }
  78. if (this.m_ImageSelectTouch)
  79. {
  80. this.m_ImageSelectTouch.SetActive(false);
  81. }
  82. if (this.m_ParentButtonArea)
  83. {
  84. this.m_ParentButtonArea.gameObject.SetActive(false);
  85. }
  86. }
  87. else if (type == VRChoices.SelectPair.Type.Touch)
  88. {
  89. if (this.m_ImageSelectLook)
  90. {
  91. this.m_ImageSelectLook.SetActive(false);
  92. }
  93. if (this.m_ImageSelectTouch)
  94. {
  95. this.m_ImageSelectTouch.SetActive(true);
  96. }
  97. if (this.m_ParentButtonArea)
  98. {
  99. this.m_ParentButtonArea.gameObject.SetActive(false);
  100. }
  101. }
  102. else if (type == VRChoices.SelectPair.Type.Text)
  103. {
  104. if (this.m_ImageSelectLook)
  105. {
  106. this.m_ImageSelectLook.SetActive(false);
  107. }
  108. if (this.m_ImageSelectTouch)
  109. {
  110. this.m_ImageSelectTouch.SetActive(false);
  111. }
  112. if (this.m_ParentButtonArea)
  113. {
  114. this.m_ParentButtonArea.gameObject.SetActive(true);
  115. }
  116. }
  117. }
  118. public void SelectFinalize(UnityAction callback = null)
  119. {
  120. this.Close(callback);
  121. }
  122. private static VRSelectorMenu m_Instance;
  123. [SerializeField]
  124. private RectTransform m_ParentButtonArea;
  125. [SerializeField]
  126. private GameObject m_PrefabSelectorButton;
  127. [SerializeField]
  128. [Tooltip("見て決めるタイプの選択肢の説明イメージ")]
  129. private GameObject m_ImageSelectLook;
  130. [SerializeField]
  131. [Tooltip("触って決めるタイプの選択肢の説明イメージ")]
  132. private GameObject m_ImageSelectTouch;
  133. }