VRFaceShortcutConfig.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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.CreateDefaultItems();
  43. this.CreateViveItems();
  44. NGUIWindow fadeWindowThis = this.m_FadeWindowThis;
  45. fadeWindowThis.OnClose = (Action)Delegate.Combine(fadeWindowThis.OnClose, new Action(delegate()
  46. {
  47. ControllerShortcutSettingData.config.Write();
  48. }));
  49. }
  50. private void CreateDefaultItems()
  51. {
  52. OVRLipSync.VariableData variable = GameMain.Instance.LipSyncMgr.Variable;
  53. VRFaceShortcutConfig.ItemSlider itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("リップシンク:マイク感度");
  54. itemSlider.min = 0f;
  55. itemSlider.max = 10f;
  56. itemSlider.Set(variable.MicSensitivity);
  57. itemSlider.onValueChanged = delegate(float value)
  58. {
  59. GameMain.Instance.LipSyncMgr.Variable.MicSensitivity = value;
  60. };
  61. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("リップシンク:自分の声の大きさ");
  62. itemSlider.min = 0f;
  63. itemSlider.max = 10f;
  64. itemSlider.Set(variable.MicVolume);
  65. itemSlider.onValueChanged = delegate(float value)
  66. {
  67. GameMain.Instance.LipSyncMgr.Variable.MicVolume = value;
  68. };
  69. VRFaceShortcutConfig.ItemSelectButton itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("リップシンク:ミュートにする");
  70. itemSelectButton.textLeft.text = "ON";
  71. itemSelectButton.textRight.text = "OFF";
  72. itemSelectButton.Set(variable.Mute);
  73. itemSelectButton.onClickIsLeft = delegate(bool isLeft)
  74. {
  75. variable.Mute = isLeft;
  76. };
  77. itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("手元ショートカット:表情の変化");
  78. itemSelectButton.textLeft.text = "即座に変更する";
  79. itemSelectButton.textRight.text = "選択して決定する";
  80. itemSelectButton.Set(ControllerShortcutSettingData.config.isDirectMode);
  81. itemSelectButton.onClickIsLeft = delegate(bool isLeft)
  82. {
  83. ControllerShortcutSettingData.config.isDirectMode = isLeft;
  84. };
  85. itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("手元ショートカット:手元のUI");
  86. itemSelectButton.textLeft.text = "常に表示する";
  87. itemSelectButton.textRight.text = "決定時に隠す";
  88. itemSelectButton.Set(ControllerShortcutSettingData.config.isEveryShowMode);
  89. itemSelectButton.onClickIsLeft = delegate(bool isLeft)
  90. {
  91. ControllerShortcutSettingData.config.isEveryShowMode = isLeft;
  92. };
  93. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体向きの頭への追従");
  94. itemSlider.min = 0f;
  95. itemSlider.max = 1f;
  96. itemSlider.Set(ControllerShortcutSettingData.config.maintainPelvisPosition);
  97. itemSlider.onValueChanged = delegate(float value)
  98. {
  99. ControllerShortcutSettingData.config.maintainPelvisPosition = value;
  100. };
  101. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体位置の頭への追従");
  102. itemSlider.min = 0f;
  103. itemSlider.max = 1f;
  104. itemSlider.Set(ControllerShortcutSettingData.config.bodyPosStiffness);
  105. itemSlider.onValueChanged = delegate(float value)
  106. {
  107. ControllerShortcutSettingData.config.bodyPosStiffness = value;
  108. };
  109. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("体回転の頭への追従");
  110. itemSlider.min = 0f;
  111. itemSlider.max = 1f;
  112. itemSlider.Set(ControllerShortcutSettingData.config.bodyRotStiffness);
  113. itemSlider.onValueChanged = delegate(float value)
  114. {
  115. ControllerShortcutSettingData.config.bodyRotStiffness = value;
  116. };
  117. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("胸部回転の頭への追従");
  118. itemSlider.min = 0f;
  119. itemSlider.max = 1f;
  120. itemSlider.Set(ControllerShortcutSettingData.config.chestRotationWeight);
  121. itemSlider.onValueChanged = delegate(float value)
  122. {
  123. ControllerShortcutSettingData.config.chestRotationWeight = value;
  124. };
  125. itemSlider = this.CreateItem<VRFaceShortcutConfig.ItemSlider>("カメラの画角");
  126. itemSlider.min = 0f;
  127. itemSlider.max = 1f;
  128. itemSlider.Set(ControllerShortcutSettingData.config.selfCameraFOV);
  129. itemSlider.onValueChanged = delegate(float value)
  130. {
  131. ControllerShortcutSettingData.config.selfCameraFOV = value;
  132. };
  133. }
  134. private void CreateViveItems()
  135. {
  136. if (GameMain.Instance.VRDeviceTypeID != GameMain.VRDeviceType.VIVE)
  137. {
  138. return;
  139. }
  140. VRFaceShortcutConfig.ItemSelectButton itemSelectButton = this.CreateItem<VRFaceShortcutConfig.ItemSelectButton>("一番上にあるトラッカーを\n頭トラッキングに利用");
  141. itemSelectButton.textLeft.text = "ON";
  142. itemSelectButton.textRight.text = "OFF";
  143. itemSelectButton.Set(ControllerShortcutSettingData.config.use1TrackerForHead);
  144. itemSelectButton.onClickIsLeft = delegate(bool isLeft)
  145. {
  146. ControllerShortcutSettingData.config.use1TrackerForHead = isLeft;
  147. this.SetActiveItem("2つめと3つめのトラッカーを\n足トラッキングに利用", isLeft, false);
  148. this.SetActiveItem("1つめと2つめのトラッカーを\n足トラッキングに利用", !isLeft, false);
  149. };
  150. }
  151. private void SetActiveItem(string itemKey, bool isActive, bool isEnableError = true)
  152. {
  153. VRFaceShortcutConfig.Item item;
  154. if (!this.m_ItemDic.TryGetValue(itemKey, out item))
  155. {
  156. if (isEnableError)
  157. {
  158. string message = "[VRFaceShortcutConfig] コンフィグ項目に「" + itemKey + "」は存在しません";
  159. Debug.LogError(message);
  160. NDebug.Assert(message, false);
  161. }
  162. return;
  163. }
  164. if (item.gameObject.activeSelf != isActive)
  165. {
  166. item.gameObject.SetActive(isActive);
  167. this.m_IsUpdateReposition = true;
  168. }
  169. }
  170. private void LateUpdate()
  171. {
  172. if (this.m_IsUpdateReposition)
  173. {
  174. this.m_IsUpdateReposition = false;
  175. this.m_Grid.Reposition();
  176. this.m_ScrollView.UpdatePosition();
  177. }
  178. }
  179. private static T GetChildObject<T>(GameObject gameObject, string path)
  180. {
  181. GameObject childObject = UTY.GetChildObject(gameObject, path, false);
  182. if (childObject == null)
  183. {
  184. string message = string.Concat(new string[]
  185. {
  186. "[VRFaceShortcutConfig] ",
  187. gameObject.name,
  188. "/",
  189. path,
  190. "が見つかりませんでした"
  191. });
  192. NDebug.Assert(message, false);
  193. Debug.LogError(message);
  194. }
  195. T component = childObject.GetComponent<T>();
  196. if (component == null)
  197. {
  198. string message2 = string.Concat(new object[]
  199. {
  200. "[VRFaceShortcutConfig] ",
  201. gameObject.name,
  202. "/",
  203. path,
  204. "に、\n",
  205. typeof(T),
  206. "のコンポーネントがありませんでした"
  207. });
  208. NDebug.Assert(message2, false);
  209. Debug.LogError(message2);
  210. }
  211. return component;
  212. }
  213. [SerializeField]
  214. [Range(0.001f, 1f)]
  215. private float m_FadeSpeed = 0.25f;
  216. [SerializeField]
  217. private NGUIWindow m_FadeWindowThis;
  218. [SerializeField]
  219. private UIScrollView m_ScrollView;
  220. [SerializeField]
  221. private UIGrid m_Grid;
  222. private Dictionary<Type, VRFaceShortcutConfig.Item> m_ItemTemplateList = new Dictionary<Type, VRFaceShortcutConfig.Item>();
  223. private Dictionary<string, VRFaceShortcutConfig.Item> m_ItemDic = new Dictionary<string, VRFaceShortcutConfig.Item>();
  224. private bool m_IsUpdateReposition;
  225. public abstract class Item : MonoBehaviour
  226. {
  227. public UILabel label
  228. {
  229. get
  230. {
  231. return this.m_Label;
  232. }
  233. set
  234. {
  235. this.m_Label = value;
  236. }
  237. }
  238. protected virtual void Awake()
  239. {
  240. this.m_Label = VRFaceShortcutConfig.GetChildObject<UILabel>(base.gameObject, "name");
  241. }
  242. public abstract void Set(object value);
  243. private UILabel m_Label;
  244. }
  245. public class ItemSlider : VRFaceShortcutConfig.Item
  246. {
  247. public UISlider slider
  248. {
  249. get
  250. {
  251. return this.m_Slider;
  252. }
  253. private set
  254. {
  255. this.m_Slider = value;
  256. }
  257. }
  258. public float normalizedValue
  259. {
  260. get
  261. {
  262. return this.slider.value;
  263. }
  264. set
  265. {
  266. this.slider.value = value;
  267. }
  268. }
  269. public float min
  270. {
  271. get
  272. {
  273. return this.m_Min;
  274. }
  275. set
  276. {
  277. this.m_Min = value;
  278. }
  279. }
  280. public float max
  281. {
  282. get
  283. {
  284. return this.m_Max;
  285. }
  286. set
  287. {
  288. this.m_Max = value;
  289. }
  290. }
  291. public float value
  292. {
  293. get
  294. {
  295. return Mathf.Lerp(this.min, this.max, this.normalizedValue);
  296. }
  297. set
  298. {
  299. this.normalizedValue = Mathf.InverseLerp(this.min, this.max, value);
  300. }
  301. }
  302. public Action<float> onValueChanged { get; set; }
  303. public Action onDragFinished { get; set; }
  304. protected override void Awake()
  305. {
  306. base.Awake();
  307. this.slider = VRFaceShortcutConfig.GetChildObject<UISlider>(base.gameObject, "slider");
  308. EventDelegate.Add(this.slider.onChange, delegate()
  309. {
  310. if (this.onValueChanged != null)
  311. {
  312. this.onValueChanged(this.value);
  313. }
  314. });
  315. UISlider slider = this.slider;
  316. slider.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(slider.onDragFinished, new UIProgressBar.OnDragFinished(delegate()
  317. {
  318. if (this.onDragFinished != null)
  319. {
  320. this.onDragFinished();
  321. }
  322. }));
  323. }
  324. public override void Set(object value)
  325. {
  326. this.value = (float)value;
  327. }
  328. private UISlider m_Slider;
  329. private float m_Min;
  330. private float m_Max = 1f;
  331. }
  332. public class ItemSelectButton : VRFaceShortcutConfig.Item
  333. {
  334. public UIButton buttonRight
  335. {
  336. get
  337. {
  338. return this.m_ButtonRight;
  339. }
  340. private set
  341. {
  342. this.m_ButtonRight = value;
  343. }
  344. }
  345. public UIButton buttonLeft
  346. {
  347. get
  348. {
  349. return this.m_ButtonLeft;
  350. }
  351. private set
  352. {
  353. this.m_ButtonLeft = value;
  354. }
  355. }
  356. public UILabel textRight
  357. {
  358. get
  359. {
  360. return this.m_TextRight;
  361. }
  362. private set
  363. {
  364. this.m_TextRight = value;
  365. }
  366. }
  367. public UILabel textLeft
  368. {
  369. get
  370. {
  371. return this.m_TextLeft;
  372. }
  373. private set
  374. {
  375. this.m_TextLeft = value;
  376. }
  377. }
  378. public Action<bool> onClickIsLeft { get; set; }
  379. protected override void Awake()
  380. {
  381. base.Awake();
  382. this.buttonRight = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button right");
  383. this.buttonLeft = VRFaceShortcutConfig.GetChildObject<UIButton>(base.gameObject, "button left");
  384. this.textRight = this.buttonRight.GetComponentInChildren<UILabel>();
  385. this.textLeft = this.buttonLeft.GetComponentInChildren<UILabel>();
  386. EventDelegate.Add(this.buttonRight.onClick, delegate()
  387. {
  388. if (this.onClickIsLeft != null)
  389. {
  390. this.onClickIsLeft(false);
  391. }
  392. this.OnClickButton(false);
  393. });
  394. EventDelegate.Add(this.buttonLeft.onClick, delegate()
  395. {
  396. if (this.onClickIsLeft != null)
  397. {
  398. this.onClickIsLeft(true);
  399. }
  400. this.OnClickButton(true);
  401. });
  402. }
  403. private void OnClickButton(bool isLeft)
  404. {
  405. this.buttonLeft.defaultColor = ((!isLeft) ? VRFaceShortcutConfig.ItemSelectButton.ButtonDefaultColor : VRFaceShortcutConfig.ItemSelectButton.ButtonClickedColor);
  406. this.buttonRight.defaultColor = (isLeft ? VRFaceShortcutConfig.ItemSelectButton.ButtonDefaultColor : VRFaceShortcutConfig.ItemSelectButton.ButtonClickedColor);
  407. }
  408. public void Emulate(bool isLeft)
  409. {
  410. UIButton uibutton = (!isLeft) ? this.buttonRight : this.buttonLeft;
  411. EventDelegate.Execute(uibutton.onClick);
  412. }
  413. public override void Set(object value)
  414. {
  415. this.Emulate((bool)value);
  416. }
  417. private static Color ButtonDefaultColor = new Color(1f, 1f, 1f, 0.5f);
  418. private static Color ButtonClickedColor = Color.white;
  419. private UIButton m_ButtonRight;
  420. private UIButton m_ButtonLeft;
  421. private UILabel m_TextRight;
  422. private UILabel m_TextLeft;
  423. }
  424. }