OtherCommandShortcut.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using UnityEngine.UI;
  6. public class OtherCommandShortcut : MonoBehaviour
  7. {
  8. public bool IsLeftHand
  9. {
  10. get
  11. {
  12. return this.m_IsLeftHand;
  13. }
  14. set
  15. {
  16. this.m_IsLeftHand = value;
  17. }
  18. }
  19. public AVRController controller
  20. {
  21. get
  22. {
  23. return this.m_Controller;
  24. }
  25. private set
  26. {
  27. this.m_Controller = value;
  28. }
  29. }
  30. private CircleListSelectUI circleList
  31. {
  32. get
  33. {
  34. return this.m_CircleList;
  35. }
  36. set
  37. {
  38. this.m_CircleList = value;
  39. }
  40. }
  41. public bool isEnableHandUI
  42. {
  43. get
  44. {
  45. return this.circleList != null && this.circleList.gameObject.activeSelf;
  46. }
  47. set
  48. {
  49. if (this.circleList != null && this.circleList.gameObject.activeSelf != value)
  50. {
  51. this.circleList.gameObject.SetActive(value);
  52. }
  53. }
  54. }
  55. public void Init(bool isLeftHand)
  56. {
  57. this.IsLeftHand = isLeftHand;
  58. Debug.Log("初期化:様々なショートカットを行う手元UI");
  59. this.controller = ((!isLeftHand) ? GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller : GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller);
  60. this.InitCircleUI();
  61. }
  62. private void InitCircleUI()
  63. {
  64. string text = "OVR/CircleCommandUI/HandSignDataShortcut(Cotroller)";
  65. GameObject gameObject = Resources.Load<GameObject>(text);
  66. if (gameObject == null)
  67. {
  68. NDebug.Assert("[HandSignShortcut] " + text + "\nプレハブが見つかりません", false);
  69. }
  70. GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject);
  71. this.circleList = gameObject2.GetComponent<CircleListSelectUI>();
  72. this.m_ItemList = new List<KeyValuePair<string, Action<OtherCommandShortcut.ItemData>>>();
  73. this.m_ItemList.Add(new KeyValuePair<string, Action<OtherCommandShortcut.ItemData>>("撮影", delegate(OtherCommandShortcut.ItemData itemData)
  74. {
  75. GameMain.Instance.OvrIK.SelfShotCam();
  76. }));
  77. this.m_ItemList.Add(new KeyValuePair<string, Action<OtherCommandShortcut.ItemData>>((!GameMain.Instance.OvrIK.EyeToCam) ? "カメラ視線OFF" : "カメラ視線ON", delegate(OtherCommandShortcut.ItemData itemData)
  78. {
  79. GameMain.Instance.OvrIK.EyeToCam = !GameMain.Instance.OvrIK.EyeToCam;
  80. if (GameMain.Instance.OvrIK.EyeToCam)
  81. {
  82. itemData.text.text = "カメラ視線ON";
  83. }
  84. else
  85. {
  86. itemData.text.text = "カメラ視線OFF";
  87. }
  88. }));
  89. this.CreateItemList();
  90. CircleCommandUI circleCommandUI = this.circleList.circleCommandUI;
  91. circleCommandUI.onSelect.AddListener(new UnityAction<GameObject>(this.OnSelectItem));
  92. circleCommandUI.onDeselect.AddListener(new UnityAction<GameObject>(this.OnDeselectItem));
  93. circleCommandUI.onDecide.AddListener(new UnityAction<GameObject>(this.OnDecide));
  94. this.circleList.controller = this.controller;
  95. Transform transform = gameObject2.transform;
  96. transform.SetParent(base.transform);
  97. transform.localPosition = Vector3.zero;
  98. transform.localRotation = Quaternion.identity;
  99. transform.localScale = Vector3.one;
  100. Vector3 b = new Vector3(0.03f, 0.15f, -0.05f);
  101. Vector3 localEulerAngles = new Vector3(35f, 15f, 0f);
  102. if (this.IsLeftHand)
  103. {
  104. b.Scale(new Vector3(-1f, 1f, 1f));
  105. localEulerAngles.Scale(new Vector3(1f, -1f, -1f));
  106. }
  107. transform.localPosition += b;
  108. transform.localEulerAngles = localEulerAngles;
  109. GameObject childObject = UTY.GetChildObject(this.circleList.gameObject, "CircleCommandUI/text right hand", false);
  110. childObject.GetComponent<Text>().text = ((!this.IsLeftHand) ? "右" : "左");
  111. }
  112. private void CreateItemList()
  113. {
  114. CircleCommandUI circleCommandUI = this.circleList.circleCommandUI;
  115. circleCommandUI.Show<Transform>(this.m_ItemList.Count, delegate(int index, Transform trans)
  116. {
  117. Text componentInChildren = trans.GetComponentInChildren<Text>();
  118. trans.localScale = Vector3.one * 0.5f;
  119. OtherCommandShortcut.ItemData itemData = trans.gameObject.AddComponent<OtherCommandShortcut.ItemData>();
  120. itemData.text = componentInChildren;
  121. KeyValuePair<string, Action<OtherCommandShortcut.ItemData>> keyValuePair = this.m_ItemList[index];
  122. itemData.text.text = keyValuePair.Key;
  123. itemData.onDecide = keyValuePair.Value;
  124. });
  125. }
  126. private void OnSelectItem(GameObject item)
  127. {
  128. if (item == null)
  129. {
  130. return;
  131. }
  132. Graphic component = item.GetComponent<Graphic>();
  133. if (component != null)
  134. {
  135. component.color = Color.red;
  136. }
  137. item.transform.localScale = Vector3.one;
  138. item.transform.SetAsLastSibling();
  139. }
  140. private void OnDeselectItem(GameObject item)
  141. {
  142. if (item == null)
  143. {
  144. return;
  145. }
  146. Graphic component = item.GetComponent<Graphic>();
  147. if (component != null)
  148. {
  149. Color white = Color.white;
  150. white.a = 0.5f;
  151. component.color = white;
  152. }
  153. item.transform.localScale = Vector3.one * 0.5f;
  154. }
  155. private void OnDecide(GameObject selectItem)
  156. {
  157. if (selectItem == null)
  158. {
  159. Debug.LogWarning("選択項目にnullが入った");
  160. return;
  161. }
  162. this.OnDeselectItem(selectItem);
  163. if (!ControllerShortcutSettingData.config.isEveryShowMode)
  164. {
  165. this.m_CircleList.SetActiveUI(false);
  166. }
  167. OtherCommandShortcut.ItemData component = selectItem.GetComponent<OtherCommandShortcut.ItemData>();
  168. if (component != null && component.onDecide != null)
  169. {
  170. component.onDecide(component);
  171. }
  172. }
  173. private void OnApplicationQuit()
  174. {
  175. this.m_IsQuitting = true;
  176. }
  177. private void OnDestroy()
  178. {
  179. if (this.m_IsQuitting)
  180. {
  181. return;
  182. }
  183. if (this.circleList != null && this.circleList.gameObject != null)
  184. {
  185. UnityEngine.Object.Destroy(this.circleList.gameObject);
  186. Debug.Log("[OtherCommandShortcut] コントローラについているUIを破棄しました");
  187. }
  188. }
  189. [SerializeField]
  190. private CircleListSelectUI m_CircleList;
  191. private bool m_IsLeftHand;
  192. private AVRController m_Controller;
  193. private List<KeyValuePair<string, Action<OtherCommandShortcut.ItemData>>> m_ItemList;
  194. private bool m_IsQuitting;
  195. private class ItemData : MonoBehaviour
  196. {
  197. public Action<OtherCommandShortcut.ItemData> onDecide { get; set; }
  198. public Text text { get; set; }
  199. }
  200. }