1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System.Collections.Generic;
- using UnityEngine;
- using Rokid.UXR.Interaction;
- namespace Rokid.UXR.Demo
- {
- public class RKHandInteractionDemo : MonoBehaviour
- {
- [SerializeField]
- private GrabInteractable[] interactableObjs;
- private List<Vector3> oriPositions = new List<Vector3>();
- void Start()
- {
- interactableObjs = GetComponentsInChildren<GrabInteractable>();
- for (int i = 0; i < interactableObjs.Length; i++)
- {
- oriPositions.Add(interactableObjs[i].transform.localPosition);
- }
- }
- void Update()
- {
- if (IsDoubleClick())
- {
- for (int i = 0; i < interactableObjs.Length; i++)
- {
- Rigidbody rigidbody = interactableObjs[i].GetComponent<Rigidbody>();
- rigidbody.angularVelocity = Vector3.zero;
- rigidbody.velocity = Vector3.zero;
- interactableObjs[i].transform.localPosition = oriPositions[i];
- interactableObjs[i].transform.localRotation = Quaternion.identity;
- interactableObjs[i].gameObject.SetActive(true);
- }
- }
- }
- #region IsDoubleClick
- float doubleClickTime = 0.5f;
- float clickTime = 0;
- int clickCount = 0;
- private bool IsDoubleClick()
- {
- clickTime += Time.deltaTime;
- if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.JoystickButton0))
- {
- clickCount++;
- }
- if (clickTime < doubleClickTime)
- {
- if (clickCount == 2)
- {
- clickTime = 0;
- clickCount = 0;
- return true;
- }
- }
- else
- {
- clickCount = 0;
- clickTime = 0;
- }
- return false;
- }
- #endregion
- }
- }
|