public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            CameraMode mode = WeatherMakerScript.ResolveCameraMode();

            //2D settings toggle on and off depending if the target camera is orthographic
            if (mode == CameraMode.OrthographicXY || mode == CameraMode.OrthographicXZ)
            {
                EditorGUILayout.BeginVertical("box");
                EditorGUILayout.LabelField("2D Settings:");

                GUIContent layerTip = new GUIContent("Sorting Layer", "Layer name for custom sorting");
                chosenIndex = EditorGUILayout.Popup(layerTip, chosenIndex, sortingLayerNames);
                layerName   = (sortingLayerNames[chosenIndex] == null ? null : sortingLayerNames[chosenIndex].text);

                GUIContent orderTip = new GUIContent("Sort Order", "Sort order in the sort layer");
                orderInLayer = EditorGUILayout.IntField(orderTip, inspectorTarget.SortOrderInLayer);

                EditorGUILayout.EndVertical();
            }

            //Draw the rest of the inspector. The fields above are marked not to be drawn in the default inspector so that we don't have duplicates
            DrawDefaultInspector();

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(inspectorTarget, "Edit Lightning");
                inspectorTarget.SortLayerName    = layerName;
                inspectorTarget.SortOrderInLayer = orderInLayer;
                EditorUtility.SetDirty(inspectorTarget);
            }
        }
        /// <summary>
        /// Get a gradient lookup value given directional light position
        /// </summary>
        /// <returns>Value</returns>
        public float GetGradientLookup()
        {
            if (!LightIsActive)
            {
                return(1.0f);
            }

            float      sunGradientLookup;
            CameraMode mode = WeatherMakerScript.ResolveCameraMode();

            if (mode == CameraMode.OrthographicXY && !OrbitTypeIsPerspective)
            {
                sunGradientLookup = transform.forward.z;
            }
            else if (mode == CameraMode.OrthographicXZ && !OrbitTypeIsPerspective)
            {
                sunGradientLookup = transform.forward.x;
            }
            else
            {
                // TODO: Support full spherical world
                sunGradientLookup = -transform.forward.y;
            }
            sunGradientLookup = ((sunGradientLookup + 1.0f) * 0.5f);
            return(sunGradientLookup);
        }
Пример #3
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;
        }
Пример #4
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;
        }