UserDefinePanel.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 System.Collections;
  10. using UnityEngine;
  11. namespace NRKernal.NRExamples
  12. {
  13. /// <summary> Panel for editing the user define. </summary>
  14. [HelpURL("https://developer.nreal.ai/develop/unity/customize-phone-controller")]
  15. public class UserDefinePanel : MonoBehaviour
  16. {
  17. /// <summary> The user define panel. </summary>
  18. public GameObject m_UserDefinePanel;
  19. /// <summary> Starts this object. </summary>
  20. void Start()
  21. {
  22. StartCoroutine(RigistUserDefinePanel());
  23. }
  24. /// <summary> Rigist user define panel. </summary>
  25. /// <returns> An IEnumerator. </returns>
  26. private IEnumerator RigistUserDefinePanel()
  27. {
  28. while (GameObject.FindObjectOfType<NRVirtualDisplayer>() == null)
  29. {
  30. yield return new WaitForEndOfFrame();
  31. }
  32. var virtualdisplayer = GameObject.FindObjectOfType<NRVirtualDisplayer>();
  33. if (virtualdisplayer.transform.GetComponentInChildren<Canvas>() == null)
  34. {
  35. yield break;
  36. }
  37. var root = virtualdisplayer.transform.GetComponentInChildren<Canvas>().transform;
  38. Instantiate(m_UserDefinePanel, root);
  39. }
  40. }
  41. }