/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ using UnityEngine; using UnityEngine.SceneManagement; namespace NRKernal.NRExamples { /// Panel for editing the hidden debug. public class HiddenDebugPanel : MonoBehaviour { /// The buttons root. public Transform m_ButtonsRoot; /// The buttons. private UserDefineButton[] Buttons; /// Starts this object. void Start() { Buttons = gameObject.GetComponentsInChildren(true); m_ButtonsRoot.gameObject.SetActive(false); foreach (var item in Buttons) { item.OnClick += OnItemTriggerEvent; } } /// Executes the 'item trigger event' action. /// The key. private void OnItemTriggerEvent(string key) { if (key.Equals("InvisibleBtn")) { m_ButtonsRoot.gameObject.SetActive(!m_ButtonsRoot.gameObject.activeInHierarchy); } else if (CanSceneLoaded(key)) { SceneManager.LoadScene(key); } } /// Determine if we can scene loaded. /// The name. /// True if we can scene loaded, false if not. private bool CanSceneLoaded(string name) { return (SceneUtility.GetBuildIndexByScenePath(name) != -1) && !SceneManager.GetActiveScene().name.Equals(name); } } }