123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using SC.XR.Unity.Module_InputSystem;
- using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Manage : MonoBehaviour
- {
- public Move move;
- public Transform target;
- public Transform leftHand;
- public Transform rightHand;
- public Transform head;
- //public HandDetector detector;
- public Camera leftCamera;
- public bool state;
-
- private Vector3 hitPoint;
- /*
- * 因当前SCSDK版本太低 没找到调用手部射线交互点的信息 ,
- * 所以用了 比较蠢的方法, 后面维护要是空的慌 ,可以自行修改
- *
- */
- //private InputDeviceBase leftHand;
- //private InputDeviceBase rightHand;
- //private InputDeviceBase head;
- private void Start()
- {
- state = false;
- //leftHand = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.GT26Dof);
- //rightHand = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.GGT26Dof);
- //head = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.Head);
- }
- private void Update()
- {
- #region old
- // CursorPress
- //if (Input.GetMouseButtonDown(0))
- //{
- // if (rightHand.gameObject.activeSelf)
- // {
- // Debug.Log("rightHand");
- // }
- // else if (leftHand.gameObject.activeSelf)
- // {
- // Debug.Log("leftHand");
- // }
- // else if (head.gameObject.activeSelf)
- // {
- // Debug.Log("head");
- // }
- // // SetDestination();
- //}
- #endregion
- // 优先级 右手 左手 其他(头 )
- if(state)
- {
- state = false;
- if(rightHand.gameObject.activeSelf)
- {
- SetDestination(rightHand.position);
- }
- else if(leftHand.gameObject.activeSelf)
- {
- SetDestination(leftHand.position);
- }
- else if(head.gameObject.activeSelf)
- {
- SetDestination(head.position);
- }
- }
- }
- public void PlaneOnClick()
- {
- state = true;
- Debug.Log("PlaneOnClick");
- }
- private void SetDestination()
- {
- Ray ray = leftCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, 50))
- {
- hitPoint = new Vector3(hit.point.x, 0, hit.point.z);
- GameObject newTarget = GameObject.Instantiate(target, new Vector3(hitPoint.x, transform.position.y + 0.02f, hitPoint.z), Quaternion.identity, null).gameObject;
- newTarget.SetActive(true);
- move.SetDestination(hitPoint);
- Debug.Log(hitPoint);
- }
- }
- private void SetDestination( Vector3 pos)
- {
- pos = new Vector3(pos.x, transform.position.y, pos.z);
- GameObject newTarget = GameObject.Instantiate(target, pos + new Vector3(0, 0.02f, 0), Quaternion.identity, null).gameObject;
- newTarget.transform.parent = transform.parent;
- // Debug.Log(newTarget.transform.parent.name + " AAAAAAAAAAAAAA");
- newTarget.SetActive(true);
- newTarget.transform.LookAt(transform);
- move.SetDestination(pos);
- }
- }
|