public static WeatherMakerProfileScript OverrideProfile
        (
            WeatherMakerProfileScript profile,
            WeatherMakerCloudProfileScript cloudProfile,
            WeatherMakerSkyProfileScript skyProfile,
            WeatherMakerAuroraProfileScript auroraProfile,
            WeatherMakerPrecipitationProfileScript precipitationProfile,
            WeatherMakerFullScreenFogProfileScript fogProfile,
            WeatherMakerWindProfileScript windProfile,
            WeatherMakerLightningProfileScript lightningProfile,
            WeatherMakerSoundProfileScript soundProfile,
            RangeOfFloats transitionDuration,
            RangeOfFloats holdDuration
        )
        {
            if (profile == null)
            {
                Debug.LogError("Null profile in Weather Maker profile OverrideProfile, this is not allowed");
                return(null);
            }

            // check for overrides, if so clone the profile
            else if (cloudProfile != null || skyProfile != null || auroraProfile != null || precipitationProfile != null || fogProfile != null ||
                     windProfile != null || lightningProfile != null || soundProfile != null || transitionDuration.Maximum > 0.0f || holdDuration.Maximum > 0.0f)
            {
                if (profile.name.IndexOf("(clone)", System.StringComparison.OrdinalIgnoreCase) < 0)
                {
                    profile = ScriptableObject.Instantiate(profile);
                }
                AssignOverride(ref profile.CloudProfile, cloudProfile);
                AssignOverride(ref profile.SkyProfile, skyProfile);
                AssignOverride(ref profile.AuroraProfile, auroraProfile);
                AssignOverride(ref profile.PrecipitationProfile, precipitationProfile);
                AssignOverride(ref profile.FogProfile, fogProfile);
                AssignOverride(ref profile.WindProfile, windProfile);
                AssignOverride(ref profile.LightningProfile, lightningProfile);
                AssignOverride(ref profile.SoundProfile, soundProfile);
                if (transitionDuration.Maximum > 0.0f)
                {
                    profile.TransitionDuration = transitionDuration;
                }
                if (holdDuration.Maximum > 0.0f)
                {
                    profile.HoldDuration = holdDuration;
                }
            }

            return(profile);
        }
Пример #2
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;
        }
Пример #3
0
 public void SetWindProfileAnimated(WeatherMakerWindProfileScript newProfile, float transitionDelay, float transitionDuration)
 {
     WindProfile = newProfile;
     AnimateWindChange(newProfile, transitionDelay, transitionDuration);
 }