VREventNotifierGrab.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using UnityEngine;
  3. public class VREventNotifierGrab : VREventNotifier
  4. {
  5. protected override void Start()
  6. {
  7. this.LookTimeCountDownStop();
  8. }
  9. public void Init(OvrMgr.OvrObject.Controller f_ViveController)
  10. {
  11. f_ViveController.grip_collider.on_grab_obj_callback = new OvrGripCollider.OnGrabObject(this.GrabObj);
  12. f_ViveController.grip_collider.on_release_obj_callback = new OvrGripCollider.OnReleaseObject(this.ReleaseObj);
  13. }
  14. private void GrabTimeCountDownStart()
  15. {
  16. this.m_fMaxTime = this.m_HitGrabTarget.GetTimeOutTime();
  17. this.m_fNowTime = this.m_fMaxTime;
  18. this.m_EventText.SetGaugeRate(0f);
  19. this.m_EventText.Show(VREventText.TYPE.GRAB, this.m_HitGrabTarget.GetEventName(), 0f);
  20. }
  21. private void LookTimeCountDownStop()
  22. {
  23. this.m_EventText.Hide(VREventText.TYPE.GRAB);
  24. }
  25. private void GrabTimeOut()
  26. {
  27. Debug.Log("Grab:StartScript");
  28. this.LookTimeCountDownStop();
  29. if (this.m_HitGrabTarget != null)
  30. {
  31. this.m_HitGrabTarget.StartScript();
  32. this.m_HitGrabTarget = null;
  33. }
  34. }
  35. public void GrabObj(GameObject f_goTarget)
  36. {
  37. if (SceneVRCommunication.Instance == null)
  38. {
  39. return;
  40. }
  41. if (f_goTarget == null || VREventNotifier.m_clSingle != null || GameMain.Instance.MainCamera.IsFadeProc() || !SceneVRCommunication.Instance.IsFreeMode)
  42. {
  43. return;
  44. }
  45. this.m_HitGrabTarget = f_goTarget.GetComponent<VREventTriggerGrab>();
  46. if (this.m_HitGrabTarget != null)
  47. {
  48. if (this.m_HitGrabTarget.rigidBody != null)
  49. {
  50. Rigidbody rigidBody = this.m_HitGrabTarget.rigidBody;
  51. Rigidbody rigidbody = rigidBody;
  52. Vector3 zero = Vector3.zero;
  53. rigidBody.angularVelocity = zero;
  54. rigidbody.velocity = zero;
  55. rigidBody.isKinematic = true;
  56. }
  57. if (this.m_HitGrabTarget.IsEnableEvent())
  58. {
  59. this.m_HitGrabTarget.OnEvnetCountDownEnter(base.gameObject);
  60. this.GrabTimeCountDownStart();
  61. VREventNotifier.m_clSingle = this;
  62. this.m_HitGrabTarget.m_dgDestroy = new VREventTriggerGrab.dgDestroy(this.ReleaseObj);
  63. }
  64. else
  65. {
  66. this.m_HitGrabTarget.m_dgDestroy = null;
  67. this.m_HitGrabTarget = null;
  68. }
  69. }
  70. }
  71. public void ReleaseObj(GameObject gripObject, Vector3 linearVelocity, Vector3 angularVelocity)
  72. {
  73. if (gripObject != null)
  74. {
  75. VREventTriggerGrab component = gripObject.GetComponent<VREventTriggerGrab>();
  76. if (component != null && component.rigidBody != null)
  77. {
  78. Rigidbody rigidBody = component.rigidBody;
  79. rigidBody.isKinematic = false;
  80. rigidBody.velocity = linearVelocity;
  81. rigidBody.angularVelocity = angularVelocity;
  82. }
  83. }
  84. if (this.m_HitGrabTarget != null)
  85. {
  86. this.m_HitGrabTarget.m_dgDestroy = null;
  87. this.m_HitGrabTarget.OnEventCountDownExit(base.gameObject);
  88. this.m_HitGrabTarget = null;
  89. }
  90. VREventNotifier.m_clSingle = null;
  91. this.LookTimeCountDownStop();
  92. }
  93. private void Update()
  94. {
  95. if (SceneVRCommunication.Instance == null)
  96. {
  97. return;
  98. }
  99. if (GameMain.Instance.MainCamera.IsFadeOut())
  100. {
  101. this.m_HitBackGrabTarget = false;
  102. if (this.m_HitGrabTarget != null)
  103. {
  104. this.m_HitGrabTarget.m_dgDestroy = null;
  105. this.m_HitGrabTarget = null;
  106. }
  107. this.LookTimeCountDownStop();
  108. return;
  109. }
  110. if (this.m_HitGrabTarget != null)
  111. {
  112. this.m_fNowTime -= Time.deltaTime;
  113. if (this.m_fNowTime <= 0f)
  114. {
  115. this.GrabTimeOut();
  116. this.m_EventText.SetGaugeRate(1f);
  117. }
  118. else
  119. {
  120. this.m_EventText.SetGaugeRate(1f - this.m_fNowTime / this.m_fMaxTime);
  121. }
  122. }
  123. if (this.m_HitBackGrabTarget && this.m_HitGrabTarget == null)
  124. {
  125. this.LookTimeCountDownStop();
  126. }
  127. this.m_HitBackGrabTarget = (this.m_HitGrabTarget != null);
  128. }
  129. public VREventText m_EventText;
  130. private float m_fMaxTime = 5f;
  131. private float m_fNowTime;
  132. private VREventTriggerGrab m_HitGrabTarget;
  133. private bool m_HitBackGrabTarget;
  134. }