using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using VRTK;
|
|
|
|
|
|
public class ResetAfterTime : MonoBehaviour
|
|
{
|
|
|
|
|
|
[SerializeField]
|
|
private float m_resetTime = 20;
|
|
|
|
private VRTK_InteractableObject m_interactable;
|
|
private Vector3 m_startPos;
|
|
private Quaternion m_startRot;
|
|
private Rigidbody m_rb;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
m_interactable = GetComponent<VRTK_InteractableObject>();
|
|
m_rb = GetComponent<Rigidbody>();
|
|
m_startPos = transform.position;
|
|
m_startRot = transform.rotation;
|
|
}
|
|
|
|
|
|
private IEnumerator resetAfterTime(float time)
|
|
{
|
|
yield return new WaitForSeconds(time);
|
|
|
|
transform.position = m_startPos;
|
|
transform.rotation = m_startRot;
|
|
m_rb.velocity = Vector3.zero;
|
|
m_rb.angularVelocity = Vector3.zero;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
RegisterEvents(true);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
RegisterEvents(false);
|
|
}
|
|
|
|
|
|
|
|
private void OnGrab(object sender, InteractableObjectEventArgs args)
|
|
{
|
|
StopAllCoroutines();
|
|
}
|
|
|
|
|
|
private void OnDrop(object sender, InteractableObjectEventArgs args)
|
|
{
|
|
StartCoroutine(resetAfterTime(m_resetTime));
|
|
}
|
|
|
|
|
|
private void OnSnap(object sender, InteractableObjectEventArgs args)
|
|
{
|
|
StopAllCoroutines();
|
|
|
|
}
|
|
|
|
|
|
private void RegisterEvents(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
m_interactable.InteractableObjectSnappedToDropZone += OnSnap;
|
|
m_interactable.InteractableObjectGrabbed += OnGrab;
|
|
m_interactable.InteractableObjectUngrabbed += OnDrop;
|
|
}
|
|
else
|
|
{
|
|
m_interactable.InteractableObjectSnappedToDropZone -= OnSnap;
|
|
m_interactable.InteractableObjectGrabbed -= OnGrab;
|
|
m_interactable.InteractableObjectUngrabbed -= OnDrop;
|
|
}
|
|
}
|
|
|
|
|
|
}
|