VREventTriggerGrab.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using UnityEngine;
  3. public class VREventTriggerGrab : VREventTrigger
  4. {
  5. public Rigidbody rigidBody
  6. {
  7. get
  8. {
  9. return (!this.m_bNoMove) ? this.m_rigidBody : null;
  10. }
  11. }
  12. protected override void Start()
  13. {
  14. this.m_rigidBody = base.GetComponent<Rigidbody>();
  15. if (this.m_rigidBody == null)
  16. {
  17. this.m_rigidBody = base.gameObject.AddComponent<Rigidbody>();
  18. }
  19. this.m_rigidBody.isKinematic = true;
  20. this.m_rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
  21. this.m_backuplocalPos = base.transform.localPosition;
  22. this.m_backupRotation = base.transform.rotation;
  23. }
  24. private void OnDestroy()
  25. {
  26. if (this.m_dgDestroy != null)
  27. {
  28. this.m_dgDestroy(null, Vector3.zero, Vector3.zero);
  29. }
  30. }
  31. public override void StartScript()
  32. {
  33. this.m_fResetTime = -1f;
  34. base.StartScript();
  35. if (this.m_bEnable && this.m_onFireResetObjects != null && this.m_onFireResetObjects.Length > 0)
  36. {
  37. foreach (VREventTriggerGrab vreventTriggerGrab in this.m_onFireResetObjects)
  38. {
  39. vreventTriggerGrab.ResetRigid();
  40. }
  41. }
  42. }
  43. public void ResetRigid()
  44. {
  45. if (this.rigidBody == null || this.m_rigidBody.isKinematic)
  46. {
  47. return;
  48. }
  49. Rigidbody rigidBody = this.m_rigidBody;
  50. Vector3 zero = Vector3.zero;
  51. this.m_rigidBody.angularVelocity = zero;
  52. rigidBody.velocity = zero;
  53. this.m_rigidBody.isKinematic = true;
  54. base.transform.localPosition = this.m_backuplocalPos;
  55. base.transform.rotation = this.m_backupRotation;
  56. this.m_fResetTime = -1f;
  57. }
  58. public override void OnEvnetCountDownEnter(GameObject f_goSrc)
  59. {
  60. }
  61. public override void OnEventCountDownExit(GameObject f_goSrc)
  62. {
  63. }
  64. private void Update()
  65. {
  66. if (this.m_rigidBody.isKinematic)
  67. {
  68. return;
  69. }
  70. Vector3 position = base.transform.position;
  71. if ((double)position.y <= -2.5)
  72. {
  73. this.ResetRigid();
  74. }
  75. else if (2.5f <= position.y)
  76. {
  77. if (this.m_fResetTime == -1f)
  78. {
  79. this.m_fResetTime = Time.time;
  80. }
  81. else if (this.m_fResetTime + 5f <= Time.time)
  82. {
  83. this.ResetRigid();
  84. }
  85. }
  86. else
  87. {
  88. this.m_fResetTime = -1f;
  89. }
  90. }
  91. public bool m_bNoMove;
  92. [SerializeField]
  93. [Tooltip("イベント発行時,物理関係がリセットされるオブジェクトリスト")]
  94. public VREventTriggerGrab[] m_onFireResetObjects;
  95. public VREventTriggerGrab.dgDestroy m_dgDestroy;
  96. private Rigidbody m_rigidBody;
  97. private Vector3 m_backuplocalPos;
  98. private Quaternion m_backupRotation;
  99. private float m_fResetTime = -1f;
  100. public delegate void dgDestroy(GameObject gripObject, Vector3 linearVelocity, Vector3 angularVelocity);
  101. }