Example #1
0
        /// <summary>
        /// Create Gaia Culling System Profile asset
        /// </summary>
#if UNITY_EDITOR
        public static GaiaSceneCullingProfile CreateCullingProfile()
        {
            GaiaSceneCullingProfile asset        = ScriptableObject.CreateInstance <GaiaSceneCullingProfile>();
            GaiaSettings            gaiaSettings = GaiaUtils.GetGaiaSettings();

            asset.UpdateCulling(gaiaSettings);
            asset.UpdateShadow();
            AssetDatabase.CreateAsset(asset, "Assets/Gaia Scene Culling Profile.asset");
            AssetDatabase.SaveAssets();
            return(asset);
        }
Example #2
0
        public static void CreateCullingProfileMenu()
        {
            GaiaSceneCullingProfile asset        = ScriptableObject.CreateInstance <GaiaSceneCullingProfile>();
            GaiaSettings            gaiaSettings = GaiaUtils.GetGaiaSettings();

            asset.UpdateCulling(gaiaSettings);
            asset.UpdateShadow();
            AssetDatabase.CreateAsset(asset, "Assets/Gaia Scene Culling Profile.asset");
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = asset;
        }
Example #3
0
        public void Initialize()
        {
            if (m_profile == null)
            {
                GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings();
                m_profile = ScriptableObject.CreateInstance <GaiaSceneCullingProfile>();
                m_profile.UpdateCulling(gaiaSettings);
                m_profile.UpdateShadow();
            }

            ApplyToGameCamera();
        }
Example #4
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);
                        }
                    }
                }
            }
        }