Esempio n. 1
0
        public void WeatherProfileChanged(WeatherMakerProfileScript oldProfile, WeatherMakerProfileScript newProfile, float transitionDelay, float transitionDuration)
        {
            Precipitation               = newProfile.PrecipitationProfile.PrecipitationType;
            PrecipitationChangeDelay    = transitionDelay;
            PrecipitationChangeDuration = transitionDuration;
            PrecipitationIntensity      = newProfile.PrecipitationProfile.IntensityRange.Random();
            nextIntensityChangeSeconds  = (newProfile.PrecipitationProfile.IntensityRangeDuration.Maximum <= 0.0f ? 0.0f : newProfile.PrecipitationProfile.IntensityRangeDuration.Random());
            nextIntensityChangeRange    = newProfile.PrecipitationProfile.IntensityRange;
            nextIntensityDurationRange  = newProfile.PrecipitationProfile.IntensityRangeDuration;
            Color      oldPrecipitationTintColor          = precipitationTintColor;
            Color      oldPrecipitationMistTintColor      = precipitationMistTintColor;
            Color      oldPecipitationSecondaryTintColor  = precipitationSecondaryTintColor;
            Color      newPrecipitationTintColor          = newProfile.PrecipitationProfile.PrecipitationTintColor;
            Color      newPrecipitationMistTintColor      = newProfile.PrecipitationProfile.PrecipitationMistTintColor;
            Color      newPrecipitationSecondaryTintColor = newProfile.PrecipitationProfile.PrecipitationSecondaryTintColor;
            FloatTween tween = TweenFactory.Tween("WeatherMakerPrecipitation_" + GetInstanceID(), 0.0f, 1.0f, transitionDuration, TweenScaleFunctions.Linear, (ITween <float> c) =>
            {
                float progress                  = c.CurrentValue;
                precipitationTintColor          = Color.Lerp(oldPrecipitationTintColor, newPrecipitationTintColor, progress);
                precipitationMistTintColor      = Color.Lerp(oldPrecipitationMistTintColor, newPrecipitationMistTintColor, progress);
                precipitationSecondaryTintColor = Color.Lerp(oldPecipitationSecondaryTintColor, newPrecipitationSecondaryTintColor, progress);
            });

            tween.Delay = transitionDelay;
        }
        /// <summary>
        /// Start and add a float tween
        /// </summary>
        /// <param name="obj">Game object</param>
        /// <param name="key">Key</param>
        /// <param name="start">Start value</param>
        /// <param name="end">End value</param>
        /// <param name="duration">Duration in seconds</param>
        /// <param name="scaleFunc">Scale function</param>
        /// <param name="progress">Progress handler</param>
        /// <param name="completion">Completion handler</param>
        /// <returns>FloatTween</returns>
        public static FloatTween Tween(this GameObject obj, object key, float start, float end, float duration, Func <float, float> scaleFunc, System.Action <ITween <float> > progress, System.Action <ITween <float> > completion = null)
        {
            FloatTween t = TweenFactory.Tween(key, start, end, duration, scaleFunc, progress, completion);

            t.GameObject = obj;
            t.Renderer   = obj.GetComponent <Renderer>();
            return(t);
        }
Esempio n. 3
0
        /// <summary>
        /// Start and add a float tween
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="start">Start value</param>
        /// <param name="end">End value</param>
        /// <param name="duration">Duration in seconds</param>
        /// <param name="scaleFunc">Scale function</param>
        /// <param name="progress">Progress handler</param>
        /// <param name="completion">Completion handler</param>
        /// <returns>FloatTween</returns>
        public static FloatTween Tween(object key, float start, float end, float duration, Func <float, float> scaleFunc, System.Action <ITween <float> > progress, System.Action <ITween <float> > completion = null)
        {
            FloatTween t = new FloatTween();

            t.Key = key;
            t.Start(start, end, duration, scaleFunc, progress, completion);
            AddTween(t);

            return(t);
        }
