Example #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;
        }
Example #2
0
            /// <summary>
            /// Show clouds from a mesh
            /// </summary>
            /// <param name="mesh">Mesh</param>
            /// <param name="lifeTimeRange">Life time range</param>
            /// <param name="fadeTimeRange">Range of fade time for each cloud</param>
            /// <param name="fadeTimeDelayRange">Amount to add to the delay for fading for each subsequent cloud</param>
            public static void ShowClouds(Mesh mesh, RangeOfFloats lifeTimeRange, RangeOfFloats fadeTimeRange, RangeOfFloats fadeTimeDelayRange)
            {
                if (mesh == null)
                {
                    return;
                }

                List <Vector4> lifeTimes = new List <Vector4>(mesh.vertexCount);
                float          fadeDelay = 0.0f;

                for (int i = 0; i < mesh.vertexCount / 4; i++)
                {
                    float   fadeTime      = fadeTimeRange.Random();
                    float   totalLifeTime = lifeTimeRange.Random();
                    float   creationTime  = Time.timeSinceLevelLoad + fadeDelay;
                    Vector4 lifeTime      = new Vector4(creationTime, fadeTime, totalLifeTime);
                    fadeDelay += fadeTimeDelayRange.Random();
                    lifeTimes.Add(lifeTime);
                    lifeTimes.Add(lifeTime);
                    lifeTimes.Add(lifeTime);
                    lifeTimes.Add(lifeTime);
                }

                mesh.SetUVs(1, lifeTimes);
            }
        public static byte[] Serialize(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms, System.Text.Encoding.UTF8);

            System.Type t = obj.GetType();
            byte        header;

            if (!TypesToHeader.TryGetValue(t, out header))
            {
#if NETFX_CORE
                if (!System.Reflection.IntrospectionExtensions.GetTypeInfo(t).IsEnum)
#else
                if (!t.IsEnum)
#endif

                {
                    return(null);
                }
                header = HeaderEnum;
            }
            writer.Write(header);
            switch (header)
            {
            case HeaderFloat: { writer.Write((float)obj); break; }

            case HeaderInt: { writer.Write((int)obj); break; }

            case HeaderShort: { writer.Write((short)obj); break; }

            case HeaderByte: { writer.Write((byte)obj); break; }

            case HeaderColor: { Color c = (Color)obj; writer.Write(c.r); writer.Write(c.g); writer.Write(c.b); writer.Write(c.a); break; }

            case HeaderVector2: { Vector2 v = (Vector2)obj; writer.Write(v.x); writer.Write(v.y); break; }

            case HeaderVector3: { Vector3 v = (Vector3)obj; writer.Write(v.x); writer.Write(v.y); writer.Write(v.z); break; }

            case HeaderVector4: { Vector4 v = (Vector4)obj; writer.Write(v.x); writer.Write(v.y); writer.Write(v.z); writer.Write(v.w); break; }

            case HeaderQuaternion: { Quaternion q = (Quaternion)obj; writer.Write(q.x); writer.Write(q.y); writer.Write(q.z); writer.Write(q.w); break; }

            case HeaderBool: { writer.Write((bool)obj); break; }

            case HeaderFloatRange: { RangeOfFloats v = (RangeOfFloats)obj; writer.Write(v.Minimum); writer.Write(v.Maximum); break; }

            case HeaderIntRange: { RangeOfIntegers v = (RangeOfIntegers)obj; writer.Write(v.Minimum); writer.Write(v.Maximum); break; }

            case HeaderEnum: { writer.Write((int)obj); break; }
            }
            return(ms.ToArray());
        }
