ControllerShortcutWindow.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. using System;
  2. using System.Collections;
  3. using Kasizuki;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. public class ControllerShortcutWindow : MonoBehaviour
  7. {
  8. public float fadeSpeed
  9. {
  10. get
  11. {
  12. return this.m_FadeSpeed;
  13. }
  14. set
  15. {
  16. this.m_FadeSpeed = Mathf.Clamp(value, 0.001f, 1f);
  17. }
  18. }
  19. private bool IsEnableTypeVR()
  20. {
  21. GameMain instance = GameMain.Instance;
  22. if (!instance.VRMode)
  23. {
  24. return false;
  25. }
  26. GameMain.VRFamilyType vrfamily = instance.VRFamily;
  27. return vrfamily != GameMain.VRFamilyType.FOVE;
  28. }
  29. private void Awake()
  30. {
  31. if (!this.IsEnableTypeVR())
  32. {
  33. Debug.Log("[ControllerShortcutWindow] ハンドコントローラが存在しない操作系だったので、UIを無効化します。");
  34. base.gameObject.SetActive(false);
  35. }
  36. this.m_ButtonDic = new ObjectCacheDic();
  37. }
  38. public void Init(PhotoFaceDataShortcutParent rightHandUI, PhotoFaceDataShortcutParent leftHandUI)
  39. {
  40. PhotoFaceDataShortcutSetter component = this.m_FadeWindowFaceShortcut.GetComponent<PhotoFaceDataShortcutSetter>();
  41. component.Init(rightHandUI.handUI, leftHandUI.handUI);
  42. }
  43. private void Start()
  44. {
  45. UIWFTabButton uiwftabButton = this.m_ButtonDic.CacheChildObject<UIWFTabButton>(this.m_ParentButtonMainMenu.gameObject, "button config", "コンフィグ");
  46. UIWFTabButton uiwftabButton2 = this.m_ButtonDic.CacheChildObject<UIWFTabButton>(this.m_ParentButtonMainMenu.gameObject, "button calibration", "キャリブレーション");
  47. UIWFTabButton uiwftabButton3 = this.m_ButtonDic.CacheChildObject<UIWFTabButton>(this.m_ParentButtonMainMenu.gameObject, "button face", "表情");
  48. UIWFTabButton uiwftabButton4 = this.m_ButtonDic.CacheChildObject<UIWFTabButton>(this.m_ParentButtonMainMenu.gameObject, "button hand", "ハンドサイン");
  49. UIWFTabButton uiwftabButton5 = this.m_ButtonDic.CacheChildObject<UIWFTabButton>(this.m_ParentButtonMainMenu.gameObject, "button motion", "モーション");
  50. UIWFTabButton uiwftabButton6 = this.m_ButtonDic.CacheChildObject<UIWFTabButton>(this.m_ParentButtonMainMenu.gameObject, "button general object", "一般オブジェクト");
  51. uiwftabButton5.gameObject.SetActive(false);
  52. uiwftabButton4.gameObject.SetActive(false);
  53. Debug.Log("メインメニューのうち、モーション登録ボタンを隠します。");
  54. this.m_ParentButtonMainMenu.GetComponent<UIGrid>().Reposition();
  55. EventDelegate.Add(uiwftabButton.onClick, new EventDelegate.Callback(this.OpenWindowConfig));
  56. EventDelegate.Add(uiwftabButton2.onClick, new EventDelegate.Callback(this.OpenWindowCalibration));
  57. EventDelegate.Add(uiwftabButton3.onClick, new EventDelegate.Callback(this.OpenWindowFaceShortcut));
  58. EventDelegate.Add(uiwftabButton4.onClick, new EventDelegate.Callback(this.OpenWindowHandShortcut));
  59. EventDelegate.Add(uiwftabButton5.onClick, new EventDelegate.Callback(this.OpenWindowMotionShortcut));
  60. EventDelegate.Add(uiwftabButton6.onClick, new EventDelegate.Callback(this.OpenWindowGeneralObject));
  61. this.m_FadeWindowHideButton = UTY.GetChildObject(this.m_FadeWindowParent.gameObject, "parent button/Button Hide", false).GetComponent<UIButton>();
  62. EventDelegate.Add(this.m_FadeWindowHideButton.onClick, delegate()
  63. {
  64. this.m_FadeWindowParent.Close(0.25f, null);
  65. });
  66. this.SetupCaribWindow();
  67. this.m_ParentButtonMainMenu.Select(uiwftabButton2);
  68. uiwftabButton2.SetSelect(true);
  69. NGUIWindow fadeWindowParent = this.m_FadeWindowParent;
  70. fadeWindowParent.OnOpen = (Action)Delegate.Combine(fadeWindowParent.OnOpen, new Action(this.OnOpenFadeWindowParent));
  71. this.ChangeLayout();
  72. SceneManager.activeSceneChanged += this.OnActiveSceneChanged;
  73. }
  74. private void SetupCaribWindow()
  75. {
  76. this.m_FadeWindowCalibration.CacheChildObject<NGUIWindow>("Window Start", "FadeWindow Start");
  77. this.m_FadeWindowCalibration.CacheChildObject<NGUIWindow>("Window Countdown", "FadeWindow Countdown");
  78. this.m_FadeWindowCalibration.CacheChildObject<UILabel>("Window Countdown/label countdown", "countdown");
  79. this.m_FadeWindowCalibration.CacheChildObject<UILabel>("Window Countdown/label description", "label count desc");
  80. this.m_FadeWindowCalibration.CacheChildObject<UILabel>("Window Start/label", "label start desc");
  81. UIButton uibutton = this.m_FadeWindowCalibration.CacheChildObject<UIButton>("Window Start/button start", "startButton");
  82. UIButton uibutton2 = this.m_FadeWindowCalibration.CacheChildObject<UIButton>("Window Start/button end", "endButton");
  83. NGUIWindow fadeWindowCalibration = this.m_FadeWindowCalibration;
  84. fadeWindowCalibration.OnOpen = (Action)Delegate.Combine(fadeWindowCalibration.OnOpen, new Action(delegate()
  85. {
  86. NGUIWindow cache = this.m_FadeWindowCalibration.GetCache<NGUIWindow>("FadeWindow Start");
  87. NGUIWindow cache2 = this.m_FadeWindowCalibration.GetCache<NGUIWindow>("FadeWindow Countdown");
  88. cache.Open(0.001f, null);
  89. cache2.Close(0.001f, null);
  90. cache.gameObject.SetActive(true);
  91. cache2.gameObject.SetActive(false);
  92. this.ChangeLayout();
  93. }));
  94. EventDelegate.Add(uibutton.onClick, new EventDelegate.Callback(this.OnClickCalibrationStart));
  95. EventDelegate.Add(uibutton2.onClick, new EventDelegate.Callback(this.OnClickCalibrationEnd));
  96. this.m_FadeWindowCalibration.GetCache<UILabel>("label count desc").text = ControllerShortcutWindow.STR_LABEL_DESC_COUNT_DOWN;
  97. this.m_FadeWindowCalibration.GetCache<UILabel>("label start desc").supportEncoding = true;
  98. }
  99. private void OnOpenFadeWindowParent()
  100. {
  101. this.ChangeLayout();
  102. }
  103. private void ChangeLayout()
  104. {
  105. UILabel cache = this.m_FadeWindowCalibration.GetCache<UILabel>("label start desc");
  106. UIButton cache2 = this.m_FadeWindowCalibration.GetCache<UIButton>("startButton");
  107. UIButton cache3 = this.m_FadeWindowCalibration.GetCache<UIButton>("endButton");
  108. UIWFTabButton cache4 = this.m_ButtonDic.GetCache<UIWFTabButton>("表情");
  109. UIWFTabButton cache5 = this.m_ButtonDic.GetCache<UIWFTabButton>("モーション");
  110. UIWFTabButton cache6 = this.m_ButtonDic.GetCache<UIWFTabButton>("ハンドサイン");
  111. UIWFTabButton cache7 = this.m_ButtonDic.GetCache<UIWFTabButton>("一般オブジェクト");
  112. if (!OvrIK.IsVRIKMode)
  113. {
  114. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  115. if (maid == null || !maid.Visible || maid.IsBusy || !maid.body0.isLoadedBody)
  116. {
  117. cache.text = ControllerShortcutWindow.STR_LABEL_DESC_MISSING_MAID;
  118. cache2.gameObject.SetActive(false);
  119. cache3.gameObject.SetActive(false);
  120. Debug.Log("OvrIK\u3000メイドの準備がまだ行われていません。");
  121. }
  122. else
  123. {
  124. bool flag = false;
  125. try
  126. {
  127. string nowSceneName = GameMain.Instance.GetNowSceneName();
  128. if (!string.IsNullOrEmpty(nowSceneName) && nowSceneName.IndexOf("SceneDance_") == 0)
  129. {
  130. DanceMain danceMain = UnityEngine.Object.FindObjectOfType<DanceMain>();
  131. if (danceMain != null && danceMain.OvrCamTrans != null)
  132. {
  133. flag = true;
  134. }
  135. }
  136. }
  137. catch
  138. {
  139. Debug.Log("シーン名の取得に失敗しました");
  140. }
  141. if (!GameMain.Instance.CMSystem.SConfig.OvrIkAllSceneEnable && flag)
  142. {
  143. cache.text = ControllerShortcutWindow.STR_LABEL_DESC_NOT_SUPPORT_MOVE_CAMERA;
  144. cache2.gameObject.SetActive(false);
  145. cache3.gameObject.SetActive(false);
  146. }
  147. else
  148. {
  149. cache.text = ControllerShortcutWindow.STR_LABEL_DESC_START;
  150. cache2.gameObject.SetActive(true);
  151. cache3.gameObject.SetActive(false);
  152. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.VIVE && ControllerShortcutSettingData.config.use1TrackerForHead)
  153. {
  154. UILabel uilabel = cache;
  155. uilabel.text = uilabel.text + "\n" + ControllerShortcutWindow.STR_LABEL_DESC_START_NOTES_TRACKER;
  156. }
  157. }
  158. }
  159. cache4.isEnabled = false;
  160. cache5.isEnabled = false;
  161. cache6.isEnabled = false;
  162. cache7.isEnabled = false;
  163. }
  164. else
  165. {
  166. cache.text = ControllerShortcutWindow.STR_LABEL_DESC_END;
  167. cache2.gameObject.SetActive(false);
  168. cache3.gameObject.SetActive(true);
  169. cache4.isEnabled = true;
  170. cache5.isEnabled = true;
  171. cache6.isEnabled = true;
  172. cache7.isEnabled = true;
  173. }
  174. }
  175. private void OpenWindowConfig()
  176. {
  177. this.m_FadeWindowCalibration.Close(this.fadeSpeed, null);
  178. this.m_FadeWindowFaceShortcut.Close(this.fadeSpeed, null);
  179. this.m_FadeWindowMotionShortcut.Close(this.fadeSpeed, null);
  180. this.m_FadeWindowGeneralObject.Close(this.fadeSpeed, null);
  181. this.WaitTime(this.fadeSpeed, delegate
  182. {
  183. this.m_FadeWindowConfig.Open(this.fadeSpeed, null);
  184. });
  185. }
  186. private void OpenWindowCalibration()
  187. {
  188. this.m_FadeWindowFaceShortcut.Close(this.fadeSpeed, null);
  189. this.m_FadeWindowMotionShortcut.Close(this.fadeSpeed, null);
  190. this.m_FadeWindowConfig.Close(this.fadeSpeed, null);
  191. this.m_FadeWindowGeneralObject.Close(this.fadeSpeed, null);
  192. this.WaitTime(this.fadeSpeed, delegate
  193. {
  194. this.m_FadeWindowCalibration.Open(this.fadeSpeed, null);
  195. });
  196. }
  197. private void OpenWindowFaceShortcut()
  198. {
  199. this.m_FadeWindowCalibration.Close(this.fadeSpeed, null);
  200. this.m_FadeWindowMotionShortcut.Close(this.fadeSpeed, null);
  201. this.m_FadeWindowConfig.Close(this.fadeSpeed, null);
  202. this.m_FadeWindowGeneralObject.Close(this.fadeSpeed, null);
  203. this.WaitTime(this.fadeSpeed, delegate
  204. {
  205. this.m_FadeWindowFaceShortcut.Open(this.fadeSpeed, null);
  206. });
  207. }
  208. private void OpenWindowHandShortcut()
  209. {
  210. }
  211. private void OpenWindowMotionShortcut()
  212. {
  213. this.m_FadeWindowCalibration.Close(this.fadeSpeed, null);
  214. this.m_FadeWindowFaceShortcut.Close(this.fadeSpeed, null);
  215. this.m_FadeWindowConfig.Close(this.fadeSpeed, null);
  216. this.m_FadeWindowGeneralObject.Close(this.fadeSpeed, null);
  217. this.WaitTime(this.fadeSpeed, delegate
  218. {
  219. this.m_FadeWindowMotionShortcut.Open(this.fadeSpeed, null);
  220. });
  221. }
  222. private void OpenWindowGeneralObject()
  223. {
  224. this.m_FadeWindowCalibration.Close(this.fadeSpeed, null);
  225. this.m_FadeWindowFaceShortcut.Close(this.fadeSpeed, null);
  226. this.m_FadeWindowConfig.Close(this.fadeSpeed, null);
  227. this.m_FadeWindowMotionShortcut.Close(this.fadeSpeed, null);
  228. this.WaitTime(this.fadeSpeed, delegate
  229. {
  230. this.m_FadeWindowGeneralObject.Open(this.fadeSpeed, null);
  231. });
  232. }
  233. private void OnClickCalibrationStart()
  234. {
  235. NGUIWindow cache = this.m_FadeWindowCalibration.GetCache<NGUIWindow>("FadeWindow Start");
  236. NGUIWindow windowCount = this.m_FadeWindowCalibration.GetCache<NGUIWindow>("FadeWindow Countdown");
  237. this.m_FadeWindowCalibration.GetCache<UILabel>("countdown").text = 5.ToString("f2");
  238. cache.Close(this.fadeSpeed, null);
  239. this.m_FadeWindowMainMenu.Close(this.fadeSpeed, null);
  240. this.WaitTime(this.fadeSpeed, delegate
  241. {
  242. windowCount.Open(this.fadeSpeed, null);
  243. });
  244. this.WaitTime(this.fadeSpeed + 1f, delegate
  245. {
  246. if (!OvrIK.IsVRIKMode)
  247. {
  248. OvrIK.InitStart();
  249. }
  250. this.StartCoroutine(this.CoCalibrationCountdown(delegate
  251. {
  252. this.m_FadeWindowCalibration.GetCache<NGUIWindow>("FadeWindow Countdown").Close(this.fadeSpeed, null);
  253. this.WaitTime(this.fadeSpeed, delegate
  254. {
  255. this.m_FadeWindowCalibration.GetCache<NGUIWindow>("FadeWindow Start").Open(this.fadeSpeed, null);
  256. this.m_FadeWindowMainMenu.Open(this.fadeSpeed, null);
  257. this.ChangeLayout();
  258. });
  259. }));
  260. });
  261. }
  262. private void OnClickCalibrationEnd()
  263. {
  264. this.m_FadeWindowParent.Close(this.fadeSpeed, delegate
  265. {
  266. if (OvrIK.IsVRIKMode)
  267. {
  268. OvrIK.UninitEnd();
  269. }
  270. });
  271. }
  272. private IEnumerator CoCalibrationCountdown(Action onEnd)
  273. {
  274. Debug.Log("キャリブレーション開始");
  275. float nowTime = 0f;
  276. float maxTime = 5f;
  277. UILabel textCountdown = this.m_FadeWindowCalibration.GetCache<UILabel>("countdown");
  278. while (nowTime <= maxTime)
  279. {
  280. textCountdown.text = (maxTime - nowTime).ToString("f2");
  281. nowTime += Time.deltaTime;
  282. yield return null;
  283. }
  284. textCountdown.text = 0.ToString("f2");
  285. if (onEnd != null)
  286. {
  287. onEnd();
  288. }
  289. Debug.Log("キャリブレーション完了");
  290. yield break;
  291. }
  292. private void WaitTime(float time, Action onFinish)
  293. {
  294. base.StartCoroutine(this.CoWaitTime(time, onFinish));
  295. }
  296. private IEnumerator CoWaitTime(float time, Action onFinish)
  297. {
  298. yield return new WaitForSeconds(time);
  299. if (onFinish != null)
  300. {
  301. onFinish();
  302. }
  303. yield break;
  304. }
  305. public void Open()
  306. {
  307. this.m_FadeWindowParent.Open(this.fadeSpeed, null);
  308. }
  309. public void Close()
  310. {
  311. this.m_FadeWindowParent.Close(this.fadeSpeed, null);
  312. }
  313. public bool isOpen
  314. {
  315. get
  316. {
  317. return this.m_FadeWindowParent.gameObject.activeSelf;
  318. }
  319. }
  320. private void OnActiveSceneChanged(Scene beforeScene, Scene activeScene)
  321. {
  322. if (this.m_IsDestroyed)
  323. {
  324. return;
  325. }
  326. UnityEngine.Object.Destroy(base.gameObject);
  327. Debug.Log("VRIK用UIを削除しました : シーン切り替え");
  328. }
  329. private void OnDestroy()
  330. {
  331. this.m_IsDestroyed = true;
  332. }
  333. [SerializeField]
  334. [Range(0.001f, 1f)]
  335. private float m_FadeSpeed = 0.25f;
  336. [SerializeField]
  337. private NGUIWindow m_FadeWindowFaceShortcut;
  338. [SerializeField]
  339. private NGUIWindow m_FadeWindowMotionShortcut;
  340. [SerializeField]
  341. private NGUIWindow m_FadeWindowCalibration;
  342. [SerializeField]
  343. private NGUIWindow m_FadeWindowConfig;
  344. [SerializeField]
  345. private NGUIWindow m_FadeWindowGeneralObject;
  346. [SerializeField]
  347. private NGUIWindow m_FadeWindowMainMenu;
  348. [SerializeField]
  349. private NGUIWindow m_FadeWindowParent;
  350. private UIButton m_FadeWindowHideButton;
  351. [SerializeField]
  352. private UIWFTabPanel m_ParentButtonMainMenu;
  353. private ObjectCacheDic m_ButtonDic;
  354. private static readonly string STR_LABEL_DESC_MISSING_MAID = "メイドの準備ができていません。";
  355. private static readonly string STR_LABEL_DESC_NOT_SUPPORT_MOVE_CAMERA = "移動カメラモードでは実行できません。";
  356. private static readonly string STR_LABEL_DESC_START = "「スタート」ボタンを押して、キャリブレーションを開始します。\r\n\r\nキャリブレーション中は、\r\nHDMを装着して、正面を向いて足を肩幅に開いて直立し、\r\nコントローラを持った手を肩幅で胸の前に出してお待ち下さい。";
  357. private static readonly string STR_LABEL_DESC_START_NOTES_TRACKER = "[FF8000]HMDを顔に装着した状態で、\r\n頭のトラッカーを装着予定位置に固定して下さい。[-]";
  358. private static readonly string STR_LABEL_DESC_COUNT_DOWN = "手を前に出し、\r\n足を肩幅に広げ、\r\n正面を向いて、\r\n背筋を伸ばして下さい。\r\n";
  359. private static readonly string STR_LABEL_DESC_END = "バーチャルアバタースタジオ機能を終了します。\r\n\r\n(終了後にキャラクターに不具合がある場合は\r\n\u3000シーンに入り直して下さい。)";
  360. private bool m_IsDestroyed;
  361. }