/// <summary>
        /// Create GameObjects with Components using data from PersistentScene object
        /// </summary>
        /// <param name="scene">PersistentScene</param>
        public static void InstantiateGameObjects(PersistentScene scene)
        {
            if (IdentifiersMap.Instance == null)
            {
                Debug.LogError("Create Runtime Resource Map");
                return;
            }

            DestroyGameObjects();
            if (scene.Data == null && scene.Descriptors == null)
            {
                return;
            }

            if (scene.Data == null && scene.Descriptors != null || scene.Data != null && scene.Descriptors == null)
            {
                throw new ArgumentException("data is corrupted", "scene");
            }

            if (scene.Descriptors.Length == 0)
            {
                return;
            }


            bool includeDynamicResources = true;
            //1. Find prefabs and other resources;
            Dictionary <long, UnityObject> resources = IdentifiersMap.FindResources(includeDynamicResources);

            PersistentDescriptor.GetOrCreateGameObjects(scene.Descriptors, resources /*, scene.ActiveSelf*/);
            PersistentData.RestoreDataAndResolveDependencies(scene.Data, resources);
        }
示例#2
0
        /// <summary>
        /// Create PersistentScene object for active scene
        /// </summary>
        /// <returns>PersistentScene object</returns>
        public static PersistentScene CreatePersistentScene(params Type[] ignoreTypes)
        {
            if (IdentifiersMap.Instance == null)
            {
                Debug.LogError("Create Runtime Resource Map");
                return(null);
            }

            GameObject[]    gameObjects     = SceneManager.GetActiveScene().GetRootGameObjects().OrderBy(g => g.transform.GetSiblingIndex()).ToArray();
            PersistentScene persistentScene = new PersistentScene();

            PersistentData.CreatePersistentDescriptorsAndData(gameObjects, out persistentScene.Descriptors, out persistentScene.Data /*, out persistentScene.ActiveSelf*/);

            return(persistentScene);
        }
示例#3
0
        public virtual void LoadScene(ProjectItem scene, ProjectManagerCallback callback)
        {
            RaiseSceneLoading(scene);

            bool isEnabled = RuntimeUndo.Enabled;

            RuntimeUndo.Enabled      = false;
            RuntimeSelection.objects = null;
            RuntimeUndo.Enabled      = isEnabled;

            m_project.LoadData(new[] { scene }, loadDataCompleted =>
            {
                scene = loadDataCompleted.Data[0];

                PersistentScene persistentScene = m_serializer.Deserialize <PersistentScene>(scene.Internal_Data.RawData);
                CompleteSceneLoading(scene, callback, isEnabled, persistentScene);
            });
        }
        public virtual void SaveScene(ProjectItem scene, ProjectManagerCallback callback)
        {
            if (SceneSaving != null)
            {
                SceneSaving(this, new ProjectManagerEventArgs(scene));
            }

            GameObject     extraData = new GameObject();
            ExtraSceneData saveLoad  = extraData.AddComponent <ExtraSceneData>();

            saveLoad.Selection = RuntimeSelection.objects;

            PersistentScene persistentScene = PersistentScene.CreatePersistentScene(
                typeof(SealTeam4.GameManager),
                typeof(SealTeam4.GameManagerAssistant),
                typeof(SealTeam4.RuntimeEditorUltiltes),
                typeof(UnityEngine.Networking.NetworkIdentity)
                );

            if (scene.Internal_Data == null)
            {
                scene.Internal_Data = new ProjectItemData();
            }
            scene.Internal_Data.RawData = m_serializer.Serialize(persistentScene);
            Destroy(extraData);

            m_project.Save(scene, false, saveCompleted =>
            {
                m_project.UnloadData(scene);

                m_activeScene = scene;

                if (callback != null)
                {
                    callback();
                }

                if (SceneSaved != null)
                {
                    SceneSaved(this, new ProjectManagerEventArgs(scene));
                }
            });
        }
示例#5
0
        protected void CompleteSceneLoading(ProjectItem scene, ProjectManagerCallback callback, bool isEnabled, PersistentScene persistentScene)
        {
            PersistentScene.InstantiateGameObjects(persistentScene);

            m_project.UnloadData(scene);

            ExtraSceneData extraData = FindObjectOfType <ExtraSceneData>();

            RuntimeUndo.Enabled      = false;
            RuntimeSelection.objects = extraData.Selection;
            RuntimeUndo.Enabled      = isEnabled;
            Destroy(extraData.gameObject);

            m_activeScene = scene;

            if (callback != null)
            {
                callback();
            }

            RaiseSceneLoaded(scene);
        }
示例#6
0
        public virtual void SaveScene(ProjectItem scene, ProjectManagerCallback callback)
        {
            if (SceneSaving != null)
            {
                SceneSaving(this, new ProjectManagerEventArgs(scene));
            }

            GameObject     extraData = new GameObject();
            ExtraSceneData saveLoad  = extraData.AddComponent <ExtraSceneData>();

            saveLoad.Selection = m_editor.Selection.objects;

            PersistentScene persistentScene = PersistentScene.CreatePersistentScene();

            if (scene.Internal_Data == null)
            {
                scene.Internal_Data = new ProjectItemData();
            }
            scene.Internal_Data.RawData = m_serializer.Serialize(persistentScene);
            Destroy(extraData);

            m_project.Save(scene, false, saveCompleted =>
            {
                m_project.UnloadData(scene);

                m_activeScene = scene;

                if (callback != null)
                {
                    callback();
                }

                if (SceneSaved != null)
                {
                    SceneSaved(this, new ProjectManagerEventArgs(scene));
                }
            });
        }
示例#7
0
        public static void LoadScene()
        {
            string path = EditorUtility.OpenFilePanel("Open Scene", Application.persistentDataPath, "rtsc");

            if (path.Length != 0)
            {
                IProject    project    = Dependencies.Project;
                ISerializer serializer = Dependencies.Serializer;

                project.Load(new[] { path }, loadDataCompleted =>
                {
                    ProjectItem scene = loadDataCompleted.Data[0];

                    PersistentScene persistentScene = serializer.Deserialize <PersistentScene>(scene.Internal_Data.RawData);
                    PersistentScene.InstantiateGameObjects(persistentScene);

                    project.UnloadData(scene);

                    ExtraSceneData extraData = Object.FindObjectOfType <ExtraSceneData>();
                    Object.DestroyImmediate(extraData.gameObject);
                });
            }
        }