public T FindById <T>(UTinyId id) where T : class, IRegistryObject
        {
            IRegistryObject t;

            m_Objects.TryGetValue(id, out t);
            return(t as T);
        }
 public Reference(UTinyType.Reference type, UTinyId id, string name, int value)
 {
     m_Type  = type;
     m_Id    = id;
     m_Name  = name;
     m_Value = value;
 }
예제 #3
0
        public UTinyField CreateField(UTinyId id, string name, Reference type, bool array = false)
        {
            var field = NewField(id, name, type, array);

            s_FieldsProperty.Add(this, field);
            return(field);
        }
        static UTinyUpdater()
        {
            // @TODO Move registration to an external class

            // Move into Math module
            RegisterTypeIdChange("UTiny.Core.Vector2f", "UTiny.Math.Vector2");
            RegisterTypeIdChange("UTiny.Core.Vector3f", "UTiny.Math.Vector3");
            RegisterTypeIdChange("UTiny.Core.Vector4f", "UTiny.Math.Vector4");
            RegisterTypeIdChange("UTiny.Core.Matrix3x3f", "UTiny.Math.Matrix3x3");
            RegisterTypeIdChange("UTiny.Core.Matrix4x4f", "UTiny.Math.Matrix4x4");
            RegisterTypeIdChange("UTiny.Core.Quaternionf", "UTiny.Math.Quaternion");
            RegisterTypeIdChange("UTiny.Core.Rectf", "UTiny.Math.Rect");
            RegisterTypeIdChange("UTiny.Core.RectInt", "UTiny.Math.RectInt");

            // moves into Core2D module
            RegisterTypeIdChange("UTiny.Core.DisplayOrientation", "UTiny.Core2D.DisplayOrientation");
            RegisterTypeIdChange("UTiny.Core.DisplayInfo", "UTiny.Core2D.DisplayInfo");
            RegisterTypeIdChange("UTiny.Core.MouseState", "UTiny.Core2D.MouseState");
            RegisterTypeIdChange("UTiny.Core.Camera2D", "UTiny.Core2D.Camera2D");
            RegisterTypeIdChange("UTiny.Core.Image2D", "UTiny.Core2D.Image2D");
            RegisterTypeIdChange("UTiny.Core.Sprite2D", "UTiny.Core2D.Sprite2D");
            RegisterTypeIdChange("UTiny.Core.Sprite2DRenderer", "UTiny.Core2D.Sprite2DRenderer");
            RegisterTypeIdChange("UTiny.Core.Transform", "UTiny.Core2D.Transform");

            // System renames
            RegisterSystemIdChange("UTiny.HTML.HTMLService.InputHandler", "UTiny.HTML.InputHandler");
            RegisterSystemIdChange("UTiny.HTML.HTMLService.Renderer", "UTiny.HTML.Renderer");

            // ColorRGBA is migrated to Color
            Register(UTinyId.Generate("UTiny.Core.ColorRGBA"), new ColorRGBAUpdater());
        }
            public Reference(UTinyType type, int value)
            {
                Assert.IsNotNull(type);
                Assert.IsTrue(type.IsEnum);

                var defaultValue = type.DefaultValue as UTinyObject;

                UTinyField field;

                if (null != defaultValue)
                {
                    var name      = string.Empty;
                    var container = (IPropertyContainer)defaultValue.Properties;
                    foreach (var property in defaultValue.Properties.PropertyBag.Properties)
                    {
                        var propertyValue = property.GetObjectValue(container);
                        if (!value.Equals(propertyValue))
                        {
                            continue;
                        }
                        name = property.Name;
                        break;
                    }
                    field = type.FindFieldByName(name);
                }
                else
                {
                    field = type.Fields.FirstOrDefault();
                }

                m_Type  = (UTinyType.Reference)type;
                m_Id    = field?.Id ?? UTinyId.Empty;
                m_Name  = field?.Name ?? string.Empty;
                m_Value = null != field ? (int?)defaultValue?[m_Name] ?? 0 : 0;
            }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
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);
        }
        public IRegistryObject FindById(UTinyId id)
        {
            IRegistryObject t;

            m_Objects.TryGetValue(id, out t);
            return(t);
        }
        public static void RegisterSystemIdChange(string srcSystemFullName, string dstSystemFullName)
        {
            var name = dstSystemFullName.Substring(dstSystemFullName.LastIndexOf(".", StringComparison.Ordinal) + 1);
            var type = new UTinySystem.Reference(UTinyId.Generate(dstSystemFullName), name);

            Register(UTinyId.Generate(srcSystemFullName), new SystemIdChange(type));
        }
        public bool TryFindById <T>(UTinyId id, out T t) where T : class, IRegistryObject
        {
            IRegistryObject o;

            m_Objects.TryGetValue(id, out o);
            t = o as T;
            return(true);
        }
        public static object UpdateField(UTinyId id, object value)
        {
            if (!s_FieldUpdaters.ContainsKey(id))
            {
                return(value);
            }

            return(s_FieldUpdaters[id].UpdateValue(value));
        }
        private void CreateCodeBlock()
        {
            var module = m_MainModule.Dereference(m_Registry);
            var script = m_Registry.CreateScript(UTinyId.New(), UTinyUtility.GetUniqueName(module.EnumerateDependencies().ScriptRefs(), "NewScript"));

            module.AddScriptReference((UTinyScript.Reference)script);
            m_TreeView.Reload();
            m_TreeView.SetSelection(script.Id);
            script.TextAsset = CreateTextAsset(script.Name);
        }
        private void CreateSystem()
        {
            var module = m_MainModule.Dereference(m_Registry);
            var system = m_Registry.CreateSystem(UTinyId.New(), UTinyUtility.GetUniqueName(module.EnumerateDependencies().SystemRefs(), "NewSystem"));

            module.AddSystemReference((UTinySystem.Reference)system);
            m_TreeView.Reload();
            m_TreeView.SetSelection(system.Id);
            system.TextAsset = CreateTextAsset(system.Name);
        }
        private void CreateSystemExternal()
        {
            var module = m_MainModule.Dereference(m_Registry);
            var system = m_Registry.CreateSystem(UTinyId.New(), UTinyUtility.GetUniqueName(module.EnumerateDependencies().SystemRefs(), "NewSystem"));

            system.IncludeIterator = false;
            system.External        = true;
            module.AddSystemReference((UTinySystem.Reference)system);
            m_TreeView.Reload();
            m_TreeView.SetSelection(system.Id);
        }
        private void CreateEntityGroup()
        {
            var module      = m_MainModule.Dereference(m_Registry);
            var entityGroup = m_Registry.CreateEntityGroup(UTinyId.New(), UTinyUtility.GetUniqueName(module.EntityGroups, "NewEntityGroup"));

            module.AddEntityGroupReference((UTinyEntityGroup.Reference)entityGroup);
            m_TreeView.Reload();
            m_TreeView.SetSelection(new List <int> {
                m_TreeView.State.GetInstanceId(entityGroup.Id)
            }, TreeViewSelectionOptions.RevealAndFrame);
        }
