using System; using UnityEngine; public class VREventTriggerGrab : VREventTrigger { public Rigidbody rigidBody { get { return (!this.m_bNoMove) ? this.m_rigidBody : null; } } protected override void Start() { this.m_rigidBody = base.GetComponent(); if (this.m_rigidBody == null) { this.m_rigidBody = base.gameObject.AddComponent(); } this.m_rigidBody.isKinematic = true; this.m_rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; this.m_backuplocalPos = base.transform.localPosition; this.m_backupRotation = base.transform.rotation; } private void OnDestroy() { if (this.m_dgDestroy != null) { this.m_dgDestroy(null, Vector3.zero, Vector3.zero); } } public override void StartScript() { this.m_fResetTime = -1f; base.StartScript(); if (this.m_bEnable && this.m_onFireResetObjects != null && this.m_onFireResetObjects.Length > 0) { foreach (VREventTriggerGrab vreventTriggerGrab in this.m_onFireResetObjects) { vreventTriggerGrab.ResetRigid(); } } } public void ResetRigid() { if (this.rigidBody == null || this.m_rigidBody.isKinematic) { return; } Rigidbody rigidBody = this.m_rigidBody; Vector3 zero = Vector3.zero; this.m_rigidBody.angularVelocity = zero; rigidBody.velocity = zero; this.m_rigidBody.isKinematic = true; base.transform.localPosition = this.m_backuplocalPos; base.transform.rotation = this.m_backupRotation; this.m_fResetTime = -1f; } public override void OnEvnetCountDownEnter(GameObject f_goSrc) { } public override void OnEventCountDownExit(GameObject f_goSrc) { } private void Update() { if (this.m_rigidBody.isKinematic) { return; } Vector3 position = base.transform.position; if ((double)position.y <= -2.5) { this.ResetRigid(); } else if (2.5f <= position.y) { if (this.m_fResetTime == -1f) { this.m_fResetTime = Time.time; } else if (this.m_fResetTime + 5f <= Time.time) { this.ResetRigid(); } } else { this.m_fResetTime = -1f; } } public bool m_bNoMove; [SerializeField] [Tooltip("イベント発行時,物理関係がリセットされるオブジェクトリスト")] public VREventTriggerGrab[] m_onFireResetObjects; public VREventTriggerGrab.dgDestroy m_dgDestroy; private Rigidbody m_rigidBody; private Vector3 m_backuplocalPos; private Quaternion m_backupRotation; private float m_fResetTime = -1f; public delegate void dgDestroy(GameObject gripObject, Vector3 linearVelocity, Vector3 angularVelocity); }