MainCameraCache.cs 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Rokid.UXR.Utility
  5. {
  6. /// <summary>
  7. /// 全局常量配置
  8. /// </summary>
  9. public class MainCameraCache
  10. {
  11. private static Camera cameraCache;
  12. public static Camera mainCamera
  13. {
  14. get
  15. {
  16. if (cameraCache == null)
  17. {
  18. cameraCache = Camera.main;
  19. }
  20. if (cameraCache == null)
  21. {
  22. RKLog.Warning("Please Create a Main Camera!!!");
  23. }
  24. return cameraCache;
  25. }
  26. }
  27. /// <summary>
  28. /// Manually update the cached main camera
  29. /// </summary>
  30. public static void UpdateCachedMainCamera(Camera camera)
  31. {
  32. if (camera != cameraCache)
  33. {
  34. GameObject.Destroy(cameraCache);
  35. cameraCache = camera;
  36. }
  37. }
  38. }
  39. }