HiddenDebugPanel.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. using UnityEngine;
  10. using UnityEngine.SceneManagement;
  11. namespace NRKernal.NRExamples
  12. {
  13. /// <summary> Panel for editing the hidden debug. </summary>
  14. public class HiddenDebugPanel : MonoBehaviour
  15. {
  16. /// <summary> The buttons root. </summary>
  17. public Transform m_ButtonsRoot;
  18. /// <summary> The buttons. </summary>
  19. private UserDefineButton[] Buttons;
  20. /// <summary> Starts this object. </summary>
  21. void Start()
  22. {
  23. Buttons = gameObject.GetComponentsInChildren<UserDefineButton>(true);
  24. m_ButtonsRoot.gameObject.SetActive(false);
  25. foreach (var item in Buttons)
  26. {
  27. item.OnClick += OnItemTriggerEvent;
  28. }
  29. }
  30. /// <summary> Executes the 'item trigger event' action. </summary>
  31. /// <param name="key"> The key.</param>
  32. private void OnItemTriggerEvent(string key)
  33. {
  34. if (key.Equals("InvisibleBtn"))
  35. {
  36. m_ButtonsRoot.gameObject.SetActive(!m_ButtonsRoot.gameObject.activeInHierarchy);
  37. }
  38. else if (CanSceneLoaded(key))
  39. {
  40. SceneManager.LoadScene(key);
  41. }
  42. }
  43. /// <summary> Determine if we can scene loaded. </summary>
  44. /// <param name="name"> The name.</param>
  45. /// <returns> True if we can scene loaded, false if not. </returns>
  46. private bool CanSceneLoaded(string name)
  47. {
  48. return (SceneUtility.GetBuildIndexByScenePath(name) != -1) &&
  49. !SceneManager.GetActiveScene().name.Equals(name);
  50. }
  51. }
  52. }