VRFaceShortcutConfig.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. using System;
  2. using System.Collections.Generic;
  3. using Kasizuki;
  4. using UnityEngine;
  5. public class VRFaceShortcutConfig : MonoBehaviour
  6. {
  7. public void CacheItemTemplate<T>(string path) where T : VRFaceShortcutConfig.Item
  8. {
  9. Transform childObject = VRFaceShortcutConfig.GetChildObject<Transform>(this.m_Grid.gameObject, path);
  10. T t = childObject.gameObject.AddComponent<T>();
  11. Type typeFromHandle = typeof(T);
  12. this.m_ItemTemplateList.Add(typeFromHandle, t);
  13. childObject.gameObject.SetActive(false);
  14. }
  15. public T CreateItem<T>(string itemLabel) where T : VRFaceShortcutConfig.Item
  16. {
  17. if (this.m_ItemDic.ContainsKey(itemLabel))
  18. {
  19. string message = "[VRFaceShortcutConfig] 既に「" + itemLabel + "」という項目が存在しています";
  20. Debug.LogError(message);
  21. NDebug.Assert(message, false);
  22. }
  23. VRFaceShortcutConfig.Item item;
  24. if (!this.m_ItemTemplateList.TryGetValue(typeof(T), out item))
  25. {
  26. string message2 = "[VRFaceShortcutConfig] " + typeof(T).ToString() + "型のUI項目はキャッシュされていません";
  27. Debug.LogError(message2);
  28. NDebug.Assert(message2, false);
  29. }
  30. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(item.gameObject);
  31. gameObject.transform.SetParent(this.m_Grid.transform, false);
  32. T component = gameObject.GetComponent<T>();
  33. component.gameObject.SetActive(true);
  34. component.label.text = itemLabel;
  35. this.m_ItemDic.Add(itemLabel, component);
  36. return component;
  37. }
  38. private void Awake()
  39. {
  40. this.CacheItemTemplate<VRFaceShortcutConfig.ItemSlider>("temp slider");
  41. this.CacheItemTemplate<VRFaceShortcutConfig.ItemSelectButton>("temp select");
  42. this.CacheItemTemplate<VRFaceShortcutConfig.ParentMultiButton>("temp multi select");
  43. this.CreateDefaultItems();
  44. this.CreateViveItems();
  45. NGUIWindow fadeWindowThis = this.m_FadeWindowThis;
  46. fadeWindowThis.OnClose = (Action)Delegate.Combine(fadeWindowThis.OnClose, new Action(delegate()
  47. {
  48. ControllerShortcutSettingData.config.Write();
  49. }));
  50. }
  51. private void CreateDefaultItems()
  52. {
  53. OVRLipSync.VariableData variable = GameMain.Instance.LipSyncMgr.Variable;
  54. VRFaceShortcutConfig.ItemSlider itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("リップシンク:マイク感度");
  55. itemSlider.min = 0f;
  56. itemSlider.max = 10f;
  57. itemSlider.Set(variable.MicSensitivity);
  58. itemSlider.onValueChanged = delegate(float value)
  59. {
  60. GameMain.Instance.LipSyncMgr.Variable.MicSensitivity = value;
  61. };
  62. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("リップシンク:自分の声の大きさ");
  63. itemSlider.min = 0f;
  64. itemSlider.max = 10f;
  65. itemSlider.Set(variable.MicVolume);
  66. itemSlider.onValueChanged = delegate(float value)
  67. {
  68. GameMain.Instance.LipSyncMgr.Variable.MicVolume = value;
  69. };
  70. VRFaceShortcutConfig.ItemSelectButton itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("リップシンク:ミュートにする");
  71. itemSelectButton.textLeft.text = "ON";
  72. itemSelectButton.textRight.text = "OFF";
  73. itemSelectButton.Set(variable.Mute);
  74. itemSelectButton.onClickIsLeft = delegate(bool isLeft)
  75. {
  76. variable.Mute = isLeft;
  77. };
  78. itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("手元ショートカット:表情の変化");
  79. itemSelectButton.textLeft.text = "即座に変更する";
  80. itemSelectButton.textRight.text = "選択して決定する";
  81. itemSelectButton.Set(ControllerShortcutSettingData.config.isDirectMode);
  82. itemSelectButton.onClickIsLeft = delegate(bool isLeft)
  83. {
  84. ControllerShortcutSettingData.config.isDirectMode = isLeft;
  85. };
  86. itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("手元ショートカット:手元のUI");
  87. itemSelectButton.textLeft.text = "常に表示する";
  88. itemSelectButton.textRight.text = "決定時に隠す";
  89. itemSelectButton.Set(ControllerShortcutSettingData.config.isEveryShowMode);
  90. itemSelectButton.onClickIsLeft = delegate(bool isLeft)
  91. {
  92. ControllerShortcutSettingData.config.isEveryShowMode = isLeft;
  93. };
  94. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体向きの頭への追従");
  95. itemSlider.min = 0f;
  96. itemSlider.max = 1f;
  97. itemSlider.Set(ControllerShortcutSettingData.config.maintainPelvisPosition);
  98. itemSlider.onValueChanged = delegate(float value)
  99. {
  100. ControllerShortcutSettingData.config.maintainPelvisPosition = value;
  101. };
  102. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体位置の頭への追従");
  103. itemSlider.min = 0f;
  104. itemSlider.max = 1f;
  105. itemSlider.Set(ControllerShortcutSettingData.config.bodyPosStiffness);
  106. itemSlider.onValueChanged = delegate(float value)
  107. {
  108. ControllerShortcutSettingData.config.bodyPosStiffness = value;
  109. };
  110. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体回転の頭への追従");
  111. itemSlider.min = 0f;
  112. itemSlider.max = 1f;
  113. itemSlider.Set(ControllerShortcutSettingData.config.bodyRotStiffness);
  114. itemSlider.onValueChanged = delegate(float value)
  115. {
  116. ControllerShortcutSettingData.config.bodyRotStiffness = value;
  117. };
  118. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("胸部回転の頭への追従");
  119. itemSlider.min = 0f;
  120. itemSlider.max = 1f;
  121. itemSlider.Set(ControllerShortcutSettingData.config.chestRotationWeight);
  122. itemSlider.onValueChanged = delegate(float value)
  123. {
  124. ControllerShortcutSettingData.config.chestRotationWeight = value;
  125. };
  126. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("カメラの画角");
  127. itemSlider.min = 0f;
  128. itemSlider.max = 1f;
  129. itemSlider.Set(ControllerShortcutSettingData.config.selfCameraFOV);
  130. itemSlider.onValueChanged = delegate(float value)
  131. {
  132. ControllerShortcutSettingData.config.selfCameraFOV = value;
  133. };
  134. VRFaceShortcutConfig.ParentMultiButton parentMultiButton = this.CreateItem<VRFaceShortcutConfig.ParentMultiButton>("手のスカートへの当たり判定\n※VR CONFIGより優先されます。");
  135. parentMultiButton.textRight.text = "OFF";
  136. parentMultiButton.textLeft.text = "常時ON";
  137. parentMultiButton.textCenter.text = "握時ON";
  138. if (GameMain.Instance.CMSystem.SConfig.OvrHandHitToSkirtVAS == CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.OFF)
  139. {
  140. parentMultiButton.Set(0);
  141. }
  142. else if (GameMain.Instance.CMSystem.SConfig.OvrHandHitToSkirtVAS == CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.ON)
  143. {
  144. parentMultiButton.Set(1);
  145. }
  146. else
  147. {
  148. parentMultiButton.Set(2);
  149. }
  150. parentMultiButton.onClick = delegate(int index)
  151. {
  152. CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT ovrHandHitToSkirtVAS;
  153. if (index == 0)
  154. {
  155. ovrHandHitToSkirtVAS = CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.OFF;
  156. }
  157. else if (index == 1)
  158. {
  159. ovrHandHitToSkirtVAS = CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.ON;
  160. }
  161. else
  162. {
  163. ovrHandHitToSkirtVAS = CMSystem.SerializeConfig.OVR_HAND_TO_SKIRT.GRAB;
  164. }
  165. GameMain.Instance.CMSystem.SConfig.OvrHandHitToSkirtVAS = ovrHandHitToSkirtVAS;
  166. };
  167. }
  168. private void CreateViveItems()
  169. {
  170. if (GameMain.Instance.VRDeviceTypeID != GameMain.VRDeviceType.VIVE)
  171. {
  172. return;
  173. }
  174. VRFaceShortcutConfig.ItemSelectButton itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("一番上にあるトラッカーを\n頭トラッキングに利用");
  175. itemSelectButton.textLeft.text = "ON";
  176. itemSelectButton.textRight.text = "OFF";
  177. itemSelectButton.Set(ControllerShortcutSettingData.config.use1TrackerForHead);
  178. itemSelectButton.onClickIsLeft = delegate(bool isLeft)
  179. {
  180. ControllerShortcutSettingData.config.use1TrackerForHead = isLeft;
  181. this.SetActiveItem("2つめと3つめのトラッカーを\n足トラッキングに利用", isLeft, false);
  182. this.SetActiveItem("1つめと2つめのトラッカーを\n足トラッキングに利用", !isLeft, false);
  183. };
  184. }
  185. private void SetActiveItem(string itemKey, bool isActive, bool isEnableError = true)
  186. {
  187. VRFaceShortcutConfig.Item item;
  188. if (!this.m_ItemDic.TryGetValue(itemKey, out item))
  189. {
  190. if (isEnableError)
  191. {
  192. string message = "[VRFaceShortcutConfig] コンフィグ項目に「" + itemKey + "」は存在しません";
  193. Debug.LogError(message);
  194. NDebug.Assert(message, false);
  195. }
  196. return;
  197. }
  198. if (item.gameObject.activeSelf != isActive)
  199. {
  200. item.gameObject.SetActive(isActive);
  201. this.m_IsUpdateReposition = true;
  202. }
  203. }
  204. private void LateUpdate()
  205. {
  206. if (this.m_IsUpdateReposition)
  207. {
  208. this.m_IsUpdateReposition = false;
  209. this.m_Grid.Reposition();
  210. this.m_ScrollView.UpdatePosition();
  211. }
  212. }
  213. private static T GetChildObject<T>(GameObject gameObject, string path)
  214. {
  215. GameObject childObject = UTY.GetChildObject(gameObject, path, false);
  216. if (childObject == null)
  217. {
  218. string message = string.Concat(new string[]
  219. {
  220. "[VRFaceShortcutConfig] ",
  221. gameObject.name,
  222. "/",
  223. path,
  224. "が見つかりませんでした"
  225. });
  226. NDebug.Assert(message, false);
  227. Debug.LogError(message);
  228. }
  229. T component = childObject.GetComponent<T>();
  230. if (component == null)
  231. {
  232. string message2 = string.Concat(new object[]
  233. {
  234. "[VRFaceShortcutConfig] ",
  235. gameObject.name,
  236. "/",
  237. path,
  238. "に、\n",
  239. typeof(T),
  240. "のコンポーネントがありませんでした"
  241. });
  242. NDebug.Assert(message2, false);
  243. Debug.LogError(message2);
  244. }
  245. return component;
  246. }
  247. [SerializeField]
  248. [Range(0.001f, 1f)]
  249. private float m_FadeSpeed = 0.25f;
  250. [SerializeField]
  251. private NGUIWindow m_FadeWindowThis;
  252. [SerializeField]
  253. private UIScrollView m_ScrollView;
  254. [SerializeField]
  255. private UIGrid m_Grid;
  256. private Dictionary<Type, VRFaceShortcutConfig.Item> m_ItemTemplateList = new Dictionary<Type, VRFaceShortcutConfig.Item>();
  257. private Dictionary<string, VRFaceShortcutConfig.Item> m_ItemDic = new Dictionary<string, VRFaceShortcutConfig.Item>();
  258. private bool m_IsUpdateReposition;
  259. public abstract class Item : MonoBehaviour
  260. {
  261. public UILabel label
  262. {
  263. get
  264. {
  265. return this.m_Label;
  266. }
  267. set
  268. {
  269. this.m_Label = value;
  270. }
  271. }
  272. protected virtual void Awake()
  273. {
  274. this.m_Label = VRFaceShortcutConfig.GetChildObject<UILabel>(base.gameObject, "name");
  275. }
  276. public abstract void Set(object value);
  277. private UILabel m_Label;
  278. }
  279. public class ItemSlider : VRFaceShortcutConfig.Item
  280. {
  281. public UISlider slider
  282. {
  283. get
  284. {
  285. return this.m_Slider;
  286. }
  287. private set
  288. {
  289. this.m_Slider = value;
  290. }
  291. }
  292. public float normalizedValue
  293. {
  294. get
  295. {
  296. return this.slider.value;
  297. }
  298. set
  299. {
  300. this.slider.value = value;
  301. }
  302. }
  303. public float min
  304. {
  305. get
  306. {
  307. return this.m_Min;
  308. }
  309. set
  310. {
  311. this.m_Min = value;
  312. }
  313. }
  314. public float max
  315. {
  316. get
  317. {
  318. return this.m_Max;
  319. }
  320. set
  321. {
  322. this.m_Max = value;
  323. }
  324. }
  325. public float value
  326. {
  327. get
  328. {
  329. return Mathf.Lerp(this.min, this.max, this.normalizedValue);
  330. }
  331. set
  332. {
  333. this.normalizedValue = Mathf.InverseLerp(this.min, this.max, value);
  334. }
  335. }
  336. public Action<float> onValueChanged { get; set; }
  337. public Action onDragFinished { get; set; }
  338. protected override void Awake()
  339. {
  340. base.Awake();
  341. this.slider = VRFaceShortcutConfig.GetChildObject<UISlider>(base.gameObject, "slider");
  342. EventDelegate.Add(this.slider.onChange, delegate()
  343. {
  344. if (this.onValueChanged != null)
  345. {
  346. this.onValueChanged(this.value);
  347. }
  348. });
  349. UISlider slider = this.slider;
  350. slider.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(slider.onDragFinished, new UIProgressBar.OnDragFinished(delegate()
  351. {
  352. if (this.onDragFinished != null)
  353. {
  354. this.onDragFinished();
  355. }
  356. }));
  357. }
  358. public override void Set(object value)
  359. {
  360. this.value = (float)value;
  361. }
  362. private UISlider m_Slider;
  363. private float m_Min;
  364. private float m_Max = 1f;
  365. }
  366. public class ItemSelectButton : VRFaceShortcutConfig.Item
  367. {
  368. public UIButton buttonRight
  369. {
  370. get
  371. {
  372. return this.m_ButtonRight;
  373. }
  374. private set
  375. {
  376. this.m_ButtonRight = value;
  377. }
  378. }
  379. public UIButton buttonLeft
  380. {
  381. get
  382. {
  383. return this.m_ButtonLeft;
  384. }
  385. private set
  386. {
  387. this.m_ButtonLeft = value;
  388. }
  389. }
  390. public UILabel textRight
  391. {
  392. get
  393. {
  394. return this.m_TextRight;
  395. }
  396. private set
  397. {
  398. this.m_TextRight = value;
  399. }
  400. }
  401. public UILabel textLeft
  402. {
  403. get
  404. {
  405. return this.m_TextLeft;
  406. }
  407. private set
  408. {
  409. this.m_TextLeft = value;
  410. }
  411. }
  412. public Action<bool> onClickIsLeft { get; set; }
  413. protected override void Awake()
  414. {
  415. base.Awake();
  416. this.buttonRight = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button right");
  417. this.buttonLeft = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button left");
  418. this.textRight = this.buttonRight.GetComponentInChildren<UILabel>();
  419. this.textLeft = this.buttonLeft.GetComponentInChildren<UILabel>();
  420. EventDelegate.Add(this.buttonRight.onClick, delegate()
  421. {
  422. if (this.onClickIsLeft != null)
  423. {
  424. this.onClickIsLeft(false);
  425. }
  426. this.OnClickButton(false);
  427. });
  428. EventDelegate.Add(this.buttonLeft.onClick, delegate()
  429. {
  430. if (this.onClickIsLeft != null)
  431. {
  432. this.onClickIsLeft(true);
  433. }
  434. this.OnClickButton(true);
  435. });
  436. }
  437. private void OnClickButton(bool isLeft)
  438. {
  439. this.buttonLeft.defaultColor = ((!isLeft) ? VRFaceShortcutConfig.ItemSelectButton.ButtonDefaultColor : VRFaceShortcutConfig.ItemSelectButton.ButtonClickedColor);
  440. this.buttonRight.defaultColor = (isLeft ? VRFaceShortcutConfig.ItemSelectButton.ButtonDefaultColor : VRFaceShortcutConfig.ItemSelectButton.ButtonClickedColor);
  441. }
  442. public void Emulate(bool isLeft)
  443. {
  444. UIButton uibutton = (!isLeft) ? this.buttonRight : this.buttonLeft;
  445. EventDelegate.Execute(uibutton.onClick);
  446. }
  447. public override void Set(object value)
  448. {
  449. this.Emulate((bool)value);
  450. }
  451. private static Color ButtonDefaultColor = new Color(1f, 1f, 1f, 0.5f);
  452. private static Color ButtonClickedColor = Color.white;
  453. private UIButton m_ButtonRight;
  454. private UIButton m_ButtonLeft;
  455. private UILabel m_TextRight;
  456. private UILabel m_TextLeft;
  457. }
  458. private class ParentMultiButton : VRFaceShortcutConfig.Item
  459. {
  460. public UIButton buttonRight
  461. {
  462. get
  463. {
  464. return this.m_ButtonRight;
  465. }
  466. private set
  467. {
  468. this.m_ButtonRight = value;
  469. }
  470. }
  471. public UIButton buttonLeft
  472. {
  473. get
  474. {
  475. return this.m_ButtonLeft;
  476. }
  477. private set
  478. {
  479. this.m_ButtonLeft = value;
  480. }
  481. }
  482. public UIButton buttonCenter
  483. {
  484. get
  485. {
  486. return this.m_ButtonCenter;
  487. }
  488. private set
  489. {
  490. this.m_ButtonCenter = value;
  491. }
  492. }
  493. public UILabel textRight
  494. {
  495. get
  496. {
  497. return this.m_TextRight;
  498. }
  499. private set
  500. {
  501. this.m_TextRight = value;
  502. }
  503. }
  504. public UILabel textLeft
  505. {
  506. get
  507. {
  508. return this.m_TextLeft;
  509. }
  510. private set
  511. {
  512. this.m_TextLeft = value;
  513. }
  514. }
  515. public UILabel textCenter
  516. {
  517. get
  518. {
  519. return this.m_TextCenter;
  520. }
  521. private set
  522. {
  523. this.m_TextCenter = value;
  524. }
  525. }
  526. public Action<int> onClick { get; set; }
  527. protected override void Awake()
  528. {
  529. base.Awake();
  530. this.buttonRight = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button right");
  531. this.buttonLeft = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button left");
  532. this.buttonCenter = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button center");
  533. this.textRight = this.buttonRight.GetComponentInChildren<UILabel>();
  534. this.textLeft = this.buttonLeft.GetComponentInChildren<UILabel>();
  535. this.textCenter = this.buttonCenter.GetComponentInChildren<UILabel>();
  536. EventDelegate.Add(this.buttonRight.onClick, delegate()
  537. {
  538. if (this.onClick != null)
  539. {
  540. this.onClick(0);
  541. }
  542. this.OnClickButton(0);
  543. });
  544. EventDelegate.Add(this.buttonLeft.onClick, delegate()
  545. {
  546. if (this.onClick != null)
  547. {
  548. this.onClick(1);
  549. }
  550. this.OnClickButton(1);
  551. });
  552. EventDelegate.Add(this.buttonCenter.onClick, delegate()
  553. {
  554. if (this.onClick != null)
  555. {
  556. this.onClick(2);
  557. }
  558. this.OnClickButton(2);
  559. });
  560. }
  561. private void OnClickButton(int index)
  562. {
  563. this.buttonRight.defaultColor = ((index != 0) ? VRFaceShortcutConfig.ParentMultiButton.ButtonDefaultColor : VRFaceShortcutConfig.ParentMultiButton.ButtonClickedColor);
  564. this.buttonLeft.defaultColor = ((index != 1) ? VRFaceShortcutConfig.ParentMultiButton.ButtonDefaultColor : VRFaceShortcutConfig.ParentMultiButton.ButtonClickedColor);
  565. this.buttonCenter.defaultColor = ((index != 2) ? VRFaceShortcutConfig.ParentMultiButton.ButtonDefaultColor : VRFaceShortcutConfig.ParentMultiButton.ButtonClickedColor);
  566. }
  567. public void Emulate(int index)
  568. {
  569. UIButton uibutton;
  570. if (index == 0)
  571. {
  572. uibutton = this.buttonRight;
  573. }
  574. else if (index == 1)
  575. {
  576. uibutton = this.buttonLeft;
  577. }
  578. else
  579. {
  580. uibutton = this.buttonCenter;
  581. }
  582. EventDelegate.Execute(uibutton.onClick);
  583. }
  584. public override void Set(object value)
  585. {
  586. this.Emulate((int)value);
  587. }
  588. private static Color ButtonDefaultColor = new Color(1f, 1f, 1f, 0.5f);
  589. private static Color ButtonClickedColor = Color.white;
  590. private UIButton m_ButtonRight;
  591. private UIButton m_ButtonLeft;
  592. private UIButton m_ButtonCenter;
  593. private UILabel m_TextRight;
  594. private UILabel m_TextLeft;
  595. private UILabel m_TextCenter;
  596. }
  597. }