コード例 #1
0
        private void Start()
        {
            m_instance     = this;
            WeatherPresent = CheckWeatherPresent();
            UpdateGaiaTimeOfDay(false);

            if (m_sunLight == null)
            {
                m_sunLight = GaiaUtils.GetMainDirectionalLight();
            }
            if (m_sunLight != null)
            {
                m_sunLightExists = true;
            }

            if (m_moonLight == null)
            {
                GameObject moonObject = GameObject.Find("Moon Light");
                if (moonObject != null)
                {
                    m_moonLight = moonObject.GetComponent <Light>();
                }
            }
#if GAIA_PRO_PRESENT
            if (m_moonLight != null)
            {
                m_moonLightExists = true;
            }
#endif
        }
コード例 #2
0
        private void OnEnable()
        {
            m_instance = this;
            if (m_mainLight == null)
            {
                m_mainLight = GaiaUtils.GetMainDirectionalLight();
            }

            if (m_audioSource != null)
            {
                m_audioSource.playOnAwake = false;
            }

            if (m_audioSourceUnderwater != null)
            {
                m_audioSourceUnderwater.playOnAwake = false;
            }

            if (m_underwaterMaterial == null)
            {
                m_underwaterMaterial = GaiaUtils.GetWaterMaterial(GaiaConstants.waterSurfaceObject, true);
            }

            SetupTransitionVFX(m_enableTransitionFX);
        }
コード例 #3
0
        public void UpdateCulling(GaiaSettings gaiaSettings)
        {
            if (!GaiaUtils.CheckIfSceneProfileExists())
            {
                return;
            }
            if (GaiaGlobal.Instance.m_mainCamera == null)
            {
                GaiaGlobal.Instance.m_mainCamera = GaiaUtils.GetCamera();
            }

            float farClipPlane = 2000f;

            if (GaiaGlobal.Instance.m_mainCamera != null)
            {
                farClipPlane = GaiaGlobal.Instance.m_mainCamera.farClipPlane;
            }

            if (GaiaGlobal.Instance.SceneProfile.m_sunLight == null)
            {
                GaiaGlobal.Instance.SceneProfile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
            }

            Terrain terrain = TerrainHelper.GetActiveTerrain();

            //Objects
            m_layerDistances = new float[32];
            for (int i = 0; i < m_layerDistances.Length; i++)
            {
                string layerName = LayerMask.LayerToName(i);
                switch (layerName)
                {
                case "Default":
                case "Water":
                case "PW_VFX":
                    m_layerDistances[i] = 0f;
                    break;

                case "PW_Object_Small":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment, 5f);
                    break;

                case "PW_Object_Medium":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment, 3f);
                    break;

                case "PW_Object_Large":
                    m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment);
                    break;

                default:
                    m_layerDistances[i] = 0f;
                    break;
                }
            }
        }
コード例 #4
0
        public void OnEnable()
        {
            m_instance     = this;
            WeatherPresent = CheckWeatherPresent();

            if (!Application.isPlaying)
            {
                if (m_lightingProfile == null)
                {
                    return;
                }

                if (m_waterProfile == null)
                {
                    return;
                }

                if (m_gaiaSettings == null)
                {
                    m_gaiaSettings = GaiaUtils.GetGaiaSettings();
                    if (m_gaiaSettings == null)
                    {
                        return;
                    }
                }
            }

            if (m_mainCamera == null)
            {
                m_mainCamera = GaiaUtils.GetCamera();
            }

            if (m_sunLight == null)
            {
                m_sunLight = GaiaUtils.GetMainDirectionalLight();
            }

            if (m_moonLight == null)
            {
                GameObject moonObject = GameObject.Find("Moon Light");
                if (moonObject != null)
                {
                    m_moonLight = moonObject.GetComponent <Light>();
                }
            }

            UpdateGaiaTimeOfDay(false);
            CheckPostProcessingFog(true);
        }
