Esempio n. 1
0
        private static void GenerateNewProjectAssets(
            DirectoryInfo projectDirectory,
            string name,
            IWorldManager worldManager,
            IArchetypeManager archetypeManager,
            IPersistenceManager persistenceManager
            )
        {
            // Create config entity
            var configEntity = worldManager.CreateEntity(archetypeManager.Config);

            worldManager.EntityManager.SetComponentData(configEntity, DisplayInfo.Default);

            // Generate main scene
            var cameraEntity = worldManager.CreateEntity("Camera", archetypeManager.Camera);

            worldManager.EntityManager.SetComponentData(cameraEntity, Camera2D.Default);
            worldManager.EntityManager.SetComponentData(cameraEntity, DomainCache.GetDefaultValue <Camera2D>());
            worldManager.EntityManager.SetComponentData(cameraEntity, DomainCache.GetDefaultValue <Rotation>());
            worldManager.EntityManager.SetComponentData(cameraEntity, DomainCache.GetDefaultValue <NonUniformScale>());

            using (var entities = new NativeArray <Entity>(cameraEntity.AsArray(), Allocator.Temp))
            {
                var scene     = SceneManager.Create(worldManager.EntityManager, entities, Guid.NewGuid());
                var sceneFile = projectDirectory.Combine("Scenes").GetFile("MainScene.scene");
                sceneFile.Directory.EnsureExists();
                persistenceManager.SaveScene(worldManager.EntityManager, scene, sceneFile.FullName);

                var sceneReference = new SceneReference {
                    SceneGuid = scene.SceneGuid.Guid
                };

                AddScene(worldManager.EntityManager, worldManager.GetConfigEntity(), sceneReference);
                AddStartupScene(worldManager.EntityManager, worldManager.GetConfigEntity(), sceneReference);
            }

            // Generate configuration scene
            using (var entities = new NativeArray <Entity>(configEntity.AsArray(), Allocator.Temp))
            {
                var configurationScene = SceneManager.Create(worldManager.EntityManager, entities, ConfigurationScene.Guid);
                var configurationFile  = projectDirectory.GetFile(name).ChangeExtension("configuration");
                configurationFile.Directory.EnsureExists();
                persistenceManager.SaveScene(worldManager.EntityManager, configurationScene, configurationFile.FullName);

                // Hack: remove scene guid/instance id and persistence id
                worldManager.EntityManager.RemoveComponent <SceneGuid>(configEntity);
                worldManager.EntityManager.RemoveComponent <SceneInstanceId>(configEntity);
            }
        }
Esempio n. 2
0
        public void UnloadSceneWithDialog(Scene scene)
        {
            if (IsSceneChanged(scene))
            {
                var dialogResult = EditorUtility.DisplayDialogComplex(
                    $"Save Scene",
                    $"There are unsaved changes in the Scene, do you want to save?",
                    "Yes",
                    "No",
                    "Cancel");

                switch (dialogResult)
                {
                case 0:
                    // Yes: Save and continue closing the project
                    var assetPath = m_Persistence.GetSceneAssetPath(scene);
                    if (!string.IsNullOrEmpty(assetPath))
                    {
                        m_Persistence.SaveScene(m_WorldManager.EntityManager, scene, assetPath);
                    }
                    break;

                case 1:
                    // No: Don't save and continue closing the project
                    break;

                case 2:
                    // Cancel: Opt out, the user has canceled the operation
                    return;
                }
            }
            UnloadScene(scene);
        }