ZEDLight.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //======= Copyright (c) Stereolabs Corporation, All rights reserved. ===============
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Causes the attached Light component to cast light on the real world, if visible by the ZED.
  6. /// Must be a point, spot, or directional light. Directional lights will also cast shadows on real objects.
  7. /// Works by registering the Light component to a static list (contained within) that's checked by ZEDRenderingPlane.
  8. /// For more information, see our Lighting guide: https://docs.stereolabs.com/mixed-reality/unity/lighting/
  9. /// </summary>
  10. [RequireComponent(typeof(Light))]
  11. public class ZEDLight : MonoBehaviour
  12. {
  13. /// <summary>
  14. /// List of all ZEDLights in the scene.
  15. /// </summary>
  16. [HideInInspector]
  17. public static List<ZEDLight> s_lights = new List<ZEDLight>();
  18. /// <summary>
  19. /// Light component attached to this GameObject.
  20. /// </summary>
  21. [HideInInspector]
  22. public Light cachedLight;
  23. /// <summary>
  24. /// Interior cone of the spotlight, if the Light is a spotlight.
  25. /// </summary>
  26. [HideInInspector]
  27. public float interiorCone = 0.1f;
  28. // Use this for initialization
  29. void OnEnable()
  30. {
  31. if (!s_lights.Contains(this))
  32. {
  33. s_lights.Add(this);
  34. cachedLight = GetComponent<Light>();
  35. }
  36. }
  37. void OnDisable()
  38. {
  39. if (s_lights != null)
  40. {
  41. s_lights.Remove(this);
  42. }
  43. }
  44. /// <summary>
  45. /// Checks if a light is both enabled and has above-zero range and intensity.
  46. /// Used by ZEDRenderingPlane to filter out lights that won't be visible.
  47. /// </summary>
  48. /// <returns></returns>
  49. public bool IsEnabled()
  50. {
  51. if (!cachedLight.enabled)
  52. {
  53. return false;
  54. }
  55. if (cachedLight.range <= 0 || cachedLight.intensity <= 0)
  56. {
  57. return false;
  58. }
  59. return true;
  60. }
  61. }