123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using UnityEngine;
- using UnityEngine.UI;
- namespace NRKernal
- {
-
- public class NRHomeMenu : MonoBehaviour
- {
-
- public Button confirmBtn;
-
- public Button cancelBtn;
-
- private static NRHomeMenu m_Instance;
-
- private static string m_MenuPrefabPath = "NRUI/NRHomeMenu";
-
- private Transform CameraCenter { get { return NRInput.CameraCenter; } }
-
- public static bool IsShowing { get; private set; }
-
- public static System.Action OnHomeMenuShow;
-
- public static System.Action OnHomeMenuHide;
-
- void Start()
- {
- confirmBtn.onClick.AddListener(OnComfirmButtonClick);
- cancelBtn.onClick.AddListener(OnCancelButtonClick);
- }
-
- void Update()
- {
- if (IsShowing && NRInput.RaycastMode == RaycastModeEnum.Laser)
- {
- FollowCamera();
- }
- }
-
- private void OnComfirmButtonClick()
- {
- Hide();
- NRAppManager.QuitApplication();
- }
-
- private void OnCancelButtonClick()
- {
- Hide();
- }
-
- private void FollowCamera()
- {
- if (m_Instance && CameraCenter)
- {
- m_Instance.transform.position = CameraCenter.position;
- m_Instance.transform.rotation = CameraCenter.rotation;
- }
- }
-
- private static void CreateMenu()
- {
- GameObject menuPrefab = Resources.Load<GameObject>(m_MenuPrefabPath);
- if (menuPrefab == null)
- {
- NRDebugger.Error("Can not find prefab: " + m_MenuPrefabPath);
- return;
- }
- GameObject menuGo = Instantiate(menuPrefab);
- m_Instance = menuGo.GetComponent<NRHomeMenu>();
- if (m_Instance)
- {
- DontDestroyOnLoad(menuGo);
- }
- else
- {
- Destroy(menuGo);
- }
- }
-
- public static void Toggle()
- {
- if (IsShowing)
- {
- Hide();
- }
- else
- {
- Show();
- }
- }
-
- public static void Show()
- {
- if (m_Instance == null)
- {
- CreateMenu();
- }
- if (m_Instance)
- {
- m_Instance.gameObject.SetActive(true);
- IsShowing = true;
- if (NRInput.RaycastMode == RaycastModeEnum.Gaze)
- {
- m_Instance.FollowCamera();
- }
- if (OnHomeMenuShow != null)
- {
- OnHomeMenuShow();
- }
- }
- }
-
- public static void Hide()
- {
- if (m_Instance)
- {
- m_Instance.gameObject.SetActive(false);
- IsShowing = false;
- if (OnHomeMenuHide != null)
- {
- OnHomeMenuHide();
- }
- }
- }
- }
- }
|