Esempio n. 1
0
        private static void SaveState(FileInfo file, Project project)
        {
            var editorSceneManager = project.Session.GetManager <IEditorSceneManager>();

            var scenes = new List <Scene>();

            for (var i = 0; i < editorSceneManager.LoadedSceneCount; i++)
            {
                scenes.Add(editorSceneManager.GetLoadedSceneAtIndex(i));
            }

            var assetGuid     = AssetDatabaseUtility.GetAssetGuid(Application.AuthoringProject.GetProjectFile());
            var entityManager = project.Session.GetManager <IWorldManager>().EntityManager;

            // This does not scale!
            // @TODO Stream API
            var json = JsonSerialization.Serialize(new SessionState
            {
                ProjectAssetGuid = assetGuid,
                EntityManager    = entityManager,
                Scenes           = scenes
            }, new EntityJsonVisitor(entityManager));

            file.WriteAllText(json);
        }
Esempio n. 2
0
        internal static Project Open(FileInfo projectFile)
        {
            var project = new Project
            {
                Settings = JsonSerialization.Deserialize <ProjectSettings>(projectFile.FullName)
            };

            project.Guid = new Guid(projectFile.ToAssetGuid());

            // Patch up any guid references if they are missing.
            if (Guid.Empty == project.Settings.Configuration)
            {
                project.Settings.Configuration = new Guid(AssetDatabaseUtility.GetAssetGuid(projectFile.ChangeExtension(k_ConfigurationFileExtension)));
            }

            if (Guid.Empty == project.Settings.MainAsmdef)
            {
                project.Settings.MainAsmdef = new Guid(AssetDatabaseUtility.GetAssetGuid(projectFile.ChangeExtension(k_AssemblyDefinitionFileExtension)));
            }

            if (!DomainReload.IsDomainReloading)
            {
                var entityManager = project.EntityManager;
                var configFile    = project.GetConfigurationFile();

                if (configFile.Exists)
                {
                    project.PersistenceManager.LoadScene(entityManager, configFile.FullName);

                    // Hack: remove scene guid/instance id
                    var configEntity = project.WorldManager.GetConfigEntity();
                    entityManager.RemoveComponent <SceneGuid>(configEntity);
                    entityManager.RemoveComponent <SceneInstanceId>(configEntity);
                }
                else
                {
                    var configEntity = project.WorldManager.CreateEntity(project.ArchetypeManager.Config);
                    entityManager.SetComponentData(configEntity, DisplayInfo.Default);
                }
            }

            s_Projects.Add(project);
            ProjectOpened(project);

            DomainCache.CacheIncludedAssemblies(project);
            return(project);
        }