예제 #1
0
        private void OnEnable()
        {
            //Get Gaia Lighting Profile object
            m_profile = (GaiaGlobal)target;

            if (m_editorUtils == null)
            {
                // Get editor utils for this
                m_editorUtils = PWApp.GetEditorUtils(this);
            }

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

            if (m_profile.SceneProfile == null)
            {
                m_profile.SceneProfile = ScriptableObject.CreateInstance <SceneProfile>();
            }

            if (m_profile.SceneProfile.m_selectedLightingProfileValuesIndex > m_profile.SceneProfile.m_lightingProfiles.Count - 1)
            {
                m_profile.SceneProfile.m_selectedLightingProfileValuesIndex = 1;
            }

            if (m_profile.SceneProfile.m_selectedWaterProfileValuesIndex > m_profile.SceneProfile.m_waterProfiles.Count - 1)
            {
                m_profile.SceneProfile.m_selectedWaterProfileValuesIndex = 1;
            }

            m_profile.SceneProfile.ProfileVersion = PWApp.CONF.Version;

#if GAIA_PRO_PRESENT
            if (ProceduralWorldsGlobalWeather.Instance != null)
            {
                LoadSettings();
            }
#endif
            if (dropdownGUIStyle == null)
            {
                dropdownGUIStyle = new GUIStyle(EditorStyles.popup)
                {
                    fixedHeight = 16f, margin = new RectOffset(0, 0, 4, 0)
                };
            }

            if (m_profile.SceneProfile.m_lightingProfiles.Count > 0)
            {
                if (m_profile.SceneProfile.m_selectedLightingProfileValuesIndex != -99)
                {
                    GaiaLightingProfileValues profileValues = m_profile.SceneProfile.m_lightingProfiles[m_profile.SceneProfile.m_selectedLightingProfileValuesIndex];
                    GaiaSceneManagement.FetchSceneSettigns(m_profile.SceneProfile, profileValues);
                }
            }
        }
