Exemplo n.º 1
0
        /// <summary>
        /// Loads the utmodule at the given file path
        /// </summary>
        /// <param name="moduleFile">Relative path to the .utmodule file</param>
        public static void LoadModule(string moduleFile)
        {
            Assert.IsFalse(EditorApplication.isPlayingOrWillChangePlaymode);

            var context  = new UTinyContext();
            var registry = context.Registry;

            UTinyPersistence.LoadModule(moduleFile, registry);

            var module = registry.FindAllBySource(UTinyRegistry.DefaultSourceIdentifier).OfType <UTinyModule>().First();

            Assert.IsNotNull(module);

            module.Name = Path.GetFileNameWithoutExtension(moduleFile);

            SetupModule(registry, module);

            var project = registry.CreateProject(UTinyId.Generate(KWorkspaceProjectName), KWorkspaceProjectName);

            project.Module = (UTinyModule.Reference)module;

            var editorContext = new UTinyEditorContext((UTinyProject.Reference)project, EditorContextType.Module, context, UTinyEditorPrefs.LoadWorkspace(project.PersistenceId));

            LoadContext(editorContext, isChanged: false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates and loads a new .utmodule
        /// @NOTE The module only exists in memory until Save() is called
        /// </summary>
        public static void NewModule()
        {
            var context  = new UTinyContext();
            var registry = context.Registry;

            UTinyPersistence.LoadAllModules(registry);

            // Create a `workspace` project to host the module for editing purposes
            var project = registry.CreateProject(UTinyId.Generate(KWorkspaceProjectName), KWorkspaceProjectName);

            // Create objects for the new module
            var module = registry.CreateModule(UTinyId.New(), "NewModule");

            // Setup initial state for the module
            module.Namespace = "module";

            SetupModule(registry, module);

            project.Module = (UTinyModule.Reference)module;

            var workspace = new UTinyEditorWorkspace();

            UTinyEditorPrefs.SaveWorkspace(workspace);

            var editorContext = new UTinyEditorContext((UTinyProject.Reference)project, EditorContextType.Module, context, workspace);

            LoadContext(editorContext, isChanged: true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates and loads a new .utproject
        /// @NOTE The project only exists in memory until Save() is called
        /// </summary>
        public static void NewProject()
        {
            Assert.IsFalse(EditorApplication.isPlayingOrWillChangePlaymode);

            var context  = new UTinyContext();
            var registry = context.Registry;

            UTinyPersistence.LoadAllModules(registry);

            // Create new objects for the project
            var project = registry.CreateProject(UTinyId.New(), "NewProject");
            var module  = registry.CreateModule(UTinyId.New(), "Main");

            // Setup the start scene
            var entityGroup    = registry.CreateEntityGroup(UTinyId.New(), "NewEntityGroup");
            var entityGroupRef = (UTinyEntityGroup.Reference)entityGroup;
            var cameraEntity   = registry.CreateEntity(UTinyId.New(), "Camera");
            var transform      = cameraEntity.AddComponent(registry.GetTransformType());

            transform.Refresh();
            var camera = cameraEntity.AddComponent(registry.GetCamera2DType());

            camera.Refresh();
            camera["clearFlags"] = new UTinyEnum.Reference(registry.GetCameraClearFlagsType().Dereference(registry), 1);
            camera.AssignPropertyFrom("backgroundColor", Color.black);
            camera["depth"] = -1.0f;
            entityGroup.AddEntityReference((UTinyEntity.Reference)cameraEntity);

            // Setup initial state for the project
            module.Options           |= UTinyModuleOptions.ProjectModule;
            module.Namespace          = "game";
            module.StartupEntityGroup = (UTinyEntityGroup.Reference)entityGroup;

            module.AddEntityGroupReference(entityGroupRef);

            project.Module = (UTinyModule.Reference)module;
            project.Settings.EmbedAssets  = true;
            project.Settings.CanvasWidth  = 1920;
            project.Settings.CanvasHeight = 1080;

            SetupProject(registry, project);

            module.AddExplicitModuleDependency((UTinyModule.Reference)registry.FindByName <UTinyModule>("UTiny.Core2D"));

            // Always include a dependency on core, math, core2d by default
            // And HTML for now, since it is the only renderer we have right now.
            module.AddExplicitModuleDependency((UTinyModule.Reference)registry.FindByName <UTinyModule>("UTiny.HTML"));

            var workspace = new UTinyEditorWorkspace
            {
                OpenedEntityGroups = { entityGroupRef },
                ActiveEntityGroup  = entityGroupRef
            };

            UTinyEditorPrefs.SaveWorkspace(workspace);

            var editorContext = new UTinyEditorContext((UTinyProject.Reference)project, EditorContextType.Project, context, workspace);

            LoadContext(editorContext, isChanged: true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Trys to loads the last saved temp file
        /// </summary>
        public static void LoadTemp()
        {
            Assert.IsFalse(EditorApplication.isPlayingOrWillChangePlaymode);

            if (!UTinyTemp.Exists())
            {
                return;
            }

            var context  = new UTinyContext();
            var registry = context.Registry;

            string persistenceId;

            if (!UTinyTemp.Accept(registry, out persistenceId))
            {
                LoadPersistenceId(persistenceId);
                return;
            }

            var project = registry.FindAllByType <UTinyProject>().FirstOrDefault();
            UTinyEditorContext editorContext = null;

            if (project != null)
            {
                SetupProject(registry, project);

                editorContext = new UTinyEditorContext((UTinyProject.Reference)project, EditorContextType.Project, context, UTinyEditorPrefs.LoadLastWorkspace());
            }
            else
            {
                var module = registry.FindAllBySource(UTinyRegistry.DefaultSourceIdentifier).OfType <UTinyModule>().First();

                SetupModule(registry, module);

                if (null != module)
                {
                    project        = registry.CreateProject(UTinyId.Generate(KWorkspaceProjectName), KWorkspaceProjectName);
                    project.Module = (UTinyModule.Reference)module;

                    editorContext = new UTinyEditorContext((UTinyProject.Reference)project, EditorContextType.Module, context, UTinyEditorPrefs.LoadLastWorkspace());
                }
            }

            Assert.IsNotNull(project);
            LoadContext(editorContext, true);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads the utproject at the given file path
        /// </summary>
        /// <param name="projectFile">Relative path to the .utproject file</param>
        public static void LoadProject(string projectFile)
        {
            Assert.IsFalse(EditorApplication.isPlayingOrWillChangePlaymode);

            var context  = new UTinyContext();
            var registry = context.Registry;

            UTinyPersistence.LoadProject(projectFile, registry);

            var project = registry.FindAllByType <UTinyProject>().First();

            Assert.IsNotNull(project);

            project.Name = Path.GetFileNameWithoutExtension(projectFile);

            SetupProject(registry, project);

            var editorContext = new UTinyEditorContext((UTinyProject.Reference)project, EditorContextType.Project, context, UTinyEditorPrefs.LoadWorkspace(project.PersistenceId));

            LoadContext(editorContext, isChanged: false);
        }
Exemplo n.º 6
0
 public UTinyEditorContext(UTinyProject.Reference project, EditorContextType type, UTinyContext context, UTinyEditorWorkspace workspace)
 {
     m_Project          = project;
     ContextType        = type;
     Context            = context ?? new UTinyContext();
     Workspace          = workspace ?? new UTinyEditorWorkspace();
     Undo               = new UTinyUndo(Registry, Caretaker);
     EntityGroupManager = new UTinyEntityGroupManager(this);
 }