RKHandInteractionDemo.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using Rokid.UXR.Interaction;
  4. namespace Rokid.UXR.Demo
  5. {
  6. public class RKHandInteractionDemo : MonoBehaviour
  7. {
  8. [SerializeField]
  9. private GrabInteractable[] interactableObjs;
  10. private List<Vector3> oriPositions = new List<Vector3>();
  11. void Start()
  12. {
  13. interactableObjs = GetComponentsInChildren<GrabInteractable>();
  14. for (int i = 0; i < interactableObjs.Length; i++)
  15. {
  16. oriPositions.Add(interactableObjs[i].transform.localPosition);
  17. }
  18. }
  19. void Update()
  20. {
  21. if (IsDoubleClick())
  22. {
  23. for (int i = 0; i < interactableObjs.Length; i++)
  24. {
  25. Rigidbody rigidbody = interactableObjs[i].GetComponent<Rigidbody>();
  26. rigidbody.angularVelocity = Vector3.zero;
  27. rigidbody.velocity = Vector3.zero;
  28. interactableObjs[i].transform.localPosition = oriPositions[i];
  29. interactableObjs[i].transform.localRotation = Quaternion.identity;
  30. interactableObjs[i].gameObject.SetActive(true);
  31. }
  32. }
  33. }
  34. #region IsDoubleClick
  35. float doubleClickTime = 0.5f;
  36. float clickTime = 0;
  37. int clickCount = 0;
  38. private bool IsDoubleClick()
  39. {
  40. clickTime += Time.deltaTime;
  41. if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.JoystickButton0))
  42. {
  43. clickCount++;
  44. }
  45. if (clickTime < doubleClickTime)
  46. {
  47. if (clickCount == 2)
  48. {
  49. clickTime = 0;
  50. clickCount = 0;
  51. return true;
  52. }
  53. }
  54. else
  55. {
  56. clickCount = 0;
  57. clickTime = 0;
  58. }
  59. return false;
  60. }
  61. #endregion
  62. }
  63. }