Example #4
0
        private void UpdateProfile()
        {
            // clients will get the transition sent to them via network extension
            if (WeatherMakerScript.Instance == null || !WeatherMakerScript.Instance.NetworkConnection.IsServer || (SingleProfile == null && ProfileGroup == null))
            {
                return;
            }
            else if (SingleProfile == null)
            {
                if (secondsRemainingTransition <= 0.0f || currentProfileSingle != null)
                {
                    secondsRemainingTransition = 0.0f;
                    if (currentProfileSingle != null)
                    {
                        secondsRemainingHold = 0.0f;
                    }

                    if ((secondsRemainingHold -= Time.deltaTime) <= 0.0f)
                    {
                        // setup new transition
                        WeatherMakerProfileScript oldProfile = (currentProfileSingle == null ? currentProfile : currentProfileSingle);
                        currentProfile           = ProfileGroup.PickWeightedProfile();
                        PreviousLastLocalProfile = (oldProfile == null || WeatherMakerScript.Instance.LastLocalProfile == null ? "None" : WeatherMakerScript.Instance.LastLocalProfile.name);
                        LastLocalProfile         = (currentProfile == null ? "None" : currentProfile.name);
                        RangeOfFloats duration = TransitionDuration;
                        currentProfile = WeatherMakerProfileGroupScript.OverrideProfile(currentProfile, CloudProfile, SkyProfile, AuroraProfile,
                                                                                        PrecipitationProfile, FogProfile, WindProfile, LightningProfile, SoundProfile, duration, HoldDuration);
                        secondsRemainingTransition = currentProfile.RandomTransitionDuration();
                        secondsRemainingHold       = currentProfile.RandomHoldDuration();
                        NotifyThoseInZoneOfProfileChange(oldProfile, currentProfile, secondsRemainingTransition);
                        CleanupProfile(oldProfile);
                    }
                }
                else
                {
                    // else let the transition continue
                    secondsRemainingTransition -= Time.deltaTime;
                }
                currentProfileSingle = null;
            }
            else if (SingleProfile != currentProfileSingle)
            {
                currentProfileSingle = SingleProfile;
                WeatherMakerProfileScript oldProfile = currentProfile;
                RangeOfFloats             duration   = TransitionDuration;
                currentProfile = WeatherMakerProfileGroupScript.OverrideProfile(SingleProfile, CloudProfile, SkyProfile, AuroraProfile,
                                                                                PrecipitationProfile, FogProfile, WindProfile, LightningProfile, SoundProfile, duration, HoldDuration);
                PreviousLastLocalProfile   = (oldProfile == null || WeatherMakerScript.Instance.LastLocalProfile == null ? "None" : WeatherMakerScript.Instance.LastLocalProfile.name);
                LastLocalProfile           = (currentProfile == null ? "None" : currentProfile.name);
                secondsRemainingTransition = currentProfile.RandomTransitionDuration();
                NotifyThoseInZoneOfProfileChange(oldProfile, SingleProfile, secondsRemainingTransition);
                CleanupProfile(oldProfile);
            }
        }
        private void RenderRangeOfFloats(Rect rect, WeatherMakerPropertyTransition t, FieldInfo field, SingleLineClampAttribute clamp)
        {
            GUIContent    labelMin = new GUIContent("Min", "Minimum Value (Inclusive)");
            GUIContent    labelMax = new GUIContent("Max", "Maximum Value (Inclusive)");
            RangeOfFloats r        = (RangeOfFloats)GetFieldValue(field, t);
            float         w        = rect.width;

            rect.width *= 0.5f;
            rect.width -= 6.0f;
            r.Minimum   = EditorGUI.FloatField(rect, labelMin, r.Minimum);
            rect.x     += rect.width + 6.0f;
            r.Maximum   = EditorGUI.FloatField(rect, labelMax, r.Maximum);
            t.Value     = r;
        }
        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);
        }
        /// <summary>
        /// Animate from one aurora profile to another
        /// </summary>
        /// <param name="oldProfile">Old profile</param>
        /// <param name="duration">Duration</param>
        /// <param name="key">Animation key</param>
        /// <param name="completion">Completion callback</param>
        public void AnimateFrom(WeatherMakerAuroraProfileScript oldProfile, float duration, string key, System.Action completion)
        {
            if (oldProfile != null)
            {
                TweenFactory.Tween(key, 0.0f, 1.0f, duration, TweenScaleFunctions.QuadraticEaseInOut, (ITween <float> v) =>
                {
                    AnimationSampleCount     = Mathf.RoundToInt(Mathf.Lerp((float)oldProfile.AnimationSampleCount, (float)SampleCount, v.CurrentProgress));
                    AnimationSubSampleCount  = Mathf.RoundToInt(Mathf.Lerp((float)oldProfile.AnimationSubSampleCount, (float)SubSampleCount, v.CurrentProgress));
                    AnimationAnimationSpeed  = Vector3.Lerp(oldProfile.AnimationAnimationSpeed, AnimationSpeed, v.CurrentProgress);
                    AnimationColor           = oldProfile.AnimationColor.Lerp(Color, v.CurrentProgress);
                    AnimationDither          = Mathf.Lerp(oldProfile.AnimationDither, Dither, v.CurrentProgress);
                    AnimationIntensity       = Mathf.Lerp(oldProfile.AnimationIntensity, Intensity, v.CurrentProgress);
                    AnimationPower           = Mathf.Lerp(oldProfile.AnimationPower, Power, v.CurrentProgress);
                    AnimationHeightFadePower = Mathf.Lerp(oldProfile.AnimationHeightFadePower, HeightFadePower, v.CurrentProgress);
                    AnimationMarchScale      = Vector3.Lerp(oldProfile.AnimationMarchScale, MarchScale, v.CurrentProgress);
                    AnimationScale           = Vector3.Lerp(oldProfile.AnimationScale, Scale, v.CurrentProgress);
                    AnimationHeight          = new RangeOfFloats(Mathf.Lerp(oldProfile.AnimationHeight.Minimum, Height.Minimum, v.CurrentProgress), Mathf.Lerp(oldProfile.Height.Maximum, Height.Maximum, v.CurrentProgress));
                    AnimationPlanetRadius    = Mathf.Lerp(oldProfile.AnimationPlanetRadius, PlanetRadius, v.CurrentProgress);
                    AnimationDistanceFade    = Mathf.Lerp(oldProfile.AnimationDistanceFade, DistanceFade, v.CurrentProgress);
                    AnimationAmbientColor    = UnityEngine.Color.Lerp(oldProfile.AnimationAmbientColor, AmbientLight * Intensity, v.CurrentProgress);
                    AnimationOctave          = Vector2.Lerp(oldProfile.AnimationOctave, Octave, v.CurrentProgress);

                    if (WeatherMakerScript.Instance != null)
                    {
                        AnimationSampleCount    = Mathf.Min(WeatherMakerScript.Instance.PerformanceProfile.AuroraSampleCount, AnimationSampleCount);
                        AnimationSubSampleCount = Mathf.Min(WeatherMakerScript.Instance.PerformanceProfile.AuroraSubSampleCount, AnimationSubSampleCount);
                    }
                }, (ITween <float> v) =>
                {
                    if (completion != null)
                    {
                        completion.Invoke();
                    }
                });
            }
            else
            {
                UpdateAnimationProperties();
                if (completion != null)
                {
                    completion.Invoke();
                }
            }
        }
        private void Strike(Vector3?_start, Vector3?_end, bool intense, float intensity, Camera camera, bool forceVisible)
        {
            Vector3 anchorPosition = camera.transform.position;
            Vector3 start          = _start ?? CalculateStartPosition(ref anchorPosition, (forceVisible ? camera : null), intense);
            Vector3 end            = _end ?? CalculateEndPosition(ref anchorPosition, ref start, (forceVisible ? camera : null), intense);

            // save the generations and trunk width in case of cloud only lightning which will modify these properties
            int   generations = LightningBoltScript.Generations;
            float intensityModifier;

            if (WeatherScript.Sun == null)
            {
                intensityModifier = 0.35f;
            }
            else if (WeatherScript.Camera.orthographic)
            {
                float sunX = (WeatherScript.Sun.Transform.eulerAngles.x + 180.0f);
                sunX = (sunX >= 360.0f ? sunX - 360.0f : sunX);
                sunX = Mathf.Abs((sunX * 0.5f) - 90.0f);
                intensityModifier = Mathf.Lerp(0.1f, 0.75f, sunX * 0.016f);
            }
            else
            {
                float sunX = (WeatherScript.Sun.Transform.eulerAngles.x + 90.0f);
                sunX = (sunX >= 360.0f ? sunX - 360.0f : sunX);
                sunX = Mathf.Abs((sunX * 0.5f) - 90.0f);
                intensityModifier = Mathf.Lerp(0.1f, 0.75f, sunX * 0.006f);
            }
            RangeOfFloats trunkWidth = LightningBoltScript.TrunkWidthRange;

            if (UnityEngine.Random.value < CloudLightningChance)
            {
                // cloud only lightning
                LightningBoltScript.TrunkWidthRange = new RangeOfFloats();
                LightningBoltScript.Generations     = 1;
            }
            LightningBoltScript.LightParameters.LightIntensity = intensity * intensityModifier;
            LightningBoltScript.Trigger(start, end);

            // restore properties in case they were modified
            LightningBoltScript.TrunkWidthRange = trunkWidth;
            LightningBoltScript.Generations     = generations;
        }