예제 #2
0
        private void GlobalSettings(bool helpEnabled)
        {
            if (GaiaGlobal.Instance.SceneProfile.m_lightingProfiles.Count > 0)
            {
                if (m_profile.m_selectedLightingProfileValuesIndex != -99)
                {
                    profile = GaiaGlobal.Instance.SceneProfile.m_lightingProfiles[m_profile.m_selectedLightingProfileValuesIndex];
                }
            }

            if (m_gaiaSettings.m_currentRenderer == GaiaConstants.EnvironmentRenderer.BuiltIn)
            {
                bool postfx = m_profile.m_setupPostFX;
                m_profile.m_setupPostFX = m_editorUtils.Toggle("SetupPostFX", m_profile.m_setupPostFX, helpEnabled);
                if (postfx != m_profile.m_setupPostFX)
                {
                    if (m_profile.m_setupPostFX)
                    {
                        if (profile != null)
                        {
                            GaiaLighting.SetupPostProcessing(profile, m_profile, GaiaUtils.GetActivePipeline(), true);
                        }
                    }
                    else
                    {
                        GaiaLighting.RemoveAllPostProcessV2CameraLayer();
                    }
                }
            }
            m_profile.m_spawnPlayerAtCurrentLocation = m_editorUtils.Toggle("SpawnPlayerAtCurrentLocation", m_profile.m_spawnPlayerAtCurrentLocation, helpEnabled);

            GaiaConstants.EnvironmentControllerType controller = m_profile.m_controllerType;
            controller = (GaiaConstants.EnvironmentControllerType)m_editorUtils.EnumPopup("ControllerType", controller, helpEnabled);
            if (controller != m_profile.m_controllerType)
            {
                m_gaiaSettings.m_currentController = controller;
                switch (controller)
                {
                case GaiaConstants.EnvironmentControllerType.FirstPerson:
                    GaiaSceneManagement.CreatePlayer(m_gaiaSettings, GaiaConstants.playerFirstPersonName, m_profile.m_spawnPlayerAtCurrentLocation, null, null, true);
                    break;

                case GaiaConstants.EnvironmentControllerType.FlyingCamera:
                    GaiaSceneManagement.CreatePlayer(m_gaiaSettings, GaiaConstants.playerFlyCamName, m_profile.m_spawnPlayerAtCurrentLocation, null, null, true);
                    break;

                case GaiaConstants.EnvironmentControllerType.ThirdPerson:
                    GaiaSceneManagement.CreatePlayer(m_gaiaSettings, GaiaConstants.playerThirdPersonName, m_profile.m_spawnPlayerAtCurrentLocation, null, null, true);
                    break;

                case GaiaConstants.EnvironmentControllerType.Car:
                    GaiaSceneManagement.CreatePlayer(m_gaiaSettings, GaiaConstants.m_carPlayerPrefabName, m_profile.m_spawnPlayerAtCurrentLocation, null, null, true);
                    break;

                case GaiaConstants.EnvironmentControllerType.XRController:
#if GAIA_XR
                    GaiaSceneManagement.CreatePlayer(m_gaiaSettings, "XRController", m_profile.m_spawnPlayerAtCurrentLocation);
#else
                    EditorUtility.DisplayDialog("XR Support not enabled", "The XR Controller is a default player for Virtual / Augmented Reality projects. Please open the Setup Panel in the Gaia Manager Standard Tab to enable XR Support in order to use the XR Player Controller. Please also make sure you have the Unity XR Interaction Toolkit package installed before doing so.", "OK");
                    controller = GaiaConstants.EnvironmentControllerType.FlyingCamera;
                    m_gaiaSettings.m_currentController = GaiaConstants.EnvironmentControllerType.FlyingCamera;
#endif
                    break;
                }

                SetPostProcessing(profile);
#if GAIA_PRO_PRESENT
                if (GaiaUtils.HasDynamicLoadedTerrains())
                {
                    TerrainLoader tl = ((GaiaScenePlayer)target).GetComponentInChildren <TerrainLoader>();
                    if (tl != null)
                    {
                        m_profile.UpdateTerrainLoaderFromProfile(ref tl);
                    }
                }
#endif
                m_profile.m_controllerType = controller;
            }

            if (controller == GaiaConstants.EnvironmentControllerType.Custom)
            {
                m_profile.m_customPlayer = (GameObject)m_editorUtils.ObjectField("MainPlayer", m_profile.m_customPlayer, typeof(GameObject), true, helpEnabled);
                m_profile.m_customCamera = (Camera)m_editorUtils.ObjectField("MainCamera", m_profile.m_customCamera, typeof(Camera), true, helpEnabled);

                if (m_editorUtils.Button("ApplySetup"))
                {
                    GaiaSceneManagement.CreatePlayer(m_gaiaSettings, "Custom", m_profile.m_spawnPlayerAtCurrentLocation, m_profile.m_customPlayer, m_profile.m_customCamera, true);
                    SetPostProcessing(profile);
#if GAIA_PRO_PRESENT
                    if (GaiaUtils.HasDynamicLoadedTerrains())
                    {
                        TerrainLoader tl = ((GaiaScenePlayer)target).GetComponentInChildren <TerrainLoader>();
                        if (tl != null)
                        {
                            m_profile.UpdateTerrainLoaderFromProfile(ref tl);
                        }
                    }
#endif
                }
            }

            EditorGUILayout.BeginHorizontal();

            if (m_editorUtils.Button("MoveCameraToPlayer"))
            {
                GaiaSceneManagement.MoveCameraToPlayer(m_gaiaSettings);
            }

            if (m_editorUtils.Button("MovePlayerToCamera"))
            {
                GaiaSceneManagement.MovePlayerToCamera(m_gaiaSettings);
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            m_editorUtils.Panel("AutoDepthOfFieldSettings", AutoDepthOfField);
            m_editorUtils.Panel("LocationManagerSettings", LocationManagerSettings);
            m_editorUtils.Panel("PlayerCameraCullingSettings", CameraCullingSettings);
            if (GaiaUtils.HasDynamicLoadedTerrains())
            {
                m_editorUtils.Panel("TerrainLoadingSettings", TerrainLoadingSettings);
            }
        }
예제 #3
0
        private void SaveAndLoad(bool helpEnabled)
        {
            EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("SaveAndLoadHelpText"), MessageType.Info);

            if (m_profile.SceneProfile == null)
            {
                m_profile.SceneProfile = ScriptableObject.CreateInstance <SceneProfile>();
            }

            bool canBeSaved = true;

            if (!m_profile.SceneProfile.DefaultLightingSet)
            {
                EditorGUILayout.HelpBox("No lighting profile settings have been saved. Please use gaia default lighting profile to save them here.", MessageType.Warning);
                canBeSaved = false;
            }
            else
            {
                //EditorGUILayout.HelpBox("Lighting profile has been saved", MessageType.Info);
            }

            if (!m_profile.SceneProfile.DefaultWaterSet)
            {
                EditorGUILayout.HelpBox("No water profile settings have been saved. Please use gaia default water profile to save them here.", MessageType.Warning);
                canBeSaved = false;
            }
            else
            {
                //EditorGUILayout.HelpBox("Water profile has been saved", MessageType.Info);
            }

            EditorGUILayout.BeginHorizontal();
            if (!canBeSaved)
            {
                GUI.enabled = false;
            }

            //string path = Application.dataPath + "/Assets";
            string path = "";

            if (m_editorUtils.Button("Save"))
            {
                string sceneName = EditorSceneManager.GetActiveScene().name;
                if (string.IsNullOrEmpty(sceneName))
                {
                    Debug.LogWarning("Unable to save file as scene has not been saved. Please save your scene then try again.");
                }

                path = EditorUtility.SaveFilePanelInProject("Save Location", sceneName + " Profile", "asset", "Save new profile asset");
                GaiaSceneManagement.SaveFile(m_profile.SceneProfile, path);
                EditorGUIUtility.ExitGUI();
            }

            GUI.enabled = true;

            if (m_editorUtils.Button("Load"))
            {
                path = EditorUtility.OpenFilePanel("Load Profile", Application.dataPath + "/Assets", "asset");
                GaiaSceneManagement.LoadFile(path);
                EditorGUIUtility.ExitGUI();
            }

            if (m_editorUtils.Button("Revert"))
            {
                GaiaSceneManagement.Revert(m_profile.SceneProfile);
                EditorGUIUtility.ExitGUI();
            }
            EditorGUILayout.EndHorizontal();
        }
