PhotoFaceDataShortcutParent.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using UnityEngine;
  3. public class PhotoFaceDataShortcutParent : MonoBehaviour
  4. {
  5. public PhotoFaceDataShortcut handUI { get; private set; }
  6. private KeyboardShortcutManager keyboardShortcut { get; set; }
  7. public bool isLeftHand { get; private set; }
  8. public bool isEnableHandUI
  9. {
  10. get
  11. {
  12. return this.handUI.gameObject.activeSelf;
  13. }
  14. set
  15. {
  16. if (this.handUI == null || this.handUI.gameObject == null)
  17. {
  18. return;
  19. }
  20. if (this.handUI.gameObject.activeSelf != value)
  21. {
  22. this.handUI.gameObject.SetActive(value);
  23. }
  24. }
  25. }
  26. public bool isEnableKeyboardShortcut
  27. {
  28. get
  29. {
  30. return this.keyboardShortcut.gameObject.activeSelf;
  31. }
  32. set
  33. {
  34. if (this.keyboardShortcut == null || this.keyboardShortcut.gameObject == null)
  35. {
  36. return;
  37. }
  38. if (this.keyboardShortcut.gameObject.activeSelf != value)
  39. {
  40. this.keyboardShortcut.gameObject.SetActive(value);
  41. }
  42. }
  43. }
  44. public void Init(bool isLeftHand)
  45. {
  46. this.isLeftHand = isLeftHand;
  47. this.SetupPhotoFaceDataShortcut();
  48. this.SetupKeyboardShortcutManager();
  49. }
  50. private void SetupPhotoFaceDataShortcut()
  51. {
  52. string text = "OVR/CircleCommandUI/PhotoFaceDataShortcut(Cotroller)";
  53. GameObject gameObject = Resources.Load<GameObject>(text);
  54. if (gameObject == null)
  55. {
  56. NDebug.Assert("[PhotoFaceDataShortcutParent] " + text + "\nプレハブが見つかりません", false);
  57. }
  58. GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject);
  59. this.handUI = gameObject2.GetComponent<PhotoFaceDataShortcut>();
  60. this.handUI.Init(this.isLeftHand);
  61. this.handUI.CreateItemList(8);
  62. Transform transform = gameObject2.transform;
  63. transform.SetParent(base.transform);
  64. transform.localPosition = Vector3.zero;
  65. transform.localRotation = Quaternion.identity;
  66. transform.localScale = Vector3.one;
  67. Vector3 b = new Vector3(0.03f, 0.15f, -0.05f);
  68. Vector3 localEulerAngles = new Vector3(35f, 15f, 0f);
  69. if (this.isLeftHand)
  70. {
  71. b.Scale(new Vector3(-1f, 1f, 1f));
  72. localEulerAngles.Scale(new Vector3(1f, -1f, -1f));
  73. }
  74. transform.localPosition += b;
  75. transform.localEulerAngles = localEulerAngles;
  76. }
  77. private void SetupKeyboardShortcutManager()
  78. {
  79. if (!this.isLeftHand)
  80. {
  81. return;
  82. }
  83. this.keyboardShortcut = new GameObject("Keyboard Shortcut").AddComponent<KeyboardShortcutManager>();
  84. this.keyboardShortcut.transform.SetParent(base.transform, false);
  85. for (int i = 0; i < this.handUI.itemDataList.Count; i++)
  86. {
  87. int index = i;
  88. this.keyboardShortcut.AddKeyData(base.gameObject, KeyCode.Alpha1 + i, delegate
  89. {
  90. this.OnKeyDownShortcut(this.handUI, index);
  91. }, delegate
  92. {
  93. this.OnKeyStayShortcut(this.handUI, index);
  94. }, delegate
  95. {
  96. this.OnKeyUpShortcut(this.handUI, index);
  97. });
  98. }
  99. }
  100. private void OnKeyDownShortcut(PhotoFaceDataShortcut shortcutController, int index)
  101. {
  102. if (ControllerShortcutSettingData.config.isDirectMode)
  103. {
  104. if (shortcutController.itemDataList.Count <= index)
  105. {
  106. return;
  107. }
  108. PhotoFaceDataShortcut.ItemData itemData = shortcutController.itemDataList[index];
  109. if (itemData == null || itemData.data == null)
  110. {
  111. return;
  112. }
  113. shortcutController.Emulate(itemData);
  114. }
  115. }
  116. private void OnKeyStayShortcut(PhotoFaceDataShortcut shortcutController, int index)
  117. {
  118. }
  119. private void OnKeyUpShortcut(PhotoFaceDataShortcut shortcutController, int index)
  120. {
  121. if (!ControllerShortcutSettingData.config.isDirectMode)
  122. {
  123. if (shortcutController.itemDataList.Count <= index)
  124. {
  125. Debug.LogWarning("[表情ショートカット]コントローラのショートカット範囲外のインデックスが指定された。");
  126. return;
  127. }
  128. PhotoFaceDataShortcut.ItemData itemData = shortcutController.itemDataList[index];
  129. if (itemData == null || itemData.data == null)
  130. {
  131. Debug.Log("[表情ショートカット]コントローラのショートカット対応のキーが押されたが、表情データはnullだった。");
  132. return;
  133. }
  134. shortcutController.Emulate(itemData);
  135. }
  136. else
  137. {
  138. foreach (PhotoFaceDataShortcut.ItemData itemData2 in shortcutController.itemDataList)
  139. {
  140. if (!(itemData2 == null) && itemData2.data != null)
  141. {
  142. shortcutController.Emulate(itemData2);
  143. break;
  144. }
  145. }
  146. }
  147. }
  148. private void OnApplicationQuit()
  149. {
  150. this.m_IsQuitting = true;
  151. }
  152. private void OnDestroy()
  153. {
  154. if (this.m_IsQuitting)
  155. {
  156. return;
  157. }
  158. if (this.handUI != null && this.handUI.gameObject != null)
  159. {
  160. UnityEngine.Object.Destroy(this.handUI.gameObject);
  161. Debug.Log("[PhotoFaceDataShortcutParent] コントローラについているUIを破棄しました");
  162. }
  163. if (this.keyboardShortcut != null && this.keyboardShortcut.gameObject != null)
  164. {
  165. UnityEngine.Object.Destroy(this.keyboardShortcut.gameObject);
  166. Debug.Log("[PhotoFaceDataShortcutParent] キーボード入力のショートカット管理クラスを破棄しました");
  167. }
  168. }
  169. private bool m_IsQuitting;
  170. }