Example #9
0
            /// <summary>
            /// Hide clouds from a mesh
            /// </summary>
            /// <param name="mesh">Mesh</param>
            /// <param name="fadeTimeRange">Range of fade time for each cloud</param>
            /// <param name="fadeTimeDelayRange">Amount to add to the delay for fading for each subsequent cloud</param>
            public static void HideClouds(Mesh mesh, RangeOfFloats fadeTimeRange, RangeOfFloats fadeTimeDelayRange)
            {
                if (mesh == null)
                {
                    return;
                }

                List <Vector4> lifeTimes = new List <Vector4>(mesh.vertexCount);
                float          fadeDelay = 0.0f;

                mesh.GetUVs(1, lifeTimes);

                for (int i = 0; i < lifeTimes.Count;)
                {
                    float   fadeTime = fadeTimeRange.Random();
                    Vector4 lifeTime = lifeTimes[i];
                    lifeTime.y     = fadeTimeRange.Random();
                    lifeTime.z     = (Time.timeSinceLevelLoad - lifeTime.x) + fadeTime + fadeDelay;
                    fadeDelay     += fadeTimeDelayRange.Random();
                    lifeTimes[i++] = lifeTimes[i++] = lifeTimes[i++] = lifeTimes[i++] = lifeTime;
                }

                mesh.SetUVs(1, lifeTimes);
            }
