123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using EZXR.Glass.Core;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace EZXR.Glass.Inputs
- {
- [ScriptExecutionOrder(-47)]
- public class TriggerForFarNearSwitch : MonoBehaviour
- {
- //检测Trigger的长度
- public static float length = 0.24f;
- HandInfo handInfo;
- private void Awake()
- {
- //transform.localScale = Vector3.one * radius * 2;
- }
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (handInfo != null && handInfo.Exist)
- {
- Pose pose = handInfo.GetJointData(HandJointType.Palm);
- transform.position = pose.position;
- transform.rotation = pose.rotation; ;
- }
- }
- private void OnDisable()
- {
- handInfo.PreCloseContactingTarget = null;
- handInfo.Last_PreCloseContactingTarget = null;
- }
- public void SetUp(Transform handRoot)
- {
- handInfo = handRoot.GetComponent<HandInfo>();
- }
- private void OnTriggerStay(Collider other)
- {
- if (other.gameObject.layer != gameObject.layer)
- {
- if (handInfo != null)
- {
- //“当用户的手是up状态”且“当前手没有进入其他Trigger”时
- if (!handInfo.isPinching && !handInfo.IsCloseContacting)
- {
- if (other.tag == "SpatialObject" || other.tag == "SpatialUI" || other.tag == "SpatialHandler")
- {
- handInfo.preCloseContacting = true;
- if (handInfo.PreCloseContactingTarget == null || Vector3.Distance(transform.position, other.transform.position) < Vector3.Distance(transform.position, handInfo.PreCloseContactingTarget.position))
- {
- //handInfo.Last_PreCloseContactingTarget = handInfo.PreCloseContactingTarget;
- handInfo.PreCloseContactingTarget = other.transform;
- }
- }
- }
- }
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.gameObject.layer != gameObject.layer)
- {
- if (handInfo != null)
- {
- //“当用户的手是up状态”且“当前手没有进入其他Trigger”时
- if (!handInfo.isPinching && !handInfo.IsCloseContacting)
- {
- if (other.tag == "SpatialObject" || other.tag == "SpatialUI" || other.tag == "SpatialHandler")
- {
- if (handInfo.PreCloseContactingTarget == other.transform)
- {
- //handInfo.Last_PreCloseContactingTarget = handInfo.PreCloseContactingTarget;
- handInfo.PreCloseContactingTarget = null;
- }
- }
- }
- }
- }
- }
- }
- }
|