123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace EZXR.Glass.Inputs
- {
-
-
-
- public class TriggerForPinch : MonoBehaviour
- {
- public HandInfo handInfo;
- public HandTouch objectGrab;
- public RotateUseHandle rotateUseHandle;
- public ScaleUseCorner scaleUseCorner;
-
- void Start()
- {
- }
-
- void Update()
- {
- #region 设置触发区的位置为拇指和食指指尖中心,长度也和两个指尖的距离相关
- Vector3 thumbTip;
- Vector3 indexTip;
- if (handInfo.Exist)
- {
- thumbTip = handInfo.GetJointData(HandJointType.Thumb_3).position;
- indexTip = handInfo.GetJointData(HandJointType.Index_4).position;
- }
- else
- {
- thumbTip = new Vector3(9999, 9999, 9999);
- indexTip = new Vector3(10000, 10000, 10000);
- }
- transform.position = (thumbTip + indexTip) / 2.0f;
- transform.localScale = new Vector3(0.01f, 0.01f, (thumbTip - indexTip).magnitude + 0.02f);
- transform.LookAt(indexTip);
- #endregion
- }
-
-
-
-
-
-
- public void SetUp(Transform handRoot)
- {
- handInfo = handRoot.GetComponent<HandInfo>();
- objectGrab = handRoot.GetComponent<HandTouch>();
- rotateUseHandle = handRoot.GetComponent<RotateUseHandle>();
- scaleUseCorner = handRoot.GetComponent<ScaleUseCorner>();
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.layer != gameObject.layer)
- {
- if (handInfo != null)
- {
-
- if (!handInfo.isPinching )
- {
- if (other.tag == "SpatialObject")
- {
-
- handInfo.CurCloseContactingTarget = other;
- objectGrab.ForOnTriggerEnter(other);
- }
- else if (other.tag == "SpatialHandler")
- {
- rotateUseHandle.ForOnTriggerEnter(other);
- scaleUseCorner.ForOnTriggerEnter(other);
- }
- }
- }
- }
- }
- private void OnTriggerStay(Collider other)
- {
- if (other.gameObject.layer != gameObject.layer)
- {
- if (handInfo != null)
- {
-
- if (!handInfo.isPinching )
- {
- if (other.tag == "SpatialObject")
- {
-
- handInfo.CurCloseContactingTarget = other;
- objectGrab.ForOnTriggerStay(other);
- }
- else if (other.tag == "SpatialHandler")
- {
- rotateUseHandle.ForOnTriggerStay(other);
- scaleUseCorner.ForOnTriggerStay(other);
- }
- }
- }
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.gameObject.layer != gameObject.layer)
- {
- if (handInfo != null)
- {
-
- if (!handInfo.isPinching)
- {
- if (other.tag == "SpatialObject")
- {
- if (handInfo.CurCloseContactingTarget == other)
- {
- handInfo.CurCloseContactingTarget = null;
- }
- Debug.Log("InteractWithFingerTip exit: " + other.name);
- objectGrab.ForOnTriggerExit(other);
- }
- else if (other.tag == "SpatialHandler")
- {
- rotateUseHandle.ForOnTriggerExit(other);
- scaleUseCorner.ForOnTriggerExit(other);
- }
- }
- }
- }
- }
- }
- }
|