UIDrag.cs 985 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using Valve.VR;
  6. public class UIDrag: MonoBehaviour,IPointerDownHandler,IPointerUpHandler
  7. {
  8. public GameObject RightHand;
  9. public bool autoLockRobot = true;
  10. Transform parent;
  11. // Update is called once per frame
  12. void Update()
  13. {
  14. }
  15. public void startDrag(){
  16. parent = this.gameObject.transform.parent;
  17. this.gameObject.transform.parent = RightHand.transform;
  18. }
  19. public void stopDrag(){
  20. this.gameObject.transform.parent = parent;
  21. }
  22. public void OnPointerDown(PointerEventData eventData)
  23. {
  24. if(!InteractionManagement.Instance.Robot_Locked && autoLockRobot){
  25. InteractionManagement.Instance.LockRobot(true); // automatically lock the robot
  26. }
  27. startDrag();
  28. }
  29. public void OnPointerUp(PointerEventData eventData)
  30. {
  31. stopDrag();
  32. }
  33. }