Example #1
0
        protected virtual void OnDestroy()
        {
            Shader.SetGlobalColor("WeatherColor", Color.white);
            Shader.SetGlobalColor("WeatherSpecularColor", Color.white);

            if (rainParms != null)
            {
                rainParms.OnDestroy();
                snowParms.OnDestroy();
                fineParms.OnDestroy();

                rainParms = null;
                snowParms = null;
                fineParms = null;
            }
        }
Example #2
0
        protected virtual IEnumerator changeWeather(WeatherType newWeatherType)
        {
            if (currentWeathTypeParm != null)
            {
                currentWeathTypeParm.sleep();
                currentWeathTypeParm = null;
            }

            float startTime = Time.time;
            float deltaTime = Time.time - startTime;

            while (deltaTime <= changeWeatherTime)
            {
                float v = deltaTime / changeWeatherTime;
                Shader.SetGlobalFloat("WeatherConver", 1.0f - v);
                if (OldWeatherType == WeatherType.Rain)
                {
                    _currentRainColor = Color.Lerp(_rainColor, Color.white, v);
                }
                yield return(null);

                deltaTime = Time.time - startTime;
            }

            Shader.SetGlobalFloat("WeatherConver", 0);
            Shader.DisableKeyword("_SNOW_ON");
            Shader.DisableKeyword("_RAIN_ON");

            switch (newWeatherType)
            {
            case WeatherType.Rain:
                Shader.EnableKeyword("_RAIN_ON");
                currentWeathTypeParm = rainParms;
                break;

            case WeatherType.Snow:
                Shader.EnableKeyword("_SNOW_ON");
                currentWeathTypeParm = snowParms;
                break;

            case WeatherType.Fine:
                Shader.DisableKeyword("_SNOW_ON");
                Shader.DisableKeyword("_RAIN_ON");
                currentWeathTypeParm = fineParms;
                break;
            }

            if (currentWeathTypeParm != null)
            {
                currentWeathTypeParm.awake();
            }

            startTime = Time.time;
            deltaTime = Time.time - startTime;
            while (deltaTime <= changeWeatherTime)
            {
                float v = deltaTime / changeWeatherTime;
                _oldGloss = Mathf.Lerp(_oldGloss, currentWeathTypeParm.Gloss, v);
                Shader.SetGlobalFloat("Gloss", _oldGloss);
                Shader.SetGlobalFloat("WeatherConver", v);
                if (newWeatherType == WeatherType.Rain)
                {
                    _currentRainColor = Color.Lerp(Color.white, _rainColor, v);
                }
                _oldForgColor                  = Color.Lerp(_oldForgColor, currentWeathTypeParm.forgColor, v);
                RenderSettings.fogColor        = _oldForgColor;
                RenderSettings.ambientSkyColor = _oldForgColor;
                if (RenderSettings.skybox != null)
                {
                    RenderSettings.skybox.color = _oldForgColor;
                }

                yield return(null);

                deltaTime = Time.time - startTime;
            }
            changeWeatherCoroutine = null;
        }