YotogiCommandMenuOVR.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using wf;
  7. using Yotogis;
  8. public class YotogiCommandMenuOVR : MonoBehaviour
  9. {
  10. public void Awake()
  11. {
  12. this.clone_src_.gameObject.SetActive(false);
  13. this.command_height_ = (int)(this.clone_src_.rect.height * this.clone_src_.localScale.y);
  14. }
  15. public void Start()
  16. {
  17. this.is_attach_hand_mode_ = false;
  18. if (this.devideType == GameMain.VRDeviceType.RIFT_TOUCH || this.devideType == GameMain.VRDeviceType.VIVE)
  19. {
  20. this.is_attach_hand_mode_ = true;
  21. this.use_adjustment_transform_ = ((this.devideType != GameMain.VRDeviceType.RIFT_TOUCH) ? this.adjustment_htc_pos_ : this.adjustment_rift_pos_);
  22. }
  23. this.command_draw_mgr_.ChangeDeviceMode(this.devideType);
  24. this.draw_gruoup_ = this.command_draw_mgr_.GetComponent<CanvasGroup>();
  25. if (this.is_attach_hand_mode_)
  26. {
  27. GameMain.Instance.OvrMgr.OvrCamera.HandLimitMode = AVRControllerBehavior.LIMIT_MODE.NO_WARP;
  28. GameMain.Instance.OvrMgr.OvrCamera.HandYotogiMode = true;
  29. this.AttachHand();
  30. }
  31. }
  32. private void OnDestroy()
  33. {
  34. if (GameMain.Instance.VRMode)
  35. {
  36. GameMain.Instance.OvrMgr.OvrCamera.HandLimitMode = AVRControllerBehavior.LIMIT_MODE.NORMAL;
  37. GameMain.Instance.OvrMgr.OvrCamera.HandYotogiMode = false;
  38. }
  39. }
  40. private void AttachHand()
  41. {
  42. if (GameMain.Instance.VRMode)
  43. {
  44. this.controller_L_ = GameMain.Instance.OvrMgr.OvrCamera.GetVRControllerButtons(true);
  45. this.controller_R_ = GameMain.Instance.OvrMgr.OvrCamera.GetVRControllerButtons(false);
  46. this.controller_trans_L_ = this.controller_L_.transform;
  47. this.controller_trans_R_ = this.controller_R_.transform;
  48. this.controller_attach_side_L_ = false;
  49. }
  50. }
  51. public void SetOnEnterEvetn(Action<Skill.Data.Command.Data> call_event)
  52. {
  53. this.call_event_ = call_event;
  54. }
  55. public void ReserveSkillCommand(Skill.Data.Command skill_command)
  56. {
  57. this.DestroySkillCommand();
  58. for (int i = 0; i < skill_command.data.Length; i++)
  59. {
  60. if (this.command_dic_.ContainsKey(skill_command.data[i]))
  61. {
  62. return;
  63. }
  64. Skill.Data.Command.Data data = skill_command.data[i];
  65. RectTransform rectTransform = UnityEngine.Object.Instantiate<RectTransform>(this.clone_src_);
  66. rectTransform.SetParent(this.command_panel_, false);
  67. rectTransform.GetComponent<Text>().text = data.basic.name;
  68. rectTransform.gameObject.SetActive(false);
  69. this.command_dic_.Add(data, rectTransform);
  70. }
  71. }
  72. public void ClearCommand()
  73. {
  74. foreach (KeyValuePair<Skill.Data.Command.Data, RectTransform> keyValuePair in this.command_dic_)
  75. {
  76. keyValuePair.Value.gameObject.SetActive(false);
  77. }
  78. }
  79. public void DestroySkillCommand()
  80. {
  81. foreach (KeyValuePair<Skill.Data.Command.Data, RectTransform> keyValuePair in this.command_dic_)
  82. {
  83. UnityEngine.Object.Destroy(keyValuePair.Value.gameObject);
  84. }
  85. this.command_dic_.Clear();
  86. this.select_command_ = null;
  87. }
  88. public void AddCommand(Skill.Data.Command.Data command_data)
  89. {
  90. if (!this.command_dic_.ContainsKey(command_data))
  91. {
  92. return;
  93. }
  94. this.command_dic_[command_data].gameObject.SetActive(true);
  95. }
  96. public void FixCommand()
  97. {
  98. int num = int.MaxValue;
  99. int num2 = 0;
  100. Skill.Data.Command.Data data = null;
  101. foreach (KeyValuePair<Skill.Data.Command.Data, RectTransform> keyValuePair in this.command_dic_)
  102. {
  103. if (keyValuePair.Value.gameObject.activeSelf)
  104. {
  105. Vector3 localPosition = keyValuePair.Value.localPosition;
  106. localPosition.y = (float)(this.command_height_ * (num2++ * -1));
  107. keyValuePair.Value.localPosition = localPosition;
  108. if (keyValuePair.Key.basic.id < num)
  109. {
  110. num = keyValuePair.Key.basic.id;
  111. data = keyValuePair.Key;
  112. }
  113. }
  114. }
  115. if (data != null)
  116. {
  117. if (this.select_command_ == null)
  118. {
  119. this.select_command_ = data;
  120. }
  121. bool visible = this.visible;
  122. if (!visible)
  123. {
  124. this.visible = true;
  125. }
  126. this.Select(this.select_command_);
  127. if (!visible)
  128. {
  129. this.visible = false;
  130. }
  131. }
  132. else
  133. {
  134. this.select_command_ = null;
  135. this.visible = false;
  136. }
  137. }
  138. public bool Next()
  139. {
  140. if (!this.visible)
  141. {
  142. return false;
  143. }
  144. if (this.cbl_class != null)
  145. {
  146. this.cbl_class.Next();
  147. this.cbl_class.Enter();
  148. }
  149. List<Skill.Data.Command.Data> list = new List<Skill.Data.Command.Data>();
  150. foreach (KeyValuePair<Skill.Data.Command.Data, RectTransform> keyValuePair in this.command_dic_)
  151. {
  152. if (keyValuePair.Value.gameObject.activeSelf)
  153. {
  154. list.Add(keyValuePair.Key);
  155. }
  156. }
  157. list.Sort((Skill.Data.Command.Data a, Skill.Data.Command.Data b) => a.basic.id - b.basic.id);
  158. int i = 0;
  159. while (i < list.Count)
  160. {
  161. if (list[i] != this.select_command_)
  162. {
  163. i++;
  164. }
  165. else
  166. {
  167. if (this.is_commandloop_)
  168. {
  169. if (i + 1 < list.Count)
  170. {
  171. this.Select(list[i + 1]);
  172. }
  173. else
  174. {
  175. this.Select(list[0]);
  176. }
  177. return true;
  178. }
  179. if (i + 1 < list.Count)
  180. {
  181. this.Select(list[i + 1]);
  182. return true;
  183. }
  184. return false;
  185. }
  186. }
  187. return false;
  188. }
  189. public bool Prev()
  190. {
  191. if (!this.visible)
  192. {
  193. return false;
  194. }
  195. if (this.cbl_class != null)
  196. {
  197. this.cbl_class.Prev();
  198. this.cbl_class.Enter();
  199. }
  200. List<Skill.Data.Command.Data> list = new List<Skill.Data.Command.Data>();
  201. foreach (KeyValuePair<Skill.Data.Command.Data, RectTransform> keyValuePair in this.command_dic_)
  202. {
  203. if (keyValuePair.Value.gameObject.activeSelf)
  204. {
  205. list.Add(keyValuePair.Key);
  206. }
  207. }
  208. list.Sort((Skill.Data.Command.Data a, Skill.Data.Command.Data b) => a.basic.id - b.basic.id);
  209. int i = 0;
  210. while (i < list.Count)
  211. {
  212. if (list[i] != this.select_command_)
  213. {
  214. i++;
  215. }
  216. else
  217. {
  218. if (this.is_commandloop_)
  219. {
  220. if (0 <= i - 1)
  221. {
  222. this.Select(list[i - 1]);
  223. }
  224. else
  225. {
  226. this.Select(list[list.Count - 1]);
  227. }
  228. return true;
  229. }
  230. if (0 <= i - 1)
  231. {
  232. this.Select(list[i - 1]);
  233. return true;
  234. }
  235. return false;
  236. }
  237. }
  238. return false;
  239. }
  240. public void Enter()
  241. {
  242. if (!this.visible)
  243. {
  244. return;
  245. }
  246. if (this.select_command_ != null && this.call_event_ != null)
  247. {
  248. this.call_event_(this.select_command_);
  249. }
  250. }
  251. public void Select(Skill.Data.Command.Data command_data)
  252. {
  253. if (!this.visible)
  254. {
  255. return;
  256. }
  257. if (!this.command_dic_[command_data].gameObject.activeSelf)
  258. {
  259. int num = -1;
  260. foreach (KeyValuePair<Skill.Data.Command.Data, RectTransform> keyValuePair in this.command_dic_)
  261. {
  262. if (keyValuePair.Value.gameObject.activeSelf && num < keyValuePair.Key.basic.id)
  263. {
  264. num = keyValuePair.Key.basic.id;
  265. command_data = keyValuePair.Key;
  266. }
  267. }
  268. }
  269. int num2 = 0;
  270. foreach (KeyValuePair<Skill.Data.Command.Data, RectTransform> keyValuePair2 in this.command_dic_)
  271. {
  272. if (keyValuePair2.Value.gameObject.activeSelf)
  273. {
  274. keyValuePair2.Value.GetComponent<Text>().color = ((keyValuePair2.Key != command_data) ? Color.gray : Color.white);
  275. if (keyValuePair2.Key == command_data)
  276. {
  277. Vector3 localPosition = this.command_panel_.transform.localPosition;
  278. localPosition.y = (float)this.GetPanelPosY(num2);
  279. if (this.select_command_ == command_data)
  280. {
  281. this.command_panel_.transform.localPosition = localPosition;
  282. }
  283. else
  284. {
  285. iTween.Stop(this.command_panel_.gameObject);
  286. iTween component = this.command_panel_.GetComponent<iTween>();
  287. if (component != null)
  288. {
  289. UnityEngine.Object.DestroyImmediate(component);
  290. }
  291. Hashtable args = TweenHash.EaseOutSine(TweenHash.Type.Position, localPosition, 0.15f);
  292. iTween.MoveTo(this.command_panel_.gameObject, args);
  293. }
  294. this.select_command_ = command_data;
  295. }
  296. num2++;
  297. }
  298. }
  299. }
  300. public bool visible
  301. {
  302. get
  303. {
  304. return base.gameObject.activeSelf;
  305. }
  306. set
  307. {
  308. base.gameObject.SetActive(value);
  309. }
  310. }
  311. public float alpha
  312. {
  313. get
  314. {
  315. return this.draw_gruoup_.alpha;
  316. }
  317. set
  318. {
  319. this.draw_gruoup_.alpha = value;
  320. }
  321. }
  322. public YotogiCommandMenuOVRWithChubLip cbl_class
  323. {
  324. get
  325. {
  326. return this.cbl_class_;
  327. }
  328. }
  329. private void Update()
  330. {
  331. if (this.is_attach_hand_mode_)
  332. {
  333. this.alpha = (float)((!GameMain.Instance.OvrMgr.OvrCamera.IsHandPenMode) ? 1 : 0);
  334. if (GameMain.Instance.OvrMgr.OvrCamera.IsHandPenMode)
  335. {
  336. return;
  337. }
  338. bool handYotogiMode = GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller.HandYotogiMode;
  339. bool handYotogiMode2 = GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller.HandYotogiMode;
  340. if (this.m_bBackHandL != handYotogiMode)
  341. {
  342. if (handYotogiMode)
  343. {
  344. this.controller_attach_side_L_ = true;
  345. }
  346. else if (handYotogiMode2)
  347. {
  348. this.controller_attach_side_L_ = false;
  349. }
  350. this.m_bBackHandL = handYotogiMode;
  351. }
  352. if (this.m_bBackHandR != handYotogiMode2)
  353. {
  354. if (handYotogiMode2)
  355. {
  356. this.controller_attach_side_L_ = false;
  357. }
  358. else if (handYotogiMode)
  359. {
  360. this.controller_attach_side_L_ = true;
  361. }
  362. this.m_bBackHandR = handYotogiMode2;
  363. }
  364. if (!handYotogiMode && !handYotogiMode2)
  365. {
  366. this.alpha = 0f;
  367. return;
  368. }
  369. if (this.controller_attach_side_L_ && !handYotogiMode)
  370. {
  371. return;
  372. }
  373. if (!this.controller_attach_side_L_ && !handYotogiMode2)
  374. {
  375. return;
  376. }
  377. AVRControllerButtons avrcontrollerButtons;
  378. Transform transform;
  379. if (this.controller_attach_side_L_)
  380. {
  381. avrcontrollerButtons = this.controller_L_;
  382. transform = this.controller_trans_L_;
  383. if (handYotogiMode2 && this.controller_R_.GetPressDown(AVRControllerButtons.BTN.TRIGGER))
  384. {
  385. this.controller_attach_side_L_ = false;
  386. this.change_hand_ = true;
  387. }
  388. }
  389. else
  390. {
  391. avrcontrollerButtons = this.controller_R_;
  392. transform = this.controller_trans_R_;
  393. if (handYotogiMode && this.controller_L_.GetPressDown(AVRControllerButtons.BTN.TRIGGER))
  394. {
  395. this.controller_attach_side_L_ = true;
  396. this.change_hand_ = true;
  397. }
  398. }
  399. if (avrcontrollerButtons != null)
  400. {
  401. if (avrcontrollerButtons.Type == AVRControllerButtons.TYPE.TOUCH)
  402. {
  403. Vector2 axis = avrcontrollerButtons.GetAxis();
  404. if (axis.y < -0.3f)
  405. {
  406. if (!this.stick_down_)
  407. {
  408. this.Next();
  409. }
  410. this.stick_down_ = true;
  411. }
  412. else if (axis.y > 0.3f)
  413. {
  414. if (!this.stick_down_)
  415. {
  416. this.Prev();
  417. }
  418. this.stick_down_ = true;
  419. }
  420. else
  421. {
  422. this.stick_down_ = false;
  423. }
  424. }
  425. else if (avrcontrollerButtons.Type == AVRControllerButtons.TYPE.VIVE && avrcontrollerButtons.GetPressUp(AVRControllerButtons.BTN.STICK_PAD))
  426. {
  427. Vector2 axis2 = avrcontrollerButtons.GetAxis();
  428. if (axis2.y < -0.3f)
  429. {
  430. this.Next();
  431. }
  432. else if (axis2.y > 0.3f)
  433. {
  434. this.Prev();
  435. }
  436. }
  437. }
  438. if (avrcontrollerButtons != null && !avrcontrollerButtons.GetPress(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) && avrcontrollerButtons.GetPressUp(AVRControllerButtons.BTN.TRIGGER))
  439. {
  440. if (!this.change_hand_)
  441. {
  442. this.Enter();
  443. }
  444. this.change_hand_ = false;
  445. }
  446. if (transform != null)
  447. {
  448. base.transform.position = transform.position;
  449. base.transform.rotation = transform.rotation;
  450. this.command_draw_mgr_.imagePositionOffset = this.use_adjustment_transform_.anchoredPosition;
  451. this.command_draw_mgr_.rotationOffset = this.use_adjustment_transform_.localEulerAngles;
  452. }
  453. }
  454. if (!this.is_attach_hand_mode_)
  455. {
  456. bool flag = false;
  457. if (GameMain.Instance.OvrMgr != null)
  458. {
  459. flag = GameMain.Instance.OvrMgr.OvrCamera.IsUIShow;
  460. }
  461. this.command_draw_mgr_.isVisible = !flag;
  462. if (this.command_draw_mgr_.isVisible)
  463. {
  464. if (Input.GetKeyDown(KeyCode.DownArrow))
  465. {
  466. this.Next();
  467. }
  468. if (Input.GetKeyDown(KeyCode.UpArrow))
  469. {
  470. this.Prev();
  471. }
  472. if (Input.GetKeyDown(KeyCode.Return))
  473. {
  474. this.Enter();
  475. }
  476. }
  477. }
  478. }
  479. private int GetPanelPosY(int select_command_no)
  480. {
  481. return this.command_height_ * select_command_no;
  482. }
  483. private GameMain.VRDeviceType devideType
  484. {
  485. get
  486. {
  487. return GameMain.Instance.VRDeviceTypeID;
  488. }
  489. }
  490. private bool m_bBackHandL;
  491. private bool m_bBackHandR;
  492. [SerializeField]
  493. private RectTransform command_panel_;
  494. [SerializeField]
  495. private RectTransform clone_src_;
  496. [SerializeField]
  497. private YotogiCommandMenuOVRWithChubLip cbl_class_;
  498. [SerializeField]
  499. private VRCommandMenuDrawManager command_draw_mgr_;
  500. [SerializeField]
  501. private bool is_commandloop_;
  502. [SerializeField]
  503. private RectTransform adjustment_rift_pos_;
  504. [SerializeField]
  505. private RectTransform adjustment_htc_pos_;
  506. private int command_height_;
  507. private bool is_attach_hand_mode_;
  508. private Dictionary<Skill.Data.Command.Data, RectTransform> command_dic_ = new Dictionary<Skill.Data.Command.Data, RectTransform>();
  509. private Skill.Data.Command.Data select_command_;
  510. private Action<Skill.Data.Command.Data> call_event_;
  511. private CanvasGroup draw_gruoup_;
  512. private bool controller_attach_side_L_;
  513. private AVRControllerButtons controller_L_;
  514. private AVRControllerButtons controller_R_;
  515. private Transform controller_trans_L_;
  516. private Transform controller_trans_R_;
  517. private RectTransform use_adjustment_transform_;
  518. private bool change_hand_;
  519. private bool stick_down_;
  520. }