PhoneScreenUtils.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. using Rokid.UXR;
  8. namespace Rokid.UXR.Utility
  9. {
  10. [ExecuteAlways]
  11. public class PhoneScreenUtils : MonoBehaviour
  12. {
  13. [SerializeField]
  14. private Canvas canvas;
  15. [SerializeField]
  16. private Camera phoneCamera;
  17. [SerializeField]
  18. private Text infoText;
  19. /// <summary>
  20. /// 在Unity编辑器上是否激活
  21. /// </summary>
  22. [SerializeField]
  23. private bool activeWhenUnityEditor;
  24. private void OnEnable()
  25. {
  26. // AutoInjectComponent.AutoInject(transform, this);
  27. #if !UNITY_EDITOR
  28. canvas.gameObject.SetActive(true);
  29. phoneCamera.gameObject.SetActive(true);
  30. phoneCamera.clearFlags=CameraClearFlags.SolidColor;
  31. #endif
  32. #if UNITY_2021_3_OR_NEWER
  33. if (infoText != null && SceneManager.GetActiveScene().name.Contains("RK"))
  34. {
  35. infoText.text = "Rokid_" + SceneManager.GetActiveScene().name.Split("RK")[1];
  36. }
  37. #endif
  38. }
  39. private void Update()
  40. {
  41. #if UNITY_EDITOR
  42. canvas.gameObject.SetActive(activeWhenUnityEditor);
  43. phoneCamera.gameObject.SetActive(activeWhenUnityEditor);
  44. #endif
  45. }
  46. }
  47. }