public void ApplyLighting(LightingDefinition lightingDefinition, bool blendTrilight = true)
    {
        Trilight trilight = new Trilight();

        trilight.sky     = lightingDefinition.AmbientSkyColor;
        trilight.equator = lightingDefinition.AmbientEquatorColor;
        trilight.ground  = lightingDefinition.AmbientGroundColor;
        Trilight trilight2 = trilight;
        LightingDefinitionOverride lightingDefinitionOverride = UnityEngine.Object.FindObjectOfType <LightingDefinitionOverride>();

        if (lightingDefinitionOverride != null && lightingDefinitionOverride.TrilightOverrides != null)
        {
            for (int i = 0; i < lightingDefinitionOverride.TrilightOverrides.Length; i++)
            {
                if (lightingDefinitionOverride.TrilightOverrides[i].LightingDef.Id == lightingDefinition.Id)
                {
                    trilight2.sky     = lightingDefinitionOverride.TrilightOverrides[i].Trilight.sky;
                    trilight2.equator = lightingDefinitionOverride.TrilightOverrides[i].Trilight.equator;
                    trilight2.ground  = lightingDefinitionOverride.TrilightOverrides[i].Trilight.ground;
                    break;
                }
            }
        }
        setTrilight(trilight2, blendTrilight);
        setSkybox(lightingDefinition.SkyboxMaterialKey);
    }
        public static Trilight FromSettings()
        {
            Trilight trilight = new Trilight();

            trilight.sky     = RenderSettings.ambientSkyColor;
            trilight.equator = RenderSettings.ambientEquatorColor;
            trilight.ground  = RenderSettings.ambientGroundColor;
            return(trilight);
        }
    private IEnumerator fadeColors(Trilight srcColors, Trilight dstColors)
    {
        float elapsed = 0f;

        do
        {
            yield return(null);

            elapsed += Time.deltaTime;
            float t = Mathf.Clamp01(elapsed / 2f);
            RenderSettings.ambientSkyColor     = Color.Lerp(srcColors.sky, dstColors.sky, t);
            RenderSettings.ambientEquatorColor = Color.Lerp(srcColors.equator, dstColors.equator, t);
            RenderSettings.ambientGroundColor  = Color.Lerp(srcColors.ground, dstColors.ground, t);
        }while (elapsed < 2f);
    }
 private void setTrilight(Trilight destionColors, bool blendTrilight)
 {
     StopAllCoroutines();
     if (blendTrilight)
     {
         Trilight srcColors = Trilight.FromSettings();
         StartCoroutine(fadeColors(srcColors, destionColors));
     }
     else
     {
         RenderSettings.ambientSkyColor     = destionColors.sky;
         RenderSettings.ambientEquatorColor = destionColors.equator;
         RenderSettings.ambientGroundColor  = destionColors.ground;
     }
 }