YotogiOldCommandMenuOVR.cs 12 KB

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