ControllerShortcutWindow.cs 16 KB

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