123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using UnityEngine;
- using Nxr.Internal;
- using NibiruAxis;
- using NibiruTask;
- namespace NXR.Samples
- {
- public class DragTest : MonoBehaviour
- {
- public TextMesh statusTextMesh;
- NxrDragableItem dragableItem;
- bool IsSelected = false;
- private Transform parentTrans;
- public void OnGazeEnter()
- {
- IsSelected = true;
- statusTextMesh.text = "Selected";
- }
- public void OnGazeExit()
- {
- IsSelected = false;
- statusTextMesh.text = "UnSelected";
- if (dragableItem != null && dragableItem.IsDraging)
- {
- statusTextMesh.text = "Draging";
- }
- }
- public void OnGazeTrigger()
- {
- bool isDraging = dragableItem != null && dragableItem.IsDraging;
- if (!IsSelected && !isDraging) return;
-
- if(!isDraging)
- {
- NxrLaserPointer nxrLaserPointer = NxrPlayerCtrl.Instance.GetControllerLaser();
- if(nxrLaserPointer != null)
- {
- // 选中跟随
- if (dragableItem != null)
- {
- dragableItem.OnBeginDrag(nxrLaserPointer.transform);
- }
- } else
- {
- // 头部
- NxrReticle mReticle = NxrViewer.Instance.GetNxrReticle();
- if(dragableItem != null)
- {
- dragableItem.OnBeginDrag(mReticle.gameObject.transform.parent);
- }
- }
- } else
- {
- // 恢复
- if (dragableItem != null)
- {
- dragableItem.OnEndDrag(parentTrans);
- }
- }
- }
-
- // Start is called before the first frame update
- void Start()
- {
- dragableItem = GetComponent<NxrDragableItem>();
- parentTrans = gameObject.transform.parent;
- statusTextMesh.text = "UnSelected";
- }
- private void Update()
- {
- if (NxrInput.GetKeyDown(CKeyEvent.KEYCODE_DPAD_CENTER) ||
- NxrInput.GetControllerKeyDown(CKeyEvent.KEYCODE_CONTROLLER_TOUCHPAD))
- {
- OnGazeTrigger();
- }
- }
- }
- }
|