예제 #17
0
        public static UTinyEntityGroup Generate(IRegistry registry, UTinyProject project)
        {
            var entityGroup = registry.CreateEntityGroup(UTinyId.New(), "Assets_Generated");
            var assets      = AssetIterator.EnumerateAssets(project.Module.Dereference(project.Registry));

            foreach (var asset in assets)
            {
                CreateEntityForAsset(registry, project, entityGroup, asset);
            }

            return(entityGroup);
        }
예제 #18
0
        /// <summary>
        /// Sets up or migrates the initial state of the project
        /// * Includes required modules
        /// * Perfrorms any migration
        /// </summary>
        /// <param name="registry"></param>
        /// <param name="project"></param>
        private static void SetupProject(IRegistry registry, UTinyProject project)
        {
            var module = project.Module.Dereference(registry);

            // Make sure there's a dependency on the core modules
            AddRequiredModuleDependencies(registry, module);

            if (project.Configuration.Equals(UTinyEntity.Reference.None))
            {
                var configurationEntity = registry.CreateEntity(UTinyId.New(), "Configuration");
                project.Configuration = (UTinyEntity.Reference)configurationEntity;
            }
        }
            public Reference(UTinyType type, UTinyId fieldId)
            {
                Assert.IsNotNull(type);
                Assert.IsTrue(type.IsEnum);

                var defaultValue = type.DefaultValue as UTinyObject;
                var field        = type.FindFieldById(fieldId);

                m_Type  = (UTinyType.Reference)type;
                m_Id    = field?.Id ?? UTinyId.Empty;
                m_Name  = field?.Name ?? string.Empty;
                m_Value = null != field ? (int?)defaultValue?[m_Name] ?? 0 : 0;
            }
예제 #20
0
        private void CreateSystem()
        {
            var module = m_MainModule.Dereference(m_Registry);
            var system = m_Registry.CreateSystem(UTinyId.New(), UTinyUtility.GetUniqueName(module.EnumerateDependencies().SystemRefs(), "NewSystem"));

            system.AddExecuteAfterReference((UTinySystem.Reference)module.Registry.FindByName <UTinySystem>("UserCodeStart"));
            system.AddExecuteBeforeReference((UTinySystem.Reference)module.Registry.FindByName <UTinySystem>("UserCodeEnd"));
            system.TextAsset = CreateTextAsset(system.Name);
            module.AddSystemReference((UTinySystem.Reference)system);

            m_TreeView.Reload();
            m_TreeView.SetSelection(system.Id);
        }
        public UTinyEntity CreateEntity(UTinyId id, string name)
        {
            var entity = new UTinyEntity(this, m_VersionStorage)
            {
                Id   = id,
                Name = name
            };

            m_VersionStorage.MarkAsChanged(entity);

            Register(entity);

            return(entity);
        }
        public int GetInstanceId(UTinyId id)
        {
            int instanceId;

            if (m_InstanceIds.TryGetValue(id, out instanceId))
            {
                return(instanceId);
            }

            instanceId = m_NextInstanceId++;
            m_InstanceIds.Add(id, instanceId);

            return(instanceId);
        }
        public UTinyProject CreateProject(UTinyId id, string name)
        {
            var project = new UTinyProject(this, m_VersionStorage)
            {
                Id   = id,
                Name = name,
            };

            m_VersionStorage.MarkAsChanged(project);

            Register(project);

            return(project);
        }
        public UTinyModule CreateModule(UTinyId id, string name)
        {
            var module = new UTinyModule(this, m_VersionStorage)
            {
                Id   = id,
                Name = name,
            };

            m_VersionStorage.MarkAsChanged(module);

            Register(module);

            return(module);
        }
        public UTinyScript CreateScript(UTinyId id, string name)
        {
            var script = new UTinyScript(this, m_VersionStorage)
            {
                Id   = id,
                Name = name
            };

            m_VersionStorage.MarkAsChanged(script);

            Register(script);

            return(script);
        }
        public UTinyType CreateType(UTinyId id, string name, UTinyTypeCode typeCode)
        {
            var type = new UTinyType(this, m_VersionStorage)
            {
                Id       = id,
                Name     = name,
                TypeCode = typeCode
            };

            m_VersionStorage.MarkAsChanged(type);

            Register(type);

            return(type);
        }
        public UTinySystem CreateSystem(UTinyId id, string name)
        {
            var system = new UTinySystem(this, m_VersionStorage)
            {
                Id      = id,
                Name    = name,
                Options = UTinySystemOptions.All
            };

            m_VersionStorage.MarkAsChanged(system);

            Register(system);

            return(system);
        }
        /// <summary>
        /// Sets up or migrates the initial state of the project
        /// * Includes required modules
        /// * Perfrorms any migration
        /// </summary>
        /// <param name="registry"></param>
        /// <param name="project"></param>
        private static void SetupProject(IRegistry registry, UTinyProject project)
        {
            var module = project.Module.Dereference(registry);

            // Make sure there's a dependency on the core modules
            module.AddExplicitModuleDependency((UTinyModule.Reference)registry.FindByName <UTinyModule>("UTiny.Core"));
            module.AddExplicitModuleDependency((UTinyModule.Reference)registry.FindByName <UTinyModule>("UTiny.Math"));
            module.AddExplicitModuleDependency((UTinyModule.Reference)registry.FindByName <UTinyModule>("UTiny.Core2D"));

            if (project.Configuration.Equals(UTinyEntity.Reference.None))
            {
                var configurationEntity = registry.CreateEntity(UTinyId.New(), "Configuration");
                project.Configuration = (UTinyEntity.Reference)configurationEntity;
            }
        }
예제 #29
0
        private void CreateStruct()
        {
            var module = m_MainModule.Dereference(m_Registry);
            var type   = m_Registry.CreateType(
                UTinyId.New(),
                UTinyUtility.GetUniqueName(module.Structs, "NewStruct"),
                UTinyTypeCode.Struct);

            module.AddStructReference((UTinyType.Reference)type);

            m_TreeView.Reload();
            m_TreeView.SetSelection(new List <int> {
                m_TreeView.State.GetInstanceId(type.Id)
            }, TreeViewSelectionOptions.RevealAndFrame |
                                    TreeViewSelectionOptions.FireSelectionChanged);
        }
예제 #30
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);
        }