예제 #4
0
        private void AutoDepthOfField(bool helpEnabled)
        {
#if UNITY_POST_PROCESSING_STACK_V2
            if (GaiaUtils.GetActivePipeline() == GaiaConstants.EnvironmentRenderer.BuiltIn)
            {
                //Get Auto Focus object
                AutoDepthOfField autoFocus = GaiaSceneManagement.SetupAutoDepthOfField(m_profile);

                //Monitor for changes
                EditorGUI.BeginChangeCheck();
                bool enableDOF = m_profile.m_enableAutoDOF;
                enableDOF = m_editorUtils.Toggle("EnableAutoDepthOfField", enableDOF, helpEnabled);
                if (m_profile.m_enableAutoDOF != enableDOF)
                {
                    m_profile.m_enableAutoDOF = enableDOF;
                    autoFocus = GaiaSceneManagement.SetupAutoDepthOfField(m_profile);
                }
                if (autoFocus != null && m_profile.m_enableAutoDOF)
                {
                    if (enableDOF)
                    {
                        bool oldDebugValue = autoFocus.m_debug;
                        autoFocus.m_debug = m_editorUtils.Toggle("ShowDebugInfo", autoFocus.m_debug);
                        if (oldDebugValue != autoFocus.m_debug && !autoFocus.m_debug)
                        {
                            autoFocus.RemoveDebugSphere();
                        }
                    }

#if !UNITY_POST_PROCESSING_STACK_V2
                    EditorGUILayout.HelpBox("Post Processing is not installed. Please install post processing from the package manager to use this feature. (Window/Package Manager)", MessageType.Warning);
                    GUI.enabled = false;
#endif
                    m_editorUtils.Heading("AutoFocusDependencies");
                    EditorGUI.indentLevel++;
                    autoFocus.m_sourceCamera = (Camera)m_editorUtils.ObjectField("SourceCamera", autoFocus.m_sourceCamera, typeof(Camera), true, helpEnabled);
                    if (autoFocus.m_sourceCamera == null)
                    {
                        EditorGUILayout.HelpBox("Source Camera is missing. Either add it manually or it will be added on start of application if present", MessageType.Error);
                    }
                    autoFocus.m_targetObject = (GameObject)m_editorUtils.ObjectField("TargetObject", autoFocus.m_targetObject, typeof(GameObject), true, helpEnabled);
                    if (autoFocus.m_targetObject == null && autoFocus.m_trackingType == GaiaConstants.DOFTrackingType.FollowTarget)
                    {
                        EditorGUILayout.HelpBox("Target Object is missing. Add it to use target focus mode", MessageType.Error);
                    }
                    autoFocus.m_targetLayer = GaiaEditorUtils.LayerMaskField(new GUIContent(m_editorUtils.GetTextValue("TargetLayer"), m_editorUtils.GetTooltip("TargetLayer")), autoFocus.m_targetLayer);
                    m_editorUtils.InlineHelp("TargetLayer", helpEnabled);
                    EditorGUI.indentLevel--;

                    m_editorUtils.Heading("AutoFocusConfiguration");
                    EditorGUI.indentLevel++;
                    autoFocus.m_interactWithPlayer = m_editorUtils.Toggle("InteractWithPlayer", autoFocus.m_interactWithPlayer, helpEnabled);
                    autoFocus.m_trackingType       = (GaiaConstants.DOFTrackingType)m_editorUtils.EnumPopup("TrackingMode", autoFocus.m_trackingType, helpEnabled);
                    autoFocus.m_focusOffset        = m_editorUtils.FloatField("FocusOffset", autoFocus.m_focusOffset, helpEnabled);
                    autoFocus.m_maxFocusDistance   = m_editorUtils.FloatField("MaxFocusDistance", autoFocus.m_maxFocusDistance, helpEnabled);
                    autoFocus.m_dofAperture        = m_editorUtils.Slider("Aperture", autoFocus.m_dofAperture, 0.1f, 32f, helpEnabled);
                    autoFocus.m_dofFocalLength     = m_editorUtils.Slider("FocalLength", autoFocus.m_dofFocalLength, 1f, 300f, helpEnabled);
                    if (Application.isPlaying)
                    {
                        EditorGUILayout.LabelField("Actual Focal Distance: " + autoFocus.m_actualFocusDistance);
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Actual Focal Distance: Will be updated at runtime");
                    }
                    m_editorUtils.InlineHelp("ActualFocalDistance", helpEnabled);

                    EditorGUI.indentLevel--;
                }

                //Check for changes, make undo record, make changes and let editor know we are dirty
                if (EditorGUI.EndChangeCheck())
                {
                    if (autoFocus != null)
                    {
                        Undo.RecordObject(autoFocus, "Made depth of field changes");
                        EditorUtility.SetDirty(autoFocus);
                        autoFocus.SetDOFMainSettings(autoFocus.m_dofAperture, autoFocus.m_dofFocalLength);
                    }

                    EditorUtility.SetDirty(m_profile);
                }
            }
            else
            {
                m_profile.m_enableAutoDOF = false;
                GaiaSceneManagement.SetupAutoDepthOfField(m_profile);
                EditorGUILayout.HelpBox("Auto Depth Of Field is not yet supported for SRP this will be available in a near future update", MessageType.Info);
            }
#else
            EditorGUILayout.HelpBox("Post Processing V2 has not been isntalled. Please install Post Processing from the package manager to use auto depth of field.", MessageType.Info);
#endif
        }