VRConfigMenu.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using UnityEngine.UI;
  5. public class VRConfigMenu : MonoBehaviour
  6. {
  7. private void Refresh()
  8. {
  9. if (GameMain.Instance == null)
  10. {
  11. return;
  12. }
  13. this.m_2DMouseRotSpeed.SetActive(false);
  14. this.m_2DMouseRotInverse.SetActive(false);
  15. this.m_2DPlaneMovement.SetActive(false);
  16. this.m_2DShowMan.SetActive(false);
  17. this.m_2DFieldOfView.SetActive(false);
  18. this.m_NonTouchPlaneMovement.SetActive(false);
  19. this.m_NonTouchMouseRotEnable.SetActive(false);
  20. this.m_NonTouchMouseRotSpeed.SetActive(false);
  21. this.m_ViveFloorHeight.SetActive(false);
  22. this.m_ViveUseSnapRotate.SetActive(false);
  23. this.m_ViveUseSnapRotateRate.SetActive(false);
  24. this.m_TouchUseSnapRotate.SetActive(false);
  25. this.m_TouchUseSnapRotateRate.SetActive(false);
  26. this.m_CommonEyeHeight.SetActive(true);
  27. this.m_CommonSittingHeight.SetActive(true);
  28. this.m_CommonCameraRotSpeed.SetActive(true);
  29. this.m_CommonCameraMoveSpeed.SetActive(true);
  30. GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
  31. if (vrdeviceTypeID == GameMain.VRDeviceType.NON)
  32. {
  33. this.m_2DMouseRotSpeed.SetActive(true);
  34. this.m_2DMouseRotInverse.SetActive(true);
  35. this.m_2DPlaneMovement.SetActive(true);
  36. this.m_2DShowMan.SetActive(true);
  37. this.m_2DFieldOfView.SetActive(true);
  38. }
  39. else if (vrdeviceTypeID == GameMain.VRDeviceType.RIFT)
  40. {
  41. this.m_NonTouchPlaneMovement.SetActive(true);
  42. this.m_NonTouchMouseRotEnable.SetActive(true);
  43. this.m_NonTouchMouseRotSpeed.SetActive(true);
  44. }
  45. else if (vrdeviceTypeID == GameMain.VRDeviceType.FOVE)
  46. {
  47. this.m_NonTouchPlaneMovement.SetActive(true);
  48. this.m_NonTouchMouseRotEnable.SetActive(true);
  49. this.m_NonTouchMouseRotSpeed.SetActive(true);
  50. }
  51. else if (vrdeviceTypeID == GameMain.VRDeviceType.VIVE)
  52. {
  53. this.m_ViveFloorHeight.SetActive(true);
  54. this.m_ViveUseSnapRotate.SetActive(true);
  55. this.m_ViveUseSnapRotateRate.SetActive(true);
  56. }
  57. else
  58. {
  59. this.m_TouchUseSnapRotate.SetActive(true);
  60. this.m_TouchUseSnapRotateRate.SetActive(true);
  61. }
  62. this.SetValue_Slider(this.m_CommonEyeHeight, 1.5f, 1.8f, GameMain.Instance.CMSystem.VRCameraHeightStand);
  63. this.SetValue_Slider(this.m_CommonSittingHeight, 0.7f, 1f, GameMain.Instance.CMSystem.VRCameraHeightSit);
  64. this.SetValue_Slider(this.m_CommonCameraRotSpeed, 0f, 1f, GameMain.Instance.CMSystem.VRCameraRotSpeedKey);
  65. this.SetValue_Slider(this.m_CommonCameraMoveSpeed, 0f, 1f, GameMain.Instance.CMSystem.VRCameraMoveSpeedKey);
  66. this.SetValue_Slider(this.m_NonTouchMouseRotSpeed, 0f, 1f, GameMain.Instance.CMSystem.VRCameraRotSpeedMouse);
  67. this.SetValue_Slider(this.m_2DMouseRotSpeed, 0f, 1f, GameMain.Instance.CMSystem.VRCameraRotSpeedMouse);
  68. this.SetValue_Slider(this.m_2DFieldOfView, 30f, 60f, GameMain.Instance.CMSystem.VRCameraFov);
  69. this.SetValue_Slider(this.m_ViveUseSnapRotateRate, 10f, 80f, (float)GameMain.Instance.CMSystem.OvrUseSnapRotateRate);
  70. this.SetValue_Slider(this.m_TouchUseSnapRotateRate, 10f, 80f, (float)GameMain.Instance.CMSystem.OvrUseSnapRotateRate);
  71. bool flag = GameMain.Instance.CMSystem.VRCameraPlaneMove;
  72. this.SetValue_ToggleButton(this.m_2DPlaneMovement, new bool[]
  73. {
  74. flag,
  75. !flag
  76. });
  77. flag = GameMain.Instance.CMSystem.VRCamRotDownUp;
  78. this.SetValue_ToggleButton(this.m_2DMouseRotInverse, new bool[]
  79. {
  80. flag,
  81. !flag
  82. });
  83. flag = GameMain.Instance.CMSystem.VRManShow;
  84. this.SetValue_ToggleButton(this.m_2DShowMan, new bool[]
  85. {
  86. flag,
  87. !flag
  88. });
  89. flag = GameMain.Instance.CMSystem.VRCameraPlaneMove;
  90. this.SetValue_ToggleButton(this.m_NonTouchPlaneMovement, new bool[]
  91. {
  92. flag,
  93. !flag
  94. });
  95. flag = GameMain.Instance.CMSystem.OvrMouseRot;
  96. this.SetValue_ToggleButton(this.m_NonTouchMouseRotEnable, new bool[]
  97. {
  98. flag,
  99. !flag
  100. });
  101. flag = (GameMain.Instance.CMSystem.OvrCameraHeightType == CMSystem.OVR_CAM_HEIGHT_TYPE.REAL);
  102. this.SetValue_ToggleButton(this.m_ViveFloorHeight, new bool[]
  103. {
  104. flag,
  105. !flag
  106. });
  107. flag = GameMain.Instance.CMSystem.OvrUseSnapRotate;
  108. this.SetValue_ToggleButton(this.m_ViveUseSnapRotate, new bool[]
  109. {
  110. flag,
  111. !flag
  112. });
  113. this.SetValue_ToggleButton(this.m_TouchUseSnapRotate, new bool[]
  114. {
  115. flag,
  116. !flag
  117. });
  118. VRConfigMenu.SetEvent_Slider(this.m_CommonEyeHeight, delegate(float value)
  119. {
  120. GameMain.Instance.CMSystem.VRCameraHeightStand = value;
  121. });
  122. VRConfigMenu.SetEvent_Slider(this.m_CommonSittingHeight, delegate(float value)
  123. {
  124. GameMain.Instance.CMSystem.VRCameraHeightSit = value;
  125. });
  126. VRConfigMenu.SetEvent_Slider(this.m_CommonCameraRotSpeed, delegate(float value)
  127. {
  128. GameMain.Instance.CMSystem.VRCameraRotSpeedKey = value;
  129. });
  130. VRConfigMenu.SetEvent_Slider(this.m_CommonCameraMoveSpeed, delegate(float value)
  131. {
  132. GameMain.Instance.CMSystem.VRCameraMoveSpeedKey = value;
  133. });
  134. VRConfigMenu.SetEvent_Slider(this.m_ViveUseSnapRotateRate, delegate(float value)
  135. {
  136. GameMain.Instance.CMSystem.OvrUseSnapRotateRate = (int)value;
  137. });
  138. VRConfigMenu.SetEvent_Slider(this.m_TouchUseSnapRotateRate, delegate(float value)
  139. {
  140. GameMain.Instance.CMSystem.OvrUseSnapRotateRate = (int)value;
  141. });
  142. VRConfigMenu.SetEvent_Slider(this.m_NonTouchMouseRotSpeed, delegate(float value)
  143. {
  144. GameMain.Instance.CMSystem.VRCameraRotSpeedMouse = value;
  145. });
  146. VRConfigMenu.SetEvent_Slider(this.m_2DMouseRotSpeed, delegate(float value)
  147. {
  148. GameMain.Instance.CMSystem.VRCameraRotSpeedMouse = value;
  149. });
  150. VRConfigMenu.SetEvent_Slider(this.m_2DFieldOfView, delegate(float value)
  151. {
  152. GameMain.Instance.CMSystem.VRCameraFov = value;
  153. });
  154. GameObject 2DMouseRotInverse = this.m_2DMouseRotInverse;
  155. UnityAction[] array = new UnityAction[2];
  156. array[0] = delegate
  157. {
  158. GameMain.Instance.CMSystem.VRCamRotDownUp = true;
  159. };
  160. array[1] = delegate
  161. {
  162. GameMain.Instance.CMSystem.VRCamRotDownUp = false;
  163. };
  164. VRConfigMenu.SetEvent_ToggleButton(2DMouseRotInverse, array);
  165. GameObject 2DPlaneMovement = this.m_2DPlaneMovement;
  166. UnityAction[] array2 = new UnityAction[2];
  167. array2[0] = delegate
  168. {
  169. GameMain.Instance.CMSystem.VRCameraPlaneMove = true;
  170. };
  171. array2[1] = delegate
  172. {
  173. GameMain.Instance.CMSystem.VRCameraPlaneMove = false;
  174. };
  175. VRConfigMenu.SetEvent_ToggleButton(2DPlaneMovement, array2);
  176. GameObject 2DShowMan = this.m_2DShowMan;
  177. UnityAction[] array3 = new UnityAction[2];
  178. array3[0] = delegate
  179. {
  180. GameMain.Instance.CMSystem.VRManShow = true;
  181. };
  182. array3[1] = delegate
  183. {
  184. GameMain.Instance.CMSystem.VRManShow = false;
  185. };
  186. VRConfigMenu.SetEvent_ToggleButton(2DShowMan, array3);
  187. GameObject viveUseSnapRotate = this.m_ViveUseSnapRotate;
  188. UnityAction[] array4 = new UnityAction[2];
  189. array4[0] = delegate
  190. {
  191. GameMain.Instance.CMSystem.OvrUseSnapRotate = true;
  192. };
  193. array4[1] = delegate
  194. {
  195. GameMain.Instance.CMSystem.OvrUseSnapRotate = false;
  196. };
  197. VRConfigMenu.SetEvent_ToggleButton(viveUseSnapRotate, array4);
  198. GameObject touchUseSnapRotate = this.m_TouchUseSnapRotate;
  199. UnityAction[] array5 = new UnityAction[2];
  200. array5[0] = delegate
  201. {
  202. GameMain.Instance.CMSystem.OvrUseSnapRotate = true;
  203. };
  204. array5[1] = delegate
  205. {
  206. GameMain.Instance.CMSystem.OvrUseSnapRotate = false;
  207. };
  208. VRConfigMenu.SetEvent_ToggleButton(touchUseSnapRotate, array5);
  209. GameObject nonTouchPlaneMovement = this.m_NonTouchPlaneMovement;
  210. UnityAction[] array6 = new UnityAction[2];
  211. array6[0] = delegate
  212. {
  213. GameMain.Instance.CMSystem.VRCameraPlaneMove = true;
  214. };
  215. array6[1] = delegate
  216. {
  217. GameMain.Instance.CMSystem.VRCameraPlaneMove = false;
  218. };
  219. VRConfigMenu.SetEvent_ToggleButton(nonTouchPlaneMovement, array6);
  220. GameObject nonTouchMouseRotEnable = this.m_NonTouchMouseRotEnable;
  221. UnityAction[] array7 = new UnityAction[2];
  222. array7[0] = delegate
  223. {
  224. GameMain.Instance.CMSystem.OvrMouseRot = true;
  225. };
  226. array7[1] = delegate
  227. {
  228. GameMain.Instance.CMSystem.OvrMouseRot = false;
  229. };
  230. VRConfigMenu.SetEvent_ToggleButton(nonTouchMouseRotEnable, array7);
  231. GameObject viveFloorHeight = this.m_ViveFloorHeight;
  232. UnityAction[] array8 = new UnityAction[2];
  233. array8[0] = delegate
  234. {
  235. GameMain.Instance.CMSystem.OvrCameraHeightType = CMSystem.OVR_CAM_HEIGHT_TYPE.REAL;
  236. };
  237. array8[1] = delegate
  238. {
  239. GameMain.Instance.CMSystem.OvrCameraHeightType = CMSystem.OVR_CAM_HEIGHT_TYPE.VR;
  240. };
  241. VRConfigMenu.SetEvent_ToggleButton(viveFloorHeight, array8);
  242. }
  243. private static void SetEvent_Slider(GameObject SliderObject, UnityAction<float> callback)
  244. {
  245. Slider componentInChildren = SliderObject.GetComponentInChildren<Slider>();
  246. componentInChildren.onValueChanged.RemoveAllListeners();
  247. componentInChildren.onValueChanged.AddListener(callback);
  248. }
  249. private static void SetEvent_ToggleButton(GameObject ButtonParentObject, params UnityAction[] callbacks)
  250. {
  251. Button[] buttons = ButtonParentObject.GetComponentsInChildren<Button>();
  252. for (int i = 0; i < buttons.Length; i++)
  253. {
  254. Button button = buttons[i];
  255. UnityAction callback = null;
  256. if (callbacks.Length > i)
  257. {
  258. callback = callbacks[i];
  259. }
  260. else
  261. {
  262. Debug.LogWarning("[VRConfig]フラグの数がイベントの数より少ない");
  263. }
  264. button.onClick.RemoveAllListeners();
  265. button.onClick.AddListener(delegate
  266. {
  267. ColorBlock colors;
  268. for (int j = 0; j < buttons.Length; j++)
  269. {
  270. colors = buttons[j].colors;
  271. colors.normalColor = Color.white * 0.66f;
  272. buttons[j].colors = colors;
  273. }
  274. colors = button.colors;
  275. colors.normalColor = Color.white;
  276. button.colors = colors;
  277. callback();
  278. });
  279. }
  280. }
  281. private void SetValue_Slider(GameObject SliderObject, float min, float max, float value)
  282. {
  283. Slider componentInChildren = SliderObject.GetComponentInChildren<Slider>();
  284. componentInChildren.minValue = min;
  285. componentInChildren.maxValue = max;
  286. componentInChildren.value = value;
  287. }
  288. private void SetValue_ToggleButton(GameObject ButtonParentObject, params bool[] selecteds)
  289. {
  290. Button[] componentsInChildren = ButtonParentObject.GetComponentsInChildren<Button>();
  291. for (int i = 0; i < componentsInChildren.Length; i++)
  292. {
  293. Button button = componentsInChildren[i];
  294. bool flag = false;
  295. if (selecteds.Length > i)
  296. {
  297. flag = selecteds[i];
  298. }
  299. else
  300. {
  301. Debug.LogWarning("[VRConfig]フラグの数がボタンの数より少ない");
  302. }
  303. ColorBlock colors = componentsInChildren[i].colors;
  304. colors.normalColor = ((!flag) ? (Color.white * 0.66f) : Color.white);
  305. componentsInChildren[i].colors = colors;
  306. }
  307. }
  308. private void OnEnable()
  309. {
  310. this.Refresh();
  311. }
  312. [SerializeField]
  313. private GameObject m_CommonEyeHeight;
  314. [SerializeField]
  315. private GameObject m_CommonSittingHeight;
  316. [SerializeField]
  317. private GameObject m_CommonCameraRotSpeed;
  318. [SerializeField]
  319. private GameObject m_CommonCameraMoveSpeed;
  320. [SerializeField]
  321. private GameObject m_ViveFloorHeight;
  322. [SerializeField]
  323. private GameObject m_ViveUseSnapRotate;
  324. [SerializeField]
  325. private GameObject m_ViveUseSnapRotateRate;
  326. [SerializeField]
  327. private GameObject m_TouchUseSnapRotate;
  328. [SerializeField]
  329. private GameObject m_TouchUseSnapRotateRate;
  330. [SerializeField]
  331. private GameObject m_NonTouchPlaneMovement;
  332. [SerializeField]
  333. private GameObject m_NonTouchMouseRotEnable;
  334. [SerializeField]
  335. private GameObject m_NonTouchMouseRotSpeed;
  336. [SerializeField]
  337. private GameObject m_2DMouseRotSpeed;
  338. [SerializeField]
  339. private GameObject m_2DMouseRotInverse;
  340. [SerializeField]
  341. private GameObject m_2DPlaneMovement;
  342. [SerializeField]
  343. private GameObject m_2DShowMan;
  344. [SerializeField]
  345. private GameObject m_2DFieldOfView;
  346. }