Beispiel #1
0
        internal override void Initialize()
        {
#if WEATHER_MAKER_PRESENT
            WeatherMakerScript component = GameObject.FindObjectOfType <WeatherMakerScript>();
            if (component == null)
            {
                Debug.LogError("You don't have a WeatherMakerScript in your scene. Please see the Weather Maker Day Night Cycle plugin README for instructions.");
                return;
            }
            else
            {
                weatherMakerScript = component.gameObject;
            }

            WeatherMakerDayNightCycleManagerScript dayNightScript = FindObjectOfType <WeatherMakerDayNightCycleManagerScript>();
            if (dayNightScript == null)
            {
                Debug.LogError("Cannot find an object with the `WeatherMakerDayNightCycle` attached.");
            }
            else
            {
                dayNight = dayNightScript.gameObject;
            }

            WeatherMakerDayNightCycleManagerScript.Instance.DayNightProfile = weatherMakerProfile;
#endif
            base.Initialize();
        }
Beispiel #2
0
        internal override void Start()
        {
            manager = FindObjectOfType <WeatherPluginManager>();
            if (manager == null)
            {
                Debug.LogError("Cannot find Weather Manager.");
            }

#if WEATHER_MAKER_PRESENT
            zone = FindObjectOfType <WeatherMakerWeatherZoneScript>();
            if (zone == null)
            {
                Debug.LogError("Unable to find a WeatherMakerWeatherZoneScript");
            }


            WeatherMakerScript component = GameObject.FindObjectOfType <WeatherMakerScript>();
            if (component == null)
            {
                Debug.LogError("You don't have a WeatherMakerScript in your scene. Please see the Weather Maker Weather System plugin README for instructions.");
                return;
            }
            else
            {
                weatherMaker = component.gameObject;
            }

            if (weatherMaker == null)
            {
                Debug.LogError("Unable to find or instantiate an object with the WeatherMakerScript attached");
            }

            DontDestroyOnLoad(weatherMaker);

            if (automatedGroupProfile != null)
            {
                zone.ProfileGroup  = automatedGroupProfile;
                zone.SingleProfile = null;
                manager.isAuto     = false;

                float transisitonDuration = 15f;
                float holdDuration        = 20f;

                dayNightManager = FindObjectOfType <DayNightPluginManager>();
                if (dayNightManager != null)
                {
                    transisitonDuration = dayNightManager.GameSecondsToRealSeconds(120 * 60); // 2 hour game time
                    holdDuration        = dayNightManager.GameSecondsToRealSeconds(15 * 60);  // 1/4 hour game time
                }

                automatedGroupProfile.TransitionDuration.Minimum = transisitonDuration * 0.75f;
                automatedGroupProfile.TransitionDuration.Maximum = transisitonDuration * 1.25f;
                automatedGroupProfile.HoldDuration.Minimum       = holdDuration * 0.75f;
                automatedGroupProfile.HoldDuration.Maximum       = holdDuration * 1.25f;
            }

            // Since we've changed the config of the weather maker manager we need to trigger the OnEnable method so that it re-initializes
            weatherMaker.SetActive(false);
            weatherMaker.SetActive(true);

            WeatherMakerScript.Instance.RaiseWeatherProfileChanged(null, clearProfile, 1, 20, true, null);
#endif
        }
Beispiel #3
0
        private void CameraPreCull(Camera camera)
        {
            if (!gameObject.activeInHierarchy || WeatherMakerCommandBufferManagerScript.CameraStackCount > 1 || WeatherMakerScript.ShouldIgnoreCamera(this, camera, true))
            {
                return;
            }

            RenderReflection();
        }
Beispiel #4
0
        private void CameraPreCull(Camera camera)
        {
            if (!gameObject.activeInHierarchy || WeatherMakerCommandBufferManagerScript.CameraStack > 1 || WeatherMakerScript.ShouldIgnoreCamera(this, camera, true))
            {
                return;
            }

            if (!RequestRefresh(Time.renderedFrameCount))
            {
                return; //skip if not need to refresh on this frame
            }
            CreateWaterObjects(_camViewpoint);

            if (!_camReflections)
            {
                return;
            }

            // find out the reflection plane: position and normal in world space
            Vector3 planePos    = OceanRenderer.Instance.transform.position;
            Vector3 planeNormal = Vector3.up;

            // Optionally disable pixel lights for reflection/refraction
            int oldPixelLightCount = QualitySettings.pixelLightCount;

            if (_disablePixelLights)
            {
                QualitySettings.pixelLightCount = 0;
            }

            UpdateCameraModes(_camViewpoint, _camReflections);

            // Reflect camera around reflection plane
            float   d = -Vector3.Dot(planeNormal, planePos) - _clipPlaneOffset;
            Vector4 reflectionPlane = new Vector4(planeNormal.x, planeNormal.y, planeNormal.z, d);

            Matrix4x4 reflection = Matrix4x4.zero;

            CalculateReflectionMatrix(ref reflection, reflectionPlane);
            Vector3 newpos = reflection.MultiplyPoint(_camViewpoint.transform.position);

            _camReflections.worldToCameraMatrix = _camViewpoint.worldToCameraMatrix * reflection;

            // Setup oblique projection matrix so that near plane is our reflection
            // plane. This way we clip everything below/above it for free.
            Vector4 clipPlane = CameraSpacePlane(_camReflections, planePos, planeNormal, 1.0f);

            _camReflections.projectionMatrix = _camViewpoint.CalculateObliqueMatrix(clipPlane);

            // Set custom culling matrix from the current camera
            _camReflections.cullingMatrix = _camViewpoint.projectionMatrix * _camViewpoint.worldToCameraMatrix;

            _camReflections.targetTexture = _reflectionTexture;

            // Invert culling because view is mirrored
            bool oldCulling = GL.invertCulling;

            GL.invertCulling = !oldCulling;

            _camReflections.transform.position = newpos;
            Vector3 euler = _camViewpoint.transform.eulerAngles;

            _camReflections.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
            _camReflections.cullingMatrix         = _camReflections.projectionMatrix * _camReflections.worldToCameraMatrix;

            ForceDistanceCulling(_farClipPlane);

            if (WeatherMakerCommandBufferManagerScript.Instance != null)
            {
                WeatherMakerCommandBufferManagerScript.Instance.RenderCamera(_camReflections);
            }

            GL.invertCulling = oldCulling;

            // Restore pixel light count
            if (_disablePixelLights)
            {
                QualitySettings.pixelLightCount = oldPixelLightCount;
            }

            Refreshed(Time.renderedFrameCount); //remember this frame as last refreshed
        }