Exemple #1
0
        private void UpdateWind()
        {
            // should never happen but Unity editor does weird stuff
            if (AudioSourceWind == null)
            {
                return;
            }

            if (WindProfile != null && (WindIntensity > 0.0f || WindProfile.AutoWindIntensity) && ExternalIntensityMultiplier > 0.0f &&
                WindProfile.WindSpeedRange.Maximum > 0.0f && WindProfile.WindMainMultiplier > 0.0f)
            {
                // check for wind change
                if (WindProfile.WindChangeInterval.Maximum > 0.0f && (windNextChangeTime -= Time.deltaTime) <= 0.0f)
                {
                    AudioSourceWind.AudioSource.clip = (WindProfile.WindAudioClip == null ? AudioSourceWind.AudioSource.clip : WindProfile.WindAudioClip);
                    AnimateWindChange(null, 0.0f, WindProfile.WindChangeDuration.Random());
                }

                // determine wind intensity
                WindZone.windMain = WindProfile.WindSpeedRange.Maximum * WindIntensity * WindProfile.WindMainMultiplier * ExternalIntensityMultiplier;

                // update wind audio if wind intensity changed
                if (WindZone.windMain != lastWindIntensity)
                {
                    AudioSourceWind.Play(WindIntensity * WindProfile.WindSoundMultiplier);
                }
                lastWindIntensity = WindZone.windMain;

                Vector3 newVelocity     = WindZone.transform.forward * WindZone.windMain;
                bool    velocityChanged = newVelocity != CurrentWindVelocity;
                CurrentWindVelocity = newVelocity;
                if (velocityChanged && WindChanged != null)
                {
                    WindChanged(newVelocity);
                }
            }
            else
            {
                AudioSourceWind.Stop();
                WindZone.windMain   = WindZone.windTurbulence = WindZone.windPulseFrequency = WindZone.windPulseMagnitude = 0.0f;
                CurrentWindVelocity = Vector3.zero;
            }
            AudioSourceWind.VolumeModifier = WeatherMakerAudioManagerScript.CachedWeatherVolumeModifier;
            AudioSourceWind.Update();
        }
        private void UpdateWind()
        {
            // put wind on top of camera
            if (WeatherMakerScript.Instance.Camera != null)
            {
                WindZone.transform.position = WeatherMakerScript.Instance.Camera.transform.position;
                if (!WeatherMakerScript.Instance.CameraIsOrthographic)
                {
                    WindZone.transform.Translate(0.0f, WindZone.radius, 0.0f);
                }
            }

            if (WindIntensity > 0.0f && MaximumWindSpeed > 0.0f && WindMainMultiplier > 0.0f)
            {
                WindZone.windMain = MaximumWindSpeed * WindIntensity * WindMainMultiplier;

                // update wind audio if wind intensity changed
                if (WindZone.windMain != lastWindIntensity)
                {
                    AudioSourceWind.Play(WindIntensity * WindSoundMultiplier);
                }
                lastWindIntensity = WindZone.windMain;

                // check for wind change
                if (windNextChangeTime <= Time.time)
                {
                    // update to new wind
                    windNextChangeTime = Time.time + WindChangeInterval.Random();
                    windChangeTotal    = 0.0f;
                    if (WindChangeInterval.Minimum > 0.0f && WindChangeInterval.Maximum >= WindChangeInterval.Minimum)
                    {
                        if (WindTurbulenceRange.Maximum > 0.0f)
                        {
                            WindZone.windTurbulence = WindTurbulenceRange.Random();
                        }
                        if (WindPulseMagnitudeRange.Maximum > 0.0f)
                        {
                            WindZone.windPulseMagnitude = WindPulseMagnitudeRange.Random();
                        }
                        if (WindPulseFrequencyRange.Maximum > 0.0f)
                        {
                            WindZone.windPulseFrequency = WindPulseFrequencyRange.Random();
                        }
                    }

                    // if random wind, pick a new direction from wind
                    if (RandomWindDirection)
                    {
                        // 2D is set immediately
                        if (WeatherMakerScript.Instance.CameraIsOrthographic)
                        {
                            int val = UnityEngine.Random.Range(0, 2);
                            WindZone.transform.rotation = Quaternion.Euler(0.0f, -90.0f + (180.0f * val), 0.0f);
                        }
                        // 3D is lerped over time
                        else
                        {
                            float xAxis = (AllowBlowUp ? UnityEngine.Random.Range(-30.0f, 30.0f) : 0.0f);
                            windChangeRotationStart = WindZone.transform.rotation;
                            windChangeRotationEnd   = Quaternion.Euler(xAxis, UnityEngine.Random.Range(0.0f, 360.0f), 0.0f);
                            windChangeElapsed       = 0.0f;
                            windChangeTotal         = WindChangeRotationDurationPercent.Random() * (windNextChangeTime - Time.time);
                        }
                    }
                    // else use the WindZone transform rotation as is
                }
                // no change, update lerp for wind direction if needed
                else if (windChangeTotal != 0.0f)
                {
                    WindZone.transform.rotation = Quaternion.Lerp(windChangeRotationStart, windChangeRotationEnd, windChangeElapsed / windChangeTotal);
                    windChangeElapsed           = Mathf.Min(windChangeTotal, windChangeElapsed + Time.deltaTime);
                }
                Vector3 newVelocity     = WindZone.transform.forward * WindZone.windMain;
                bool    velocityChanged = newVelocity != CurrentWindVelocity;
                CurrentWindVelocity = newVelocity;
                if (velocityChanged && WindChanged != null)
                {
                    WindChanged(newVelocity);
                }
                if (FogVelocityMultiplier != 0.0f && WeatherMakerScript.Instance.FogScript != null && WeatherMakerScript.Instance.FogScript.FogProfile != null)
                {
                    WeatherMakerScript.Instance.FogScript.FogProfile.FogNoiseVelocity = CurrentWindVelocity * FogVelocityMultiplier;
                }
            }
            else
            {
                AudioSourceWind.Stop();
                WindZone.windMain   = WindZone.windTurbulence = WindZone.windPulseFrequency = WindZone.windPulseMagnitude = 0.0f;
                CurrentWindVelocity = Vector3.zero;
            }
            AudioSourceWind.Update();
        }
 private void UpdateWind()
 {
     if (WindIntensity > 0.0f)
     {
         WindZone.windMain = MaximumWindSpeed * WindIntensity * WindMainMultiplier;
         if (WindTurbulenceRange.Maximum > 0.0f || WindPulseMagnitudeRange.Maximum > 0.0f ||
             WindPulseFrequencyRange.Maximum > 0.0f || WindDirection != lastWindDirection)
         {
             lastWindDirection = WindDirection = WindDirection.normalized;
             if (WeatherScript.Camera != null)
             {
                 WindZone.transform.position = WeatherScript.Camera.transform.position;
                 if (!WeatherScript.Camera.orthographic)
                 {
                     WindZone.transform.Translate(0.0f, WindZone.radius, 0.0f);
                 }
             }
             if (nextWindTime < Time.time)
             {
                 if (WindTurbulenceRange.Maximum > 0.0f)
                 {
                     WindZone.windTurbulence = WindTurbulenceRange.Random();
                 }
                 if (WindPulseMagnitudeRange.Maximum > 0.0f)
                 {
                     WindZone.windPulseMagnitude = WindPulseMagnitudeRange.Random();
                 }
                 if (WindPulseFrequencyRange.Maximum > 0.0f)
                 {
                     WindZone.windPulseFrequency = WindPulseFrequencyRange.Random();
                 }
                 if (RandomWindDirection)
                 {
                     if (WeatherScript.Camera != null && WeatherScript.Camera.orthographic)
                     {
                         int val = UnityEngine.Random.Range(0, 2);
                         WindZone.transform.rotation = Quaternion.Euler(0.0f, (val == 0 ? 90.0f : -90.0f), 0.0f);
                     }
                     else
                     {
                         float xAxis = (AllowBlowUp ? UnityEngine.Random.Range(-30.0f, 30.0f) : 0.0f);
                         WindZone.transform.rotation = Quaternion.Euler(xAxis, UnityEngine.Random.Range(0.0f, 360.0f), 0.0f);
                     }
                     WindDirection = WindZone.transform.forward;
                 }
                 else if (WeatherScript.Camera.orthographic)
                 {
                     WindZone.transform.right = new Vector3(WindDirection.x, WindDirection.y, 0.0f);
                 }
                 else
                 {
                     WindZone.transform.forward = WindDirection;
                 }
                 nextWindTime = Time.time + WindChangeInterval.Random();
             }
         }
         AudioSourceWind.Play(WindIntensity * WindSoundMultiplier);
         Vector3 newVelocity = WindDirection * WindZone.windMain;
         if (newVelocity != CurrentWindVelocity)
         {
             if (FogVelocityMultiplier != 0.0f && WeatherScript.FogScript != null)
             {
                 Vector3 fogVelocityOld = WeatherScript.FogScript.FogNoiseVelocity;
                 Vector3 fogVelocity    = new Vector3(newVelocity.x * FogVelocityMultiplier, newVelocity.z * FogVelocityMultiplier, 0.0f);
                 TweenFactory.Tween("WeatherMakerWindScriptFogVelocity", fogVelocityOld, fogVelocity, (nextWindTime - Time.time) * 1.1f, TweenScaleFunctions.Linear, (p) =>
                 {
                     WeatherScript.FogScript.FogNoiseVelocity = p.CurrentValue;
                 }, null);
             }
             CurrentWindVelocity = newVelocity;
             if (WindChanged != null)
             {
                 WindChanged(newVelocity);
             }
         }
     }
     else
     {
         AudioSourceWind.Stop();
         WindZone.windMain   = WindZone.windTurbulence = WindZone.windPulseFrequency = WindZone.windPulseMagnitude = 0.0f;
         CurrentWindVelocity = Vector3.zero;
     }
     AudioSourceWind.Update();
 }