Esempio n. 4
0
        /// <summary>
        /// Weather profile changed for thunder and lightning
        /// </summary>
        /// <param name="oldProfile">Old profile</param>
        /// <param name="newProfile">New profile</param>
        /// <param name="transitionDelay">Transition delay</param>
        /// <param name="transitionDuration">Transition duration</param>
        public void WeatherProfileChanged(WeatherMakerProfileScript oldProfile, WeatherMakerProfileScript newProfile, float transitionDelay, float transitionDuration)
        {
            FloatTween tween = TweenFactory.Tween("WeatherMakerScriptProfileChangeLightning", 0.0f, 1.0f, 0.01f, TweenScaleFunctions.Linear, null, (completion) =>
            {
                ThunderAndLightningScript.LightningIntenseProbability          = newProfile.LightningProfile.LightningIntenseProbability;
                ThunderAndLightningScript.LightningIntervalTimeRange           = newProfile.LightningProfile.LightningIntervalTimeRange;
                ThunderAndLightningScript.LightningForcedVisibilityProbability = newProfile.LightningProfile.LightningForcedVisibilityProbability;
                ThunderAndLightningScript.GroundLightningChance = newProfile.LightningProfile.LightningGroundChance;
                ThunderAndLightningScript.CloudLightningChance  = newProfile.LightningProfile.LightningCloudChance;
                ThunderAndLightningScript.EnableLightning       = (newProfile.LightningProfile.LightningIntervalTimeRange.Minimum > 0.0f);
            });

            tween.Delay = transitionDelay;
        }
Esempio n. 5
0
        private void TweenScript(WeatherMakerFallingParticleScript script, float end)
        {
            if (PrecipitationChangeDuration < 0.1f)
            {
                script.Intensity = end;
                return;
            }

            float      duration = (Mathf.Abs(script.Intensity - end) < PrecipitationChangeThreshold ? 0.0f : PrecipitationChangeDuration);
            FloatTween tween    = TweenFactory.Tween("WeatherMakerPrecipitationChange_" + script.gameObject.GetInstanceID(), script.Intensity, end, duration, TweenScaleFunctions.Linear, (t) =>
            {
                // Debug.LogFormat("Tween key: {0}, value: {1}, prog: {2}", t.Key, t.CurrentValue, t.CurrentProgress);
                script.Intensity = t.CurrentValue;
            });

            tween.Delay = PrecipitationChangeDelay;
        }
