Ejemplo n.º 1
0
 private void setLightValues(lightParameters p)
 {
     RenderSettings.sun.color           = p.sunColor;
     RenderSettings.ambientSkyColor     = p.skyColor;
     RenderSettings.ambientEquatorColor = p.horizonColor;
     RenderSettings.ambientGroundColor  = p.groundColor;
 }
Ejemplo n.º 2
0
 private void setLightValues(lightParameters p)
 {
     RenderSettings.sun.color           = p.sunColor;
     RenderSettings.ambientSkyColor     = p.skyColor;
     RenderSettings.ambientEquatorColor = p.horizonColor;
     RenderSettings.ambientGroundColor  = p.groundColor;
     RenderSettings.skybox = skyboxMat;
     //float t = p.sunColor.grayscale;
     //RenderSettings.skybox.SetColor("_Tint", new Color(t, t, t));
 }
Ejemplo n.º 3
0
 public static lightParameters copy(lightParameters o)
 {
     return(new lightParameters
     {
         skyColor = o.skyColor,
         horizonColor = o.horizonColor,
         groundColor = o.groundColor,
         sunColor = o.sunColor
     });
 }
Ejemplo n.º 4
0
    private lightParameters lightLerp(lightParameters p1, lightParameters p2, float f)
    {
        lightParameters ret = new lightParameters
        {
            groundColor  = Color.Lerp(p1.groundColor, p2.groundColor, f),
            skyColor     = Color.Lerp(p1.skyColor, p2.skyColor, f),
            horizonColor = Color.Lerp(p1.horizonColor, p2.horizonColor, f),
            sunColor     = Color.Lerp(p1.sunColor, p2.sunColor, f)
        };

        return(ret);
    }
Ejemplo n.º 5
0
    private lightParameters lightLerp(lightParameters p1, lightParameters p2, float f)
    {
        lightParameters ret = new lightParameters
        {
            groundColor  = Color.Lerp(p1.groundColor, p2.groundColor, f),
            skyColor     = Color.Lerp(p1.skyColor, p2.skyColor, f),
            horizonColor = Color.Lerp(p1.horizonColor, p2.horizonColor, f),
            sunColor     = Color.Lerp(p1.sunColor, p2.sunColor, f)
        };

        skyboxMat.SetTexture("_Tex", p1.skyboxTexture);
        skyboxMat.SetTexture("_OverlayTex", p2.skyboxTexture);
        skyboxMat.SetFloat("_Blend", f);
        return(ret);
    }
    void Update()
    {
        if (sun == null)
        {
            if (RenderSettings.sun != null)
            {
                sun = RenderSettings.sun;
            }
            else
            {
                sun = new Light();
            }
        }

        sun.transform.rotation = Quaternion.Euler((currentHour / 24.0f) * 360.0f - 90.0f, 0, 0);

        if (!freezeTimeOfDay)
        {
            float gameHourPerRealSeconds = 24.0f / cycleDurationSeconds;
            currentHour += Time.deltaTime * gameHourPerRealSeconds;
        }

        while (currentHour >= 24.0f)
        {
            currentHour -= 24.0f;
        }

        float morning = (sunRiseBegin + sunRiseEnd) / 2.0f;
        float evening = (sunSetBegin + sunSetEnd) / 2.0f;

        if (currentHour < sunRiseBegin)
        {
            if (phase != Phase.Night)
            {
                phase = Phase.Night;
                DayNightEvents.Instance.night();
            }
            lparams = lightLerp(nightSky, nightSky, 0f);
            //lparams = lightParameters.copy(nightSky);
        }
        else if (currentHour < morning)
        {
            if (phase != Phase.Sunrise)
            {
                phase = Phase.Sunrise;
                DayNightEvents.Instance.sunRise();
            }

            float f = Mathf.InverseLerp(sunRiseBegin, morning, currentHour);
            lparams = lightLerp(nightSky, morningSky, f);
        }
        else if (currentHour < sunRiseEnd)
        {
            if (phase != Phase.Sunrise)
            {
                phase = Phase.Sunrise;
                DayNightEvents.Instance.sunRise();
            }

            float f = Mathf.InverseLerp(morning, sunRiseEnd, currentHour);
            lparams = lightLerp(morningSky, daySky, f);
        }
        else if (currentHour < sunSetBegin)
        {
            if (phase != Phase.Day)
            {
                phase = Phase.Day;
                DayNightEvents.Instance.day();
            }

            lparams = lightLerp(daySky, daySky, 0f);
            //lparams = lightParameters.copy(daySky);
        }
        else if (currentHour < evening)
        {
            if (phase != Phase.Sunset)
            {
                phase = Phase.Sunset;
                DayNightEvents.Instance.sunSet();
            }

            float f = Mathf.InverseLerp(sunSetBegin, evening, currentHour);
            lparams = lightLerp(daySky, eveningSky, f);
        }
        else if (currentHour < sunSetEnd)
        {
            if (phase != Phase.Sunset)
            {
                phase = Phase.Sunset;
                DayNightEvents.Instance.sunSet();
            }

            float f = Mathf.InverseLerp(evening, sunSetEnd, currentHour);
            lparams = lightLerp(eveningSky, nightSky, f);
        }
        else
        {
            if (phase != Phase.Night)
            {
                phase = Phase.Night;
                DayNightEvents.Instance.night();
            }

            lparams = lightLerp(nightSky, nightSky, 0f);
            //lparams = lightParameters.copy(nightSky);
        }

        sun.intensity = originalSunIntensity;
        foreach (var item in atmosphericEffects)
        {
            item.filterSkyParams(lparams, sun);
        }

        setLightValues(lparams);

        if (!freezeTimeOfDay)
        {
            timeOfDaySlider.value = currentHour;
        }

        //Debug.Log($"Phase : {phase}");
    }