Example #10
0
        private void Strike(Vector3?_start, Vector3?_end, bool intense, float intensity, Camera camera, bool forceVisible)
        {
            WeatherMakerCelestialObjectScript sun = WeatherMakerLightManagerScript.SunForCamera(camera);

            if (sun == null)
            {
                return;
            }

            // save the generations and trunk width in case of cloud only lightning which will modify these properties
            int           generations = LightningBoltScript.Generations;
            RangeOfFloats trunkWidth  = LightningBoltScript.TrunkWidthRange;

            if (UnityEngine.Random.value < CloudLightningChance)
            {
                // cloud only lightning
                LightningBoltScript.TrunkWidthRange = new RangeOfFloats();
                LightningBoltScript.Generations     = 1;
            }

            Vector3 anchorPosition = camera.transform.position;
            Vector3 start          = _start ?? CalculateStartPosition(ref anchorPosition, (forceVisible ? camera : null), intense, LightningBoltScript.Generations <= 1);
            Vector3 end            = _end ?? CalculateEndPosition(ref anchorPosition, ref start, (forceVisible ? camera : null), intense);

            float      intensityModifier = 1.0f;
            CameraMode mode = WeatherMakerScript.ResolveCameraMode(null, camera);

            if (sun != null)
            {
                if (mode != CameraMode.Perspective)
                {
                    float sunX = (sun.transform.eulerAngles.x + 180.0f);
                    sunX = (sunX >= 360.0f ? sunX - 360.0f : sunX);
                    sunX = Mathf.Abs((sunX * 0.5f) - 90.0f);
                    intensityModifier = Mathf.Lerp(0.1f, 0.75f, sunX * 0.016f);
                }
                else
                {
                    float sunX = (sun.transform.eulerAngles.x + 90.0f);
                    sunX = (sunX >= 360.0f ? sunX - 360.0f : sunX);
                    sunX = Mathf.Abs((sunX * 0.5f) - 90.0f);
                    intensityModifier = Mathf.Lerp(0.1f, 0.75f, sunX * 0.006f);
                }
            }
            LightningBoltScript.LightParameters.LightIntensity = Mathf.Max(1.0f, intensity * intensityModifier);
            if (mode == CameraMode.Perspective)
            {
                if (LightningBoltScript.Generations > 1)
                {
                    Vector3 lightStart = start;
                    if (camera != null)
                    {
                        // HACK: Pull light toward camera to light clouds better, for some reason the light appears behind the lightning bolt
                        //  need to figure out why...
                        Vector3 toLight = camera.transform.position - lightStart;
                        lightStart  += (toLight * 0.5f);
                        lightStart.y = 1000.0f;
                    }
                    LightningBoltScript.LightParameters.LightPosition = lightStart;
                }
                else
                {
                    LightningBoltScript.LightParameters.LightPosition = start;
                }
                LightningBoltScript.LightParameters.LightRange = Random.Range(3000.0f, 6000.0f);
            }
            LightningBoltScript.Trigger(start, end);

            // restore properties in case they were modified
            LightningBoltScript.TrunkWidthRange = trunkWidth;
            LightningBoltScript.Generations     = generations;
        }