public static SceneProfile Load(string saveName, string folderName)
    {
        string path = Path.Combine(Application.persistentDataPath, "Saves");

        path = Path.Combine(path, folderName);
        path = Path.Combine(path, saveName + ".humble");

        if (File.Exists(path))
        {
            string loadJson = File.ReadAllText(path);

            SceneProfile sceneProfile = JsonUtility.FromJson <SceneProfile>(loadJson);

            return(sceneProfile);
        }
        else
        {
            Debug.LogError("Save file not found.");
            return(null);
        }
    }
    public static void Save(string saveName, string folderName, SceneData sceneData)
    {
        string path = Path.Combine(Application.persistentDataPath, "Saves");

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        path = Path.Combine(path, folderName);

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        path = Path.Combine(path, saveName + ".humble");

        SceneProfile sceneProfile = new SceneProfile(sceneData);
        string       saveJson     = JsonUtility.ToJson(sceneProfile, true);

        File.WriteAllText(path, saveJson);
    }
Пример #3
0
        /// <summary>
        /// Crate post processing instance profile
        /// </summary>
        /// <param name="sceneProfile"></param>
        public static void CreatePostFXProfileInstance(SceneProfile sceneProfile, GaiaLightingProfileValues profile)
        {
            try
            {
                if (sceneProfile == null)
                {
                    return;
                }

#if UPPipeline
                VolumeProfile volumeProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaUtils.GetAssetPath("URP Global Post Processing Profile.asset"));
                if (profile.PostProcessProfileURP != null)
                {
                    volumeProfile = profile.PostProcessProfileURP;
                }
                if (volumeProfile == null)
                {
                    return;
                }

                GaiaSessionManager session = GaiaSessionManager.GetSessionManager();
                if (session != null)
                {
                    string path = GaiaDirectories.GetSceneProfilesFolderPath(session.m_session);
                    if (!string.IsNullOrEmpty(path))
                    {
                        if (EditorSceneManager.GetActiveScene() != null)
                        {
                            if (!string.IsNullOrEmpty(EditorSceneManager.GetActiveScene().path))
                            {
                                path = path + "/" + EditorSceneManager.GetActiveScene().name + " " + volumeProfile.name + " Profile.asset";
                            }
                            else
                            {
                                path = path + "/" + volumeProfile.name + " HDRP Post FX Profile.asset";
                            }
                        }
                        else
                        {
                            path = path + "/" + volumeProfile.name + " HDRP Post FX Profile.asset";
                        }

                        if (sceneProfile.m_universalPostFXProfile != null)
                        {
                            if (!sceneProfile.m_isUserProfileSet)
                            {
                                if (!sceneProfile.m_universalPostFXProfile.name.Contains(volumeProfile.name))
                                {
                                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(sceneProfile.m_universalPostFXProfile));
                                    sceneProfile.m_universalPostFXProfile = null;
                                }
                            }
                        }

                        if (AssetDatabase.LoadAssetAtPath <VolumeProfile>(path) == null)
                        {
                            FileUtil.CopyFileOrDirectory(AssetDatabase.GetAssetPath(volumeProfile), path);
                            AssetDatabase.ImportAsset(path);
                        }

                        sceneProfile.m_universalPostFXProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(path);
                    }
                }
