Exemplo n.º 1
0
        private void Update()
        {
            FirstActiveCamera = FindFirstActiveCamera();
            if (FirstActiveCamera != null)
            {
                CurrentDebugColor = ShadowQualityLods[LOD].DebugColor;

                Debug.DrawLine(transform.position, LODCameras[index].transform.position, CurrentDebugColor);
            }
        }
Exemplo n.º 2
0
        IEnumerator AdjustLODQuality()
        {
            float          delay = UpdateDelay + UnityEngine.Random.value / 20f; //this randomization is to prevent all lights updating at the same time causing frame spikes
            int            i     = 0;
            int            DesiredQuality;
            LODAdjustment  ClampedLOD;
            WaitForSeconds Wait = new WaitForSeconds(delay);

            while (true)
            {
                FirstActiveCamera = FindFirstActiveCamera();

                if (FirstActiveCamera != null) // If first active camera is null, no cameras with LightLODCamera are active, so we will default to on, unless it should be on
                {
                    if (LightShouldBeOn)
                    {
                        DistanceFromPlayer = Vector3.Distance(transform.position, FirstActiveCamera.transform.position);
                        for (i = 0; i < ShadowQualityLods.Count; i++)
                        {
                            if ((DistanceFromPlayer > ShadowQualityLods[i].DistanceRange.x && DistanceFromPlayer <= ShadowQualityLods[i].DistanceRange.y) || i == ShadowQualityLods.Count - 1)
                            {
                                LOD = i;
                                if (ShadowQualityLods[i].CastNoShadows)
                                {
                                    light.shadows = LightShadows.None;
                                    if (ShowLightColorAsDebugColor)
                                    {
                                        light.color = ShadowQualityLods[i].DebugColor;
                                    }
                                }
                                else
                                {
                                    light.shadows = DesiredLightShadowQuality;
                                    light.enabled = true;
                                    //respect quality settings, do not go higher than what they have defined.
                                    if (QualitySettings.shadowResolution <= ShadowQualityLods[i].ShadowResolution)
                                    {
                                        IsClamped = true;

                                        DesiredQuality         = (int)QualitySettings.shadowResolution;
                                        light.shadowResolution = (LightShadowResolution)DesiredQuality;

                                        if (ShowLightColorAsDebugColor)
                                        {
                                            ClampedLOD = FindMatchingShadowQualityIndex(QualitySettings.shadowResolution);
                                            if (ClampedLOD == null)
                                            {
                                                Debug.LogWarning(string.Format(WarningMessage, QualitySettings.shadowResolution.ToString()));
                                            }
                                            else
                                            {
                                                light.color = ClampedLOD.DebugColor;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        IsClamped = false;

                                        light.shadowResolution = (LightShadowResolution)ShadowQualityLods[i].ShadowResolution;

                                        if (ShowLightColorAsDebugColor)
                                        {
                                            light.color = ShadowQualityLods[i].DebugColor;
                                        }
                                    }
                                }

                                break;
                            }
                        }
                    }
                    else
                    {
                        light.enabled = false;
                        LOD           = 0;
                    }
                }
                else if (InitiallyOn)
                {
                    light.enabled          = true;
                    light.shadows          = DesiredLightShadowQuality;
                    light.shadowResolution = InspectorShadowResolution;
                    LOD = 0;
                }

                yield return(Wait);
            }
        }