Manage.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using SC.XR.Unity.Module_InputSystem;
  2. using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class Manage : MonoBehaviour
  7. {
  8. public Move move;
  9. public Transform target;
  10. public Transform leftHand;
  11. public Transform rightHand;
  12. public Transform head;
  13. //public HandDetector detector;
  14. public Camera leftCamera;
  15. public bool state;
  16. private Vector3 hitPoint;
  17. /*
  18. * 因当前SCSDK版本太低 没找到调用手部射线交互点的信息 ,
  19. * 所以用了 比较蠢的方法, 后面维护要是空的慌 ,可以自行修改
  20. *
  21. */
  22. //private InputDeviceBase leftHand;
  23. //private InputDeviceBase rightHand;
  24. //private InputDeviceBase head;
  25. private void Start()
  26. {
  27. state = false;
  28. //leftHand = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.GT26Dof);
  29. //rightHand = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.GGT26Dof);
  30. //head = Module_InputSystem.instance.GetInputDevice<InputDeviceBase>(InputDeviceType.Head);
  31. }
  32. private void Update()
  33. {
  34. #region old
  35. // CursorPress
  36. //if (Input.GetMouseButtonDown(0))
  37. //{
  38. // if (rightHand.gameObject.activeSelf)
  39. // {
  40. // Debug.Log("rightHand");
  41. // }
  42. // else if (leftHand.gameObject.activeSelf)
  43. // {
  44. // Debug.Log("leftHand");
  45. // }
  46. // else if (head.gameObject.activeSelf)
  47. // {
  48. // Debug.Log("head");
  49. // }
  50. // // SetDestination();
  51. //}
  52. #endregion
  53. // 优先级 右手 左手 其他(头 )
  54. if(state)
  55. {
  56. state = false;
  57. if(rightHand.gameObject.activeSelf)
  58. {
  59. SetDestination(rightHand.position);
  60. }
  61. else if(leftHand.gameObject.activeSelf)
  62. {
  63. SetDestination(leftHand.position);
  64. }
  65. else if(head.gameObject.activeSelf)
  66. {
  67. SetDestination(head.position);
  68. }
  69. }
  70. }
  71. public void PlaneOnClick()
  72. {
  73. state = true;
  74. Debug.Log("PlaneOnClick");
  75. }
  76. private void SetDestination()
  77. {
  78. Ray ray = leftCamera.ScreenPointToRay(Input.mousePosition);
  79. RaycastHit hit;
  80. if (Physics.Raycast(ray, out hit, 50))
  81. {
  82. hitPoint = new Vector3(hit.point.x, 0, hit.point.z);
  83. GameObject newTarget = GameObject.Instantiate(target, new Vector3(hitPoint.x, transform.position.y + 0.02f, hitPoint.z), Quaternion.identity, null).gameObject;
  84. newTarget.SetActive(true);
  85. move.SetDestination(hitPoint);
  86. Debug.Log(hitPoint);
  87. }
  88. }
  89. private void SetDestination( Vector3 pos)
  90. {
  91. pos = new Vector3(pos.x, transform.position.y, pos.z);
  92. GameObject newTarget = GameObject.Instantiate(target, pos + new Vector3(0, 0.02f, 0), Quaternion.identity, null).gameObject;
  93. newTarget.transform.parent = transform.parent;
  94. // Debug.Log(newTarget.transform.parent.name + " AAAAAAAAAAAAAA");
  95. newTarget.SetActive(true);
  96. newTarget.transform.LookAt(transform);
  97. move.SetDestination(pos);
  98. }
  99. }