#endif
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Пример #4
0
        /// <summary>
        /// Apply URP post fx
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="lightingProfile"></param>
        public static GameObject ApplyURPPostProcessing(GaiaLightingProfileValues profile, SceneProfile lightingProfile)
        {
            try
            {
                GameObject volumeObject = null;
#if UPPipeline
                if (lightingProfile.m_enablePostProcessing)
                {
                    volumeObject = GameObject.Find("Global Post Processing");
                    if (volumeObject == null)
                    {
                        volumeObject = new GameObject("Global Post Processing");
                    }

                    GameObject parentObject = GaiaLighting.GetOrCreateParentObject(GaiaConstants.gaiaLightingObject, true);
                    if (parentObject != null)
                    {
                        volumeObject.transform.SetParent(parentObject.transform);
                    }
                    volumeObject.layer = 0;

                    Volume volume = volumeObject.GetComponent <Volume>();
                    if (volume == null)
                    {
                        volume = volumeObject.AddComponent <Volume>();
                    }

                    if (GaiaGlobal.Instance != null)
                    {
                        SceneProfile sceneProfile = GaiaGlobal.Instance.SceneProfile;
                        if (sceneProfile != null)
                        {
                            if (sceneProfile.m_lightingEditSettings || profile.m_userCustomProfile)
                            {
                                sceneProfile.m_universalPostFXProfile = profile.PostProcessProfileURP;
                            }
                            else
                            {
                                CreatePostFXProfileInstance(sceneProfile, profile);
                            }

                            volume.sharedProfile = sceneProfile.m_universalPostFXProfile;

                            Camera camera = GaiaUtils.GetCamera();
                            if (camera != null)
                            {
                                UniversalAdditionalCameraData cameraData = camera.GetComponent <UniversalAdditionalCameraData>();
                                if (cameraData == null)
                                {
                                    cameraData = camera.gameObject.AddComponent <UniversalAdditionalCameraData>();
                                }

                                cameraData.renderPostProcessing = true;
                                GaiaLighting.ConfigureAntiAliasing(sceneProfile, GaiaConstants.EnvironmentRenderer.Universal);
                            }
                        }
                    }
                }
                else
                {
                    volumeObject = GameObject.Find("Global Post Processing");
                    if (volumeObject != null)
                    {
                        GameObject.DestroyImmediate(volumeObject);
                    }

                    Camera camera = GaiaUtils.GetCamera();
                    if (camera != null)
                    {
                        UniversalAdditionalCameraData cameraData = camera.GetComponent <UniversalAdditionalCameraData>();
                        if (cameraData == null)
                        {
                            cameraData = camera.gameObject.AddComponent <UniversalAdditionalCameraData>();
                        }

                        cameraData.renderPostProcessing = false;
                    }
                }
    #endif
    #if UNITY_POST_PROCESSING_STACK_V2
                PostProcessLayer postProcessLayer = GameObject.FindObjectOfType <PostProcessLayer>();
                if (postProcessLayer != null)
                {
                    GameObject.DestroyImmediate(postProcessLayer);
                }

                PostProcessVolume postProcessVolume = GameObject.FindObjectOfType <PostProcessVolume>();
                if (postProcessVolume != null)
                {
                    GameObject.DestroyImmediate(postProcessVolume);
                }
    #endif

                return(volumeObject);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
 public void Load()
 {
     sceneProfile          = SceneDataSystem.Load("sceneData", "Scene");
     sceneData.sceneLoaded = true;
     LoadScene();
 }
    void Awake()
    {
        sceneData.scene = SceneManager.GetActiveScene();

        sceneProfile = SceneDataSystem.Load("sceneData", "Scene");
    }
        private static void OpenMultiscene(SceneProfile obj, bool additive)
        {
            Scene activeScene = default(Scene);

            if (additive || EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                var   firstUnloadedScenes   = new List <string>();
                var   inFirstUnloadedScenes = true;
                Scene firstLoadedScene      = default(Scene);

                for (int i = 0; i < obj.Scenes.Count; i++)
                {
                    var info = obj.Scenes[i];

                    if (info == null)
                    {
                        continue;
                    }

                    var path          = AssetDatabase.GetAssetPath(info.GetInstanceID());
                    var mode          = OpenSceneMode.Single;
                    var isActiveScene = info == true;

                    var exitedFirstUnloadedScenes = false;

                    if (inFirstUnloadedScenes)
                    {
                        if (!isActiveScene)
                        {
                            firstUnloadedScenes.Add(path);

                            continue;
                        }
                        else
                        {
                            inFirstUnloadedScenes     = false;
                            exitedFirstUnloadedScenes = true;
                        }
                    }

                    if ((!inFirstUnloadedScenes && !exitedFirstUnloadedScenes) || (additive && exitedFirstUnloadedScenes))
                    {
                        if ((!additive && isActiveScene))
                        {
                            mode = OpenSceneMode.Additive;
                        }
                        else
                        {
                            mode = OpenSceneMode.AdditiveWithoutLoading;
                        }
                    }

                    var scene = EditorSceneManager.OpenScene(path, mode);

                    if (isActiveScene)
                    {
                        activeScene = scene;
                    }
                    if (exitedFirstUnloadedScenes)
                    {
                        firstLoadedScene = scene;
                    }
                }

                for (int i = 0; i < firstUnloadedScenes.Count; i++)
                {
                    var path  = firstUnloadedScenes[i];
                    var scene = EditorSceneManager.OpenScene(path, OpenSceneMode.AdditiveWithoutLoading);
                    if (firstLoadedScene.IsValid())
                    {
                        EditorSceneManager.MoveSceneBefore(scene, firstLoadedScene);
                    }
                }
            }

            if (!additive && activeScene.IsValid())
            {
                EditorSceneManager.SetActiveScene(activeScene);
            }
        }