YotogiCommandMenuOVR.cs 13 KB

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