Esempio n. 6
0
        /// <summary>
        /// Create a new fog profile and begin animating to the new profile settings
        /// </summary>
        /// <param name="toProfile">New fog profile to transition to</param>
        /// <param name="transitionDelay">Transition delay in seconds</param>
        /// <param name="transitionDuration">Transition duration in seconds</param>
        /// <param name="newDensity">Density for the new profile or null to use profile density</param>
        /// <param name="tweenKey">Tween key</param>
        /// <returns>The newly created fog profile that is being transitioned to (a copy of toProfile)</returns>
        public virtual T ShowFogAnimated(T toProfile, float transitionDelay, float transitionDuration, float?newDensity = null, string tweenKey = null)
        {
            if (FogProfile == null)
            {
                Debug.LogError("Fog profile needs to be set before ShowFogAnimated can be called");
                return(null);
            }

            T toProfileInstance = ScriptableObject.Instantiate(toProfile);

            if (newDensity != null)
            {
                toProfileInstance.FogDensity = newDensity.Value;
            }
            FogProfile.CopyStateTo(toProfileInstance);
            tweenKey = (tweenKey ?? string.Empty);

            // animate density, color and noise properties, just leave the rest at final values

            // cleanup old profile if it was temporary
            T oldProfile = FogProfile;

            FogProfile = toProfileInstance;

            // make copies of final value for animatable properties
            float   newFogDensity               = toProfileInstance.FogDensity;
            float   newFogFactorMultiplier      = toProfileInstance.FogFactorMultiplier;
            Color   newFogColor                 = toProfileInstance.FogColor;
            Color   newFogEmissionColor         = toProfileInstance.FogEmissionColor;
            float   newFogLightAbsorption       = toProfileInstance.FogLightAbsorption;
            float   newMaxFogFactor             = toProfileInstance.MaxFogFactor;
            int     newFogNoiseSampleCount      = toProfileInstance.FogNoiseSampleCount;
            float   newFogNoiseAdder            = toProfileInstance.FogNoiseAdder;
            float   newFogNoiseMultiplier       = toProfileInstance.FogNoiseMultiplier;
            float   newFogNoiseScale            = toProfileInstance.FogNoiseScale;
            Vector3 newFogNoiseVelocity         = toProfileInstance.FogNoiseVelocity;
            Vector4 newFogNoiseVelocityRotation = toProfileInstance.FogNoiseVelocityRotation;
            float   newFogShadowBrightness      = toProfileInstance.FogShadowBrightness;
            float   newFogShadowDecay           = toProfileInstance.FogShadowDecay;
            float   newFogShadowDither          = toProfileInstance.FogShadowDither;
            float   newFogShadowMaxRayLength    = toProfileInstance.FogShadowMaxRayLength;
            float   newFogShadowMultiplier      = toProfileInstance.FogShadowMultiplier;
            float   newFogShadowPower           = toProfileInstance.FogShadowPower;
            int     newFogShadowSampleCount     = toProfileInstance.FogShadowSampleCount;
            float   newDitherLevel              = toProfileInstance.DitherLevel;

            float oldFogDensity          = oldProfile.FogDensity;
            float oldFogFactorMultiplier = oldProfile.FogFactorMultiplier;
            T     transitionFromProfile  = (oldFogDensity == 0.0f ? toProfileInstance : oldProfile);
            bool  newProfileHasNoise     = toProfileInstance.HasNoise;
            bool  oldProfileHasNoise     = oldProfile.HasNoise;
            bool  bothProfileHaveNoise   = newProfileHasNoise && oldProfileHasNoise;
            bool  transitionShadow       = (oldProfile.FogShadowSampleCount > 0 && toProfileInstance.FogShadowSampleCount > 0);

            // transition to a new profile without noise, copy old profile noise settings
            if (oldProfileHasNoise && !newProfileHasNoise)
            {
                toProfileInstance.FogNoiseVelocity         = transitionFromProfile.FogNoiseVelocity;
                toProfileInstance.FogNoiseVelocityRotation = transitionFromProfile.FogNoiseVelocityRotation;
                toProfileInstance.FogNoiseAdder            = transitionFromProfile.FogNoiseAdder;
                toProfileInstance.FogNoiseMultiplier       = transitionFromProfile.FogNoiseMultiplier;
                toProfileInstance.FogNoiseSampleCount      = transitionFromProfile.FogNoiseSampleCount;
                toProfileInstance.FogNoiseScale            = transitionFromProfile.FogNoiseScale;
            }

            FloatTween tween = TweenFactory.Tween("WeatherMakerFogScript_" + GetInstanceID() + tweenKey, 0.0f, 1.0f, transitionDuration, TweenScaleFunctions.Linear, (ITween <float> c) =>
            {
                float progress = c.CurrentValue;
                toProfileInstance.FogDensity          = Mathf.Lerp(oldFogDensity, newFogDensity, progress);
                toProfileInstance.FogFactorMultiplier = Mathf.Lerp(oldFogFactorMultiplier, newFogFactorMultiplier, progress);
                toProfileInstance.FogColor            = Color.Lerp(transitionFromProfile.FogColor, newFogColor, progress);
                toProfileInstance.FogEmissionColor    = Color.Lerp(transitionFromProfile.FogEmissionColor, newFogEmissionColor, progress);
                toProfileInstance.FogLightAbsorption  = Mathf.Lerp(transitionFromProfile.FogLightAbsorption, newFogLightAbsorption, progress);
                toProfileInstance.MaxFogFactor        = Mathf.Lerp(transitionFromProfile.MaxFogFactor, newMaxFogFactor, progress);
                toProfileInstance.DitherLevel         = Mathf.Lerp(transitionFromProfile.DitherLevel, newDitherLevel, progress);

                // if both profiles have fog noise, animate noise
                if (bothProfileHaveNoise)
                {
                    toProfileInstance.FogNoiseVelocity         = Vector3.Lerp(transitionFromProfile.FogNoiseVelocity, newFogNoiseVelocity, progress);
                    toProfileInstance.FogNoiseVelocityRotation = Vector4.Lerp(transitionFromProfile.FogNoiseVelocityRotation, newFogNoiseVelocityRotation, progress);
                    toProfileInstance.FogNoiseAdder            = Mathf.Lerp(transitionFromProfile.FogNoiseAdder, newFogNoiseAdder, progress);
                    toProfileInstance.FogNoiseMultiplier       = Mathf.Lerp(transitionFromProfile.FogNoiseMultiplier, newFogNoiseMultiplier, progress);
                    toProfileInstance.FogNoiseSampleCount      = (int)Mathf.Lerp(transitionFromProfile.FogNoiseSampleCount, newFogNoiseSampleCount, progress);
                    toProfileInstance.FogNoiseScale            = Mathf.Lerp(transitionFromProfile.FogNoiseScale, newFogNoiseScale, progress);
                }
                // if only new profile has noise, animate to noise from no noise
                else if (newProfileHasNoise)
                {
                    toProfileInstance.fogNoisePercent = progress;
                }
                // if only old profile has noise, animate from noise to no noise
                else if (oldProfileHasNoise)
                {
                    toProfileInstance.fogNoisePercent = 1.0f - progress;
                }

                if (transitionShadow)
                {
                    toProfileInstance.FogShadowBrightness   = Mathf.Lerp(transitionFromProfile.FogShadowBrightness, newFogShadowBrightness, progress);
                    toProfileInstance.FogShadowDecay        = Mathf.Lerp(transitionFromProfile.FogShadowDecay, newFogShadowDecay, progress);
                    toProfileInstance.FogShadowDither       = Mathf.Lerp(transitionFromProfile.FogShadowDither, newFogShadowDither, progress);
                    toProfileInstance.FogShadowMaxRayLength = Mathf.Lerp(transitionFromProfile.FogShadowMaxRayLength, newFogShadowMaxRayLength, progress);
                    toProfileInstance.FogShadowMultiplier   = Mathf.Lerp(transitionFromProfile.FogShadowMultiplier, newFogShadowMultiplier, progress);
                    toProfileInstance.FogShadowPower        = Mathf.Lerp(transitionFromProfile.FogShadowPower, newFogShadowPower, progress);
                    toProfileInstance.FogShadowSampleCount  = (int)Mathf.Lerp(transitionFromProfile.FogShadowSampleCount, newFogShadowSampleCount, progress);
                }
                // note do not animate the dither magic property!
            }, (ITween <float> c) =>
            {
                // if the old profile was a clone, clean it up
                if (oldProfile.name.IndexOf("clone", System.StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    GameObject.Destroy(oldProfile);
                }

                // if new profile has no noise and old profile had noise, disable noise by setting noise multiplier to 0 (save performance).
                if (oldProfileHasNoise && !newProfileHasNoise)
                {
                    toProfileInstance.FogNoiseMultiplier = 0.0f;
                }
            });

            tween.Delay = transitionDelay;
            return(toProfileInstance);
        }
Esempio n. 7
0
        private void AnimateWindChange(WeatherMakerWindProfileScript newProfile, float transitionDelay, float transitionDuration)
        {
            // update to new wind
            WeatherMakerWindProfileScript oldProfile = WindProfile;

            newProfile  = newProfile ?? WindProfile;
            WindProfile = newProfile;

            // pick the next time to change
            windNextChangeTime = WindProfile.WindChangeInterval.Random();

            // previous values...
            float      oldWindIntensity  = WindIntensity;
            float      oldTurbulence     = WindZone.windTurbulence;
            float      oldPulseMagnitude = WindZone.windPulseMagnitude;
            float      oldPulseFrequency = WindZone.windPulseFrequency;
            Quaternion oldWindDirection  = WindZone.transform.rotation;

            // animate to new values...
            float newWindIntensity = WindIntensity;

            if (WindProfile.AutoWindIntensity)
            {
                newWindIntensity = (WindProfile.WindSpeedRange.Maximum <= 0.0f ? 0.0f : WindProfile.WindSpeedRange.Random() / WindProfile.WindSpeedRange.Maximum);
            }
            float      newTurbulence     = WindProfile.WindTurbulenceRange.Random();
            float      newPulseMagnitude = WindProfile.WindPulseMagnitudeRange.Random();
            float      newPulseFrequency = WindProfile.WindPulseFrequencyRange.Random();
            Quaternion newWindDirection  = oldWindDirection;

            // if random wind, pick a new direction from wind
            if (RandomWindDirection)
            {
                // 2D is set immediately
                switch (WeatherMakerScript.ResolveCameraMode())
                {
                case CameraMode.OrthographicXY:
                case CameraMode.OrthographicXZ:
                    int val = UnityEngine.Random.Range(0, 2);
                    newWindDirection = Quaternion.Euler(0.0f, -90.0f + (180.0f * val), 0.0f);
                    break;

                default:
                    // 3D is lerped over time
                    float xAxis = (WindProfile.AllowBlowUp ? UnityEngine.Random.Range(-30.0f, 30.0f) : 0.0f);
                    newWindDirection = Quaternion.Euler(xAxis, UnityEngine.Random.Range(0.0f, 360.0f), 0.0f);
                    break;
                }
            }

            FloatTween tween = TweenFactory.Tween("WeatherMakerWindScript_" + GetInstanceID(), 0.0f, 1.0f, transitionDuration, TweenScaleFunctions.Linear, (t) =>
            {
                WindIntensity               = Mathf.Lerp(oldWindIntensity, newWindIntensity, t.CurrentValue);
                WindZone.windTurbulence     = Mathf.Lerp(oldTurbulence, newTurbulence, t.CurrentValue);
                WindZone.windPulseFrequency = Mathf.Lerp(oldPulseMagnitude, newPulseMagnitude, t.CurrentValue);
                WindZone.windPulseMagnitude = Mathf.Lerp(oldPulseFrequency, newPulseFrequency, t.CurrentValue);
                WindZone.transform.rotation = Quaternion.Lerp(oldWindDirection, newWindDirection, t.CurrentValue);
            }, (t) =>
            {
                // if the old profile was a clone, clean it up
                if (oldProfile.name.IndexOf("(clone)", System.StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    GameObject.Destroy(oldProfile);
                }
            });

            tween.Delay = transitionDelay;
        }
Esempio n. 8
0
        private void UpdateWeatherProfile()
        {
            if (_WeatherProfile == null || _WeatherProfile.Disabled)
            {
                return;
            }
            float transitionDuration = _WeatherProfile.TransitionDuration.Random();

            CloudChangeDuration = transitionDuration;
            Clouds = _WeatherProfile.CloudType;
            if (CloudScript != null)
            {
                Vector2 newCloudVelocity = UnityEngine.Random.insideUnitCircle * _WeatherProfile.CloudSpeed.Random();
                TweenFactory.Tween("WeatherMakerScriptProfileChangeCloudVelocity", CloudScript.CloudNoiseVelocity, newCloudVelocity, transitionDuration, TweenScaleFunctions.Linear, (progress) =>
                {
                    CloudScript.CloudNoiseVelocity = progress.CurrentValue;
                });
            }
            Precipitation               = _WeatherProfile.Precipitation;
            PrecipitationIntensity      = _WeatherProfile.PrecipitationIntensity;
            PrecipitationChangeDuration = transitionDuration * 0.5f;
            if (Clouds == WeatherMakerCloudType.None)
            {
                PrecipitationChangeDelay = 0.0f;
            }
            else
            {
                PrecipitationChangeDelay = transitionDuration * 0.5f;
            }
            if (FogScript != null)
            {
                FogScript.FogMode = WeatherMakerFogMode.Linear;
                FogScript.TransitionFogDensity(FogScript.FogDensity, _WeatherProfile.FogDensity, CloudChangeDuration);
                FogScript.FogHeight = _WeatherProfile.FogHeight;
            }
            if (WindScript != null)
            {
                WindScript.AnimateWindIntensity(_WeatherProfile.WindIntensity, transitionDuration);
                WindScript.WindMaximumChangeRotation = _WeatherProfile.WindMaximumChangeRotation;
                WindScript.WindMainMultiplier        = _WeatherProfile.WindMainMultiplier;
            }
            if (LightningScript != null)
            {
                FloatTween t = TweenFactory.Tween("WeatherMakerScriptProfileChangeLightning", 0.0f, 0.0f, 0.01f, TweenScaleFunctions.Linear, null, (completion) =>
                {
                    LightningScript.LightningIntenseProbability          = _WeatherProfile.LightningIntenseProbability;
                    LightningScript.LightningIntervalTimeRange           = _WeatherProfile.LightningIntervalTimeRange;
                    LightningScript.LightningForcedVisibilityProbability = _WeatherProfile.LightningForcedVisibilityProbability;
                    LightningScript.GroundLightningChance = _WeatherProfile.LightningGroundChance;
                    LightningScript.CloudLightningChance  = _WeatherProfile.LightningCloudChance;
                    LightningScript.EnableLightning       = _WeatherProfile.LightningEnabled;
                });
                t.Delay = PrecipitationChangeDelay;
            }
            GameObject player = GameObject.FindGameObjectWithTag("Player");

            if (player != null)
            {
                WeatherMakerSoundZoneScript soundZone = player.GetComponent <WeatherMakerSoundZoneScript>();
                if (soundZone != null)
                {
                    soundZone.Sounds.Clear();
                    soundZone.Sounds.AddRange(_WeatherProfile.Sounds);
                }
            }
        }