コード例 #5
0
        //Camera Culling
        public static void UpdateCullingDistances()
        {
            if (!GaiaUtils.CheckIfSceneProfileExists())
            {
                return;
            }

            if (GaiaGlobal.Instance.SceneProfile.CullingProfile == null)
            {
                return;
            }

#if GAIA_PRO_PRESENT
            if (ProceduralWorldsGlobalWeather.Instance != null)
            {
                if (ProceduralWorldsGlobalWeather.Instance.CheckIsNight())
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight = ProceduralWorldsGlobalWeather.Instance.m_moonLight;
                }
                else
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight = ProceduralWorldsGlobalWeather.Instance.m_sunLight;
                }
            }
            else
            {
                if (GaiaGlobal.Instance.SceneProfile.m_sunLight == null)
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
                }
            }
#else
            if (GaiaGlobal.Instance.SceneProfile.m_sunLight == null)
            {
                GaiaGlobal.Instance.SceneProfile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
            }
#endif

            //Make sure we have distances
            if (GaiaGlobal.Instance.SceneProfile.CullingProfile.m_layerDistances == null || GaiaGlobal.Instance.SceneProfile.CullingProfile.m_layerDistances.Length != 32)
            {
                return;
            }

            if (GaiaGlobal.Instance.SceneProfile.m_enableLayerCulling)
            {
                //Apply to main camera
                GaiaGlobal.Instance.m_mainCamera.layerCullDistances = GaiaGlobal.Instance.SceneProfile.CullingProfile.m_layerDistances;

                if (GaiaGlobal.Instance.SceneProfile.m_sunLight != null)
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight.layerShadowCullDistances = GaiaGlobal.Instance.SceneProfile.CullingProfile.m_shadowLayerDistances;
                }
            }
            else
            {
                float[] layerCulls = new float[32];
                for (int i = 0; i < layerCulls.Length; i++)
                {
                    layerCulls[i] = 0f;
                }

                //Apply to main camera
                GaiaGlobal.Instance.m_mainCamera.layerCullDistances = layerCulls;

                if (GaiaGlobal.Instance.SceneProfile.m_sunLight != null)
                {
                    GaiaGlobal.Instance.SceneProfile.m_sunLight.layerShadowCullDistances = layerCulls;
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Update the night mode stuff
        /// </summary>
        public void UpdateNightMode()
        {
#if GAIA_PRO_PRESENT
            if (WeatherPresent)
            {
                if (m_sunLight == null)
                {
                    m_sunLight = GaiaUtils.GetMainDirectionalLight();
                    if (m_sunLight != null)
                    {
                        m_sunLightExists = true;
                    }
                }
                else
                {
                    m_sunLightExists = true;
                }

                if (m_moonLight == null)
                {
                    GameObject moonObject = GameObject.Find("Moon Light");
                    if (moonObject != null)
                    {
                        m_moonLight = moonObject.GetComponent <Light>();
                    }

                    if (m_moonLight != null)
                    {
                        m_moonLightExists = true;
                    }
                }
                else
                {
                    m_moonLightExists = true;
                }

                if (WeatherSystem.CheckIsNight())
                {
                    if (m_moonLightExists)
                    {
                        RenderSettings.sun = m_moonLight;
                    }

                    if (m_sunLightExists)
                    {
#if HDPipeline
                        if (SunHDLightData == null)
                        {
                            SunHDLightData = GaiaHDRPRuntimeUtils.GetHDLightData(m_sunLight);
                        }

                        SunHDLightData.intensity = 0;
                        SunHDLightData.lightUnit = LightUnit.Lux;
#endif
                        m_sunLight.intensity = 0f;
                    }
                }
                else
                {
                    if (m_moonLightExists)
                    {
#if HDPipeline
                        if (MoonHDLightData == null)
                        {
                            MoonHDLightData = GaiaHDRPRuntimeUtils.GetHDLightData(m_moonLight);
                        }

                        MoonHDLightData.intensity = 0;
                        MoonHDLightData.lightUnit = LightUnit.Lux;
#endif
                        m_moonLight.intensity = 0f;
                    }

                    if (m_sunLightExists)
                    {
                        RenderSettings.sun = m_sunLight;
                    }
                }
            }
#endif
        }
コード例 #7
0
        private void CameraCullingSettings(bool helpEnabled)
        {
            //Monitor for changes
            EditorGUI.BeginChangeCheck();

            GaiaSceneCullingProfile cullingProfile = m_profile.CullingProfile;

            m_editorUtils.Heading("TerrainCulling");
            EditorGUI.indentLevel++;
            m_profile.m_terrainCullingEnabled = m_editorUtils.Toggle("UseTerrainCulling", m_profile.m_terrainCullingEnabled, helpEnabled);
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();
            m_editorUtils.Heading("CameraCulling");
            EditorGUI.indentLevel++;

            bool cullingEnabled = m_profile.m_enableLayerCulling;

            cullingEnabled = m_editorUtils.Toggle("EnableLayerCulling", cullingEnabled, helpEnabled);
            if (m_profile.m_enableLayerCulling != cullingEnabled)
            {
                m_profile.m_enableLayerCulling = cullingEnabled;
                if (Application.isPlaying)
                {
                    GaiaScenePlayer.UpdateCullingDistances();
                }
                else
                {
                    GaiaScenePlayer.ApplySceneSetup(cullingEnabled);
                }
            }
            if (m_profile.m_enableLayerCulling)
            {
                m_editorUtils.LabelField("GeneralSettings", EditorStyles.boldLabel);
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                cullingProfile = (GaiaSceneCullingProfile)m_editorUtils.ObjectField("CullingProfile", cullingProfile, typeof(GaiaSceneCullingProfile), false);
                if (m_editorUtils.Button("NewProfile", GUILayout.MaxWidth(40f)))
                {
                    GaiaSceneCullingProfile profile = GaiaSceneCullingProfile.CreateCullingProfile();
                    cullingProfile           = AssetDatabase.LoadAssetAtPath <GaiaSceneCullingProfile>(AssetDatabase.GetAssetPath(profile));
                    m_profile.CullingProfile = cullingProfile;
                    GUIUtility.ExitGUI();
                }
                EditorGUILayout.EndHorizontal();
                m_editorUtils.InlineHelp("CullingProfile", helpEnabled);
                if (cullingProfile != m_profile.CullingProfile)
                {
                    m_profile.CullingProfile = cullingProfile;
                    if (cullingProfile != null)
                    {
                        GaiaScenePlayer.ApplySceneSetup(cullingProfile.m_applyToEditorCamera);
                    }
                }
#if GAIA_PRO_PRESENT
                if (ProceduralWorldsGlobalWeather.Instance == null)
                {
                    m_profile.m_sunLight = (Light)m_editorUtils.ObjectField("SunLight", m_profile.m_sunLight, typeof(Light), true, helpEnabled);
                    if (m_profile.m_sunLight == null)
                    {
                        m_profile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
                    }
                }
#else
                m_profile.m_sunLight = (Light)m_editorUtils.ObjectField("SunLight", m_profile.m_sunLight, typeof(Light), true, helpEnabled);
                if (m_profile.m_sunLight == null)
                {
                    m_profile.m_sunLight = GaiaUtils.GetMainDirectionalLight();
                }
#endif

                if (m_profile.CullingProfile != null)
                {
                    m_profile.CullingProfile.m_applyToEditorCamera = m_editorUtils.Toggle("ApplyInEditor", m_profile.CullingProfile.m_applyToEditorCamera, helpEnabled);
                    m_profile.CullingProfile.m_realtimeUpdate      = m_editorUtils.Toggle("RealtimeUpdate", m_profile.CullingProfile.m_realtimeUpdate, helpEnabled);
                }
                EditorGUI.indentLevel--;

                if (m_profile.CullingProfile != null)
                {
                    //Objects
                    EditorGUILayout.Space();
                    m_editorUtils.LabelField("ObjectCullingSettings", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    m_editorUtils.InlineHelp("ObjectCullingSettings", helpEnabled);
                    for (int i = 0; i < m_profile.CullingProfile.m_layerDistances.Length; i++)
                    {
                        string layerName = LayerMask.LayerToName(i);
                        if (!string.IsNullOrEmpty(layerName))
                        {
                            m_profile.CullingProfile.m_layerDistances[i] = EditorGUILayout.FloatField(string.Format("[{0}] {1}", i, layerName), m_profile.CullingProfile.m_layerDistances[i]);
                        }
                    }
                    EditorGUI.indentLevel--;

                    if (m_editorUtils.Button("RevertCullingToDefaults"))
                    {
                        m_profile.CullingProfile.UpdateCulling(m_gaiaSettings);
                        EditorUtility.SetDirty(m_profile.CullingProfile);
                    }

                    //Shadows
                    EditorGUILayout.Space();
                    m_editorUtils.LabelField("ShadowCullingSettings", EditorStyles.boldLabel);
                    EditorGUI.indentLevel++;
                    m_editorUtils.InlineHelp("ShadowCullingSettings", helpEnabled);
                    for (int i = 0; i < m_profile.CullingProfile.m_shadowLayerDistances.Length; i++)
                    {
                        string layerName = LayerMask.LayerToName(i);
                        if (!string.IsNullOrEmpty(layerName))
                        {
                            m_profile.CullingProfile.m_shadowLayerDistances[i] = EditorGUILayout.FloatField(string.Format("[{0}] {1}", i, layerName), m_profile.CullingProfile.m_shadowLayerDistances[i]);
                        }
                    }

                    EditorGUI.indentLevel--;

                    if (m_editorUtils.Button("RevertShadowToDefaults"))
                    {
                        m_profile.CullingProfile.UpdateShadow();
                        EditorUtility.SetDirty(m_profile.CullingProfile);
                    }

                    EditorGUI.indentLevel--;
                }

                //Check for changes, make undo record, make changes and let editor know we are dirty
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_profile, "Made camera culling changes");
                    EditorUtility.SetDirty(m_profile);
                    if (m_profile.CullingProfile != null)
                    {
                        EditorUtility.SetDirty(m_profile.CullingProfile);
                        if (Application.isPlaying)
                        {
                            GaiaScenePlayer.UpdateCullingDistances();
                        }
                        else
                        {
                            GaiaScenePlayer.ApplySceneSetup(m_profile.CullingProfile.m_applyToEditorCamera);
                        }
                    }
                }
            }
        }
コード例 #8
0
        private void Update()
        {
            if (Application.isPlaying)
            {
                if (m_underwaterTransitionPostFX != null)
                {
                    if (m_underwaterTransitionPostFX.transform.position.y != m_seaLevel)
                    {
                        SetupTransitionVFX(m_enableTransitionFX);
                    }
                }

                if (m_mainLight == null)
                {
                    m_mainLight = GaiaUtils.GetMainDirectionalLight();
                }

                if (m_playerCamera == null)
                {
                    Debug.LogError("Player Camera is missing from the setup. Will try find it for you");
                    Camera camera = GaiaUtils.GetCamera();
                    if (camera != null)
                    {
                        m_playerCamera = camera.transform;
                    }
                    return;
                }
                else
                {
                    if (EnableUnderwaterEffects)
                    {
                        if (m_playerCamera.position.y > m_seaLevel)
                        {
                            if (!m_surfaceSetup)
                            {
                                IsUnderwater      = SetupWaterSystems(false, m_startingUnderwater);
                                m_underwaterSetup = false;
                                m_surfaceSetup    = true;
                            }
                        }
                        else
                        {
                            if (!m_underwaterSetup)
                            {
                                if (m_underwaterTransitionPostFX != null)
                                {
                                    m_underwaterTransitionPostFX.SetActive(true);
                                }
                                if (m_underwaterPostFX != null)
                                {
                                    m_underwaterPostFX.SetActive(true);
                                }
                                UpdateSurfaceFogSettings();
                                IsUnderwater      = SetupWaterSystems(true, m_startingUnderwater);
                                m_underwaterSetup = true;
                                m_surfaceSetup    = false;
                            }

                            UpdateUnderwaterFog();
                            UpdateUnderwaterPostFX();
                        }
                    }
                    else
                    {
                        if (m_underwaterTransitionPostFX != null)
                        {
                            m_underwaterTransitionPostFX.SetActive(false);
                        }
                        if (m_underwaterPostFX != null)
                        {
                            m_underwaterPostFX.SetActive(false);
                        }
                    }
                }

                if (m_weatherSystemExists)
                {
#if GAIA_PRO_PRESENT
                    if (!ProceduralWorldsGlobalWeather.Instance.IsRainingFinished || !ProceduralWorldsGlobalWeather.Instance.IsSnowingFinished)
                    {
                        ProceduralWorldsGlobalWeather.Instance.CheckUnderwaterParticlesVFX(IsUnderwater);
                    }
#endif
                }

                if (!IsUnderwater)
                {
                    UpdateSurfaceFogSettings();
                }
                else
                {
#if GAIA_PRO_PRESENT
                    if (m_weatherSystemExists)
                    {
                        if (ProceduralWorldsGlobalWeather.Instance.CheckIsNight())
                        {
                            m_mainLight = ProceduralWorldsGlobalWeather.Instance.m_moonLight;
                        }
                        else
                        {
                            m_mainLight = ProceduralWorldsGlobalWeather.Instance.m_sunLight;
                        }
                    }
#endif
                    if (m_underwaterMaterial != null)
                    {
                        UpdateUnderwaterMaterial();
                    }
                }
            }
            else
            {
                if (m_underwaterParticleSystem != null)
                {
                    m_underwaterParticleSystem.Stop();
                }

                if (m_underwaterPostFX != null)
                {
                    m_underwaterPostFX.SetActive(false);
                }

                if (m_underwaterTransitionPostFX != null)
                {
                    m_underwaterTransitionPostFX.SetActive(false);
                }

                if (m_horizonObject != null)
                {
                    m_horizonObject.SetActive(false);
                }
            }
        }
コード例 #9
0
        private void Start()
        {
            RenderPipeline = GaiaUtils.GetActivePipeline();
            m_instance     = this;

#if GAIA_PRO_PRESENT
            m_weatherSystemExists = ProceduralWorldsGlobalWeather.Instance;
#endif
            if (PWS_WaterSystem.Instance != null)
            {
                m_seaLevel = PWS_WaterSystem.Instance.SeaLevel;
            }

            if (m_playerCamera == null)
            {
                if (Camera.main != null)
                {
                    m_playerCamera = Camera.main.transform;
                }
            }
            if (m_playerCamera != null)
            {
                if (m_playerCamera.position.y > m_seaLevel)
                {
                    m_startingUnderwater = false;
                }
                else
                {
                    m_startingUnderwater = true;
                }
            }

            if (m_underwaterMaterial == null)
            {
                m_underwaterMaterial = GaiaUtils.GetWaterMaterial(GaiaConstants.waterSurfaceObject, true);
            }

            if (m_mainLight == null)
            {
                m_mainLight = GaiaUtils.GetMainDirectionalLight();
            }

            if (m_audioSource == null)
            {
                m_audioSource = GetAudioSource();
            }

            if (m_audioSourceUnderwater == null)
            {
                m_audioSourceUnderwater = GetAudioSource();
            }

            if (Application.isPlaying)
            {
                if (m_underwaterPostFX != null)
                {
                    m_underwaterPostFX.SetActive(true);
                }

                if (m_underwaterTransitionPostFX != null)
                {
                    m_underwaterTransitionPostFX.SetActive(true);
                }
            }

            if (m_audioSourceUnderwater != null)
            {
                m_audioSourceUnderwater.clip   = m_underwaterSoundFX;
                m_audioSourceUnderwater.loop   = true;
                m_audioSourceUnderwater.volume = m_playbackVolume;
                m_audioSourceUnderwater.Stop();
            }

            if (m_underwaterParticles != null)
            {
                m_underwaterParticleSystem = m_underwaterParticles.GetComponent <ParticleSystem>();
                if (m_underwaterParticleSystem != null)
                {
                    m_underwaterParticleSystem.Stop();
                }

                m_underwaterParticles.SetActive(false);
            }

            if (m_horizonObject != null)
            {
                m_horizonObject.SetActive(true);
                MeshRenderer[] meshRenders = m_horizonObject.GetComponentsInChildren <MeshRenderer>();
                foreach (MeshRenderer render in meshRenders)
                {
                    m_horizonMeshRenders.Add(render);
                    render.enabled = false;
                }
            }

            UpdateSurfaceFogSettings();
            if (m_startingUnderwater)
            {
                IsUnderwater      = SetupWaterSystems(true, m_startingUnderwater);
                m_underwaterSetup = true;
                m_surfaceSetup    = false;
            }
            else
            {
                m_underwaterSetup = true;
                m_surfaceSetup    = false;
            }
        }