BackButton.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Nxr.Internal;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. using NibiruTask;
  5. namespace NXR.Samples
  6. {
  7. //
  8. [RequireComponent(typeof(Collider))]
  9. public class BackButton : MonoBehaviour, INxrGazeResponder
  10. {
  11. private bool gazeAt = false;
  12. public void OnGazeEnter()
  13. {
  14. SetGazedAt(true);
  15. }
  16. public void OnGazeExit()
  17. {
  18. SetGazedAt(false);
  19. }
  20. public void OnGazeTrigger()
  21. {
  22. if (gameObject.name.Equals("ReqPermissionButton"))
  23. {
  24. if (NxrViewer.Instance.GetNibiruService() == null) return;
  25. NxrViewer.Instance.GetNibiruService().RequsetPermission(new string[]
  26. {
  27. NxrGlobal.Permission.CAMERA,
  28. NxrGlobal.Permission.WRITE_EXTERNAL_STORAGE,
  29. NxrGlobal.Permission.READ_EXTERNAL_STORAGE,
  30. NxrGlobal.Permission.ACCESS_NETWORK_STATE,
  31. NxrGlobal.Permission.ACCESS_COARSE_LOCATION,
  32. NxrGlobal.Permission.BLUETOOTH,
  33. NxrGlobal.Permission.BLUETOOTH_ADMIN,
  34. NxrGlobal.Permission.INTERNET,
  35. NxrGlobal.Permission.GET_TASKS
  36. });
  37. return;
  38. }
  39. // Return the current Active Scene in order to get the current Scene name.
  40. Scene scene = SceneManager.GetActiveScene();
  41. if (scene.name.Equals("FirstScene"))
  42. {
  43. if (Application.isMobilePlatform) Application.Quit();
  44. }
  45. else
  46. {
  47. SceneManager.LoadScene("FirstScene");
  48. }
  49. }
  50. public void OnUpdateIntersectionPosition(Vector3 position)
  51. {
  52. }
  53. // Start is called before the first frame update
  54. void Start()
  55. {
  56. SetGazedAt(false);
  57. }
  58. public void SetGazedAt(bool gazedAt)
  59. {
  60. gazeAt = gazedAt;
  61. Material mat = GetComponent<Renderer>().material;
  62. Color color = gazedAt ? Color.green : Color.white;
  63. mat.color = color;
  64. mat.SetColor("_BaseColor", color);
  65. }
  66. private void Update()
  67. {
  68. if (NxrInput.GetKeyUp(CKeyEvent.KEYCODE_BACK) ||
  69. NxrInput.GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU) ||
  70. NxrInput.GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU,
  71. InteractionManager.NACTION_HAND_TYPE.HAND_LEFT) ||
  72. NxrInput.GetControllerKeyUp(CKeyEvent.KEYCODE_CONTROLLER_MENU,
  73. InteractionManager.NACTION_HAND_TYPE.HAND_RIGHT))
  74. {
  75. // 返回键
  76. Debug.Log("Update->OnGazeTrigger");
  77. OnGazeTrigger();
  78. }
  79. }
  80. }
  81. }