BorderManager.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using SC.XR.Unity;
  2. using SC.XR.Unity.Module_InputSystem;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.EventSystems;
  7. public class BorderManager : SingletonMono<BorderManager>
  8. {
  9. [HideInInspector]
  10. public bool isEnable=false;//是否开启此功能
  11. const string boxName = "BoxSign";
  12. Dictionary<string,GameObject> BoxSignDic;
  13. public void StartSearch()
  14. {
  15. isEnable = true;
  16. }
  17. public void StopSearch()
  18. {
  19. isEnable = false;
  20. }
  21. public void BtnClick()
  22. {
  23. if (!isEnable)
  24. {
  25. OpenFunc();
  26. }
  27. else
  28. {
  29. CloseFunc();
  30. }
  31. }
  32. public void OpenFunc()
  33. {
  34. //if (API_GSXR_Slam.SlamManager != null && !API_GSXR_Slam.GSXR_Is_SlamRunning())
  35. //{
  36. // return;
  37. //}
  38. StartSearch();
  39. if (API_GSXR_Module_InputSystem.GSXR_InputDeviceStatus(InputDeviceType.GGT26Dof))
  40. {
  41. InstantiateObj(API_GSXR_Module_InputSystem_GGT26Dof.GSXR_GGTLeft);
  42. InstantiateObj(API_GSXR_Module_InputSystem_GGT26Dof.GSXR_GGTRight);
  43. }
  44. else if (API_GSXR_Module_InputSystem.GSXR_InputDeviceStatus(InputDeviceType.KS))
  45. {
  46. InstantiateObj(API_GSXR_Module_InputSystem_KS.GSXR_KSLeft);
  47. InstantiateObj(API_GSXR_Module_InputSystem_KS.GSXR_KSRight);
  48. }
  49. else if (API_GSXR_Module_InputSystem.GSXR_InputDeviceStatus(InputDeviceType.Head))
  50. {
  51. InstantiateObj(API_GSXR_Module_InputSystem_Head.GSXR_Head);
  52. }
  53. }
  54. public void CloseFunc()
  55. {
  56. StopSearch();
  57. foreach (var item in BoxSignDic.Values)
  58. {
  59. item.SetActive(false);
  60. }
  61. }
  62. void InstantiateObj(InputDevicePartBase part)
  63. {
  64. if (part.detectorBase.pointerBase.cursorBase.transform.GetComponentInChildren<BorderState>(true) == false)
  65. {
  66. GameObject obj = Instantiate(Resources.Load<GameObject>("Prefabs/BoundingBoxSign"));
  67. obj.transform.SetParent(part.detectorBase.pointerBase.cursorBase.transform);
  68. obj.transform.localPosition = Vector3.zero;
  69. obj.transform.localRotation = Quaternion.identity;
  70. obj.name = boxName + part.PartType;
  71. if (!BoxSignDic.ContainsKey(obj.name))
  72. {
  73. BoxSignDic.Add(obj.name, obj);
  74. }
  75. }
  76. else
  77. {
  78. part.detectorBase.pointerBase.cursorBase.transform.GetComponentInChildren<BorderState>(true).gameObject.SetActive(true);
  79. }
  80. }
  81. #region MonoBehaviour Function
  82. private void Start()
  83. {
  84. BoxSignDic = new Dictionary<string, GameObject>();
  85. }
  86. private void OnDestroy()
  87. {
  88. if (BoxSignDic!=null)
  89. {
  90. BoxSignDic.Clear();
  91. }
  92. }
  93. #endregion
  94. }