Ejemplo n.º 1
0
            void ICustomVisit <UTinyEnum.Reference> .CustomVisit(UTinyEnum.Reference value)
            {
                var type       = value.Type.Dereference(VisitorContext.Registry);
                var normalized = ExportEnumAsValue ? (type.DefaultValue as UTinyObject)?[value.Name] : $"{UTinyBuildPipeline.GetJsTypeName(type)}.{value.Name}";

                VisitorContext.Writer.Line($"{Path}.{Property.Name} = {normalized};");
            }
Ejemplo n.º 2
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);
        }