OtherCommandShortcut.cs 6.6 KB

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