VRDecideMiniGameHand.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using UnityEngine.UI;
  5. public class VRDecideMiniGameHand : MonoBehaviour
  6. {
  7. public static VRDecideMiniGameHand Create(Vector3 WorldPos, Quaternion Qt)
  8. {
  9. if (VRDecideMiniGameHand.m_Instance != null)
  10. {
  11. VRDecideMiniGameHand.m_Instance.transform.position = WorldPos;
  12. VRDecideMiniGameHand.m_Instance.transform.rotation = Qt;
  13. return VRDecideMiniGameHand.m_Instance;
  14. }
  15. VRDecideMiniGameHand vrdecideMiniGameHand = UnityEngine.Object.FindObjectOfType<VRDecideMiniGameHand>();
  16. if (!vrdecideMiniGameHand)
  17. {
  18. string path = "SceneVRCommunication/Tablet/MiniGameDecideHand";
  19. UnityEngine.Object original = Resources.Load(path);
  20. GameObject gameObject = UnityEngine.Object.Instantiate(original, WorldPos, Qt) as GameObject;
  21. vrdecideMiniGameHand = gameObject.GetComponent<VRDecideMiniGameHand>();
  22. }
  23. else
  24. {
  25. GameObject gameObject = vrdecideMiniGameHand.gameObject;
  26. }
  27. return vrdecideMiniGameHand;
  28. }
  29. public Text textCountDown
  30. {
  31. get
  32. {
  33. return this.m_TextCountDown;
  34. }
  35. }
  36. private void Awake()
  37. {
  38. if (VRDecideMiniGameHand.m_Instance != null)
  39. {
  40. UnityEngine.Object.DestroyImmediate(base.gameObject);
  41. return;
  42. }
  43. VRDecideMiniGameHand.m_Instance = this;
  44. }
  45. private void Start()
  46. {
  47. this.m_ControllerR = GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller;
  48. this.m_ControllerL = GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller;
  49. }
  50. private void Update()
  51. {
  52. if (!this.m_IsUpdate)
  53. {
  54. return;
  55. }
  56. if (!this.m_ControllerL || !this.m_ControllerR)
  57. {
  58. this.m_ControllerR = GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller;
  59. this.m_ControllerL = GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller;
  60. if (!this.m_ControllerL || !this.m_ControllerR)
  61. {
  62. return;
  63. }
  64. }
  65. bool press = this.m_ControllerR.VRControllerButtons.GetPress(AVRControllerButtons.BTN.TRIGGER);
  66. bool press2 = this.m_ControllerL.VRControllerButtons.GetPress(AVRControllerButtons.BTN.TRIGGER);
  67. float deltaTime = Time.deltaTime;
  68. if (press && press2)
  69. {
  70. this.m_TotalGrabTime = 0f;
  71. }
  72. else if (press)
  73. {
  74. this.m_TotalGrabTime += deltaTime;
  75. }
  76. else if (press2)
  77. {
  78. this.m_TotalGrabTime += deltaTime;
  79. }
  80. else
  81. {
  82. this.m_TotalGrabTime = 0f;
  83. }
  84. if (press2 != press)
  85. {
  86. this.m_TextCountDown.gameObject.SetActive(true);
  87. this.m_ImageManual.gameObject.SetActive(true);
  88. float num = this.m_MaxGrabTime - this.m_TotalGrabTime;
  89. num += 1f;
  90. this.m_TextCountDown.text = ((int)num).ToString();
  91. }
  92. else
  93. {
  94. this.m_TextCountDown.gameObject.SetActive(false);
  95. this.m_ImageManual.gameObject.SetActive(true);
  96. }
  97. if (this.m_TotalGrabTime > this.m_MaxGrabTime)
  98. {
  99. this.m_IsUpdate = false;
  100. if (press2)
  101. {
  102. this.m_Callback(this.m_ControllerL);
  103. }
  104. else
  105. {
  106. this.m_Callback(this.m_ControllerR);
  107. }
  108. }
  109. }
  110. public void StartDecideHand(UnityAction<AVRController> callback)
  111. {
  112. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.RIFT_TOUCH)
  113. {
  114. this.m_ImageManual.sprite = this.m_SpriteStartOculus;
  115. }
  116. else if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.VIVE)
  117. {
  118. this.m_ImageManual.sprite = this.m_SpriteStartHTC;
  119. }
  120. UICanvasFade component = base.GetComponent<UICanvasFade>();
  121. component.FadeIn();
  122. this.m_IsUpdate = true;
  123. this.m_Callback = null;
  124. this.m_Callback = callback;
  125. }
  126. private static VRDecideMiniGameHand m_Instance;
  127. [SerializeField]
  128. [Tooltip("カウントダウン用テキストUI")]
  129. private Text m_TextCountDown;
  130. [SerializeField]
  131. [Tooltip("説明用イメージUI")]
  132. private Image m_ImageManual;
  133. [SerializeField]
  134. [Tooltip("説明用イメージ(HTC)")]
  135. private Sprite m_SpriteStartHTC;
  136. [SerializeField]
  137. [Tooltip("説明用イメージ(Oculus)")]
  138. private Sprite m_SpriteStartOculus;
  139. private AVRController m_ControllerR;
  140. private AVRController m_ControllerL;
  141. private float m_TotalGrabTime;
  142. private float m_MaxGrabTime = 3f;
  143. private UnityAction<AVRController> m_Callback;
  144. private bool m_IsUpdate;
  145. }