YotogiCommandMenuOVR.cs 13 KB

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