protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component) { OnAddBinding(entity, component); var graphNode = GetComponent <CellGraphNode>(entity); var cell = component["cell"] as UTinyObject; if (null == cell) { return; } cell["x"] = (int)graphNode.Cell.x; cell["y"] = (int)graphNode.Cell.y; }
protected override void OnUpdateBinding(UTinyEntity entity, UTinyObject component) { OnAddBinding(entity, component); var graph = GetComponent <CellGraph>(entity); var layout = component["layout"] as UTinyObject; var size = layout?["size"] as UTinyObject; if (size != null) { graph.Layout = new CellLayout { CellSize = new Vector2((float)size["x"], (float)size["y"]) }; } graph.Width = (int)component["width"]; graph.Height = (int)component["height"]; }
public void SetUp() { m_Registry = new UTinyRegistry(); m_EnumType = m_Registry.CreateType( UTinyId.New(), "TestEnum", UTinyTypeCode.Enum); m_EnumType.BaseType = (UTinyType.Reference)UTinyType.Int32; m_EnumType.CreateField("A", (UTinyType.Reference)UTinyType.Int32); m_EnumType.CreateField("B", (UTinyType.Reference)UTinyType.Int32); m_EnumType.CreateField("C", (UTinyType.Reference)UTinyType.Int32); m_EnumType.DefaultValue = new UTinyObject(m_Registry, (UTinyType.Reference)m_EnumType) { // @NOTE We are intentionally starting at 1 to detect 0 case as errors ["A"] = 1, ["B"] = 2, ["C"] = 3 }; // Create a component with a single int field m_ComponentType = m_Registry.CreateType( UTinyId.New(), "TestComponent", UTinyTypeCode.Component); m_ComponentType.CreateField( "TestEnumField", (UTinyType.Reference)m_EnumType); m_Entity = m_Registry.CreateEntity(UTinyId.New(), "TestEntity"); var component = m_Entity.AddComponent((UTinyType.Reference)m_ComponentType); component.Refresh(); }
public void SetUp() { m_Registry = new UTinyRegistry(); // Create a component with a single int field m_ComponentType = m_Registry.CreateType( UTinyId.New(), "TestComponent", UTinyTypeCode.Component); m_ComponentType.CreateField( "TestIntField", (UTinyType.Reference)UTinyType.Int32); // Default the TestStruct.IntField to 7 m_ComponentType.DefaultValue = new UTinyObject(m_Registry, (UTinyType.Reference)m_ComponentType) { ["TestIntField"] = KTestFieldDefaultValue }; // Create an entity with our test component m_DefaultEntity = m_Registry.CreateEntity(UTinyId.New(), "DefaultEntity"); { var c = m_DefaultEntity.AddComponent((UTinyType.Reference)m_ComponentType); c.Refresh(); } // Create another entity with our test component m_OverridenEntity = m_Registry.CreateEntity(UTinyId.New(), "OverridenEntity"); { var c = m_OverridenEntity.AddComponent((UTinyType.Reference)m_ComponentType); c.Refresh(); c["TestIntField"] = KTestFieldOverrideValue; } }
public void SetUp() { m_Registry = new UTinyRegistry(); // Create a component with a single Texture2D field m_ComponentType = m_Registry.CreateType( UTinyId.New(), "TestComponent", UTinyTypeCode.Component); m_ComponentType.CreateField( "TestTexture2DField", (UTinyType.Reference)UTinyType.Texture2DEntity); m_Entity = m_Registry.CreateEntity(UTinyId.New(), "TestEntity"); var component = m_Entity.AddComponent((UTinyType.Reference)m_ComponentType); component.Refresh(); // Create some asset on disc File.WriteAllBytes(Application.dataPath + "/TestTexture.png", new Texture2D(32, 32).EncodeToPNG()); AssetDatabase.ImportAsset("Assets/TestTexture.png"); m_Texture2D = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/TestTexture.png"); }
public void PerformanceTest() { var vector3Type = registry.CreateType( UTinyId.New(), "Vector3", UTinyTypeCode.Struct); vector3Type.CreateField("X", (UTinyType.Reference)UTinyType.Float32); vector3Type.CreateField("Y", (UTinyType.Reference)UTinyType.Float32); vector3Type.CreateField("Z", (UTinyType.Reference)UTinyType.Float32); var transformType = registry.CreateType( UTinyId.New(), "Transform", UTinyTypeCode.Component); transformType.CreateField("Position", (UTinyType.Reference)vector3Type); transformType.CreateField("Scale", (UTinyType.Reference)vector3Type); const int kCount = 1000; var entities = new UTinyEntity[kCount]; var transformTypeReference = (UTinyType.Reference)transformType; { var watch = System.Diagnostics.Stopwatch.StartNew(); for (var i = 0; i < kCount; i++) { entities[i] = registry.CreateEntity(UTinyId.New(), "Entity_" + i); var transform = entities[i].AddComponent(transformTypeReference); // if (i < kCount) { transform.Refresh(null, true); var position = transform["Position"] as UTinyObject; position["X"] = i * 2f; } } watch.Stop(); Debug.Log($"Create Entities=[{kCount}] {watch.ElapsedMilliseconds}ms"); } caretaker.OnObjectChanged += (originiator, memento) => { // Force the callback }; { var watch = System.Diagnostics.Stopwatch.StartNew(); caretaker.Update(); watch.Stop(); Debug.Log($"Caretaker.Update Entities=[{kCount}] {watch.ElapsedMilliseconds}ms"); } { var watch = System.Diagnostics.Stopwatch.StartNew(); caretaker.Update(); watch.Stop(); Debug.Log($"Caretaker.Update Entities=[{kCount}] {watch.ElapsedMilliseconds}ms"); } }
public void BinaryEntityPerformance() { var registry = new UTinyRegistry(); var vector3Type = registry.CreateType( UTinyId.New(), "Vector3", UTinyTypeCode.Struct); vector3Type.CreateField("X", (UTinyType.Reference)UTinyType.Float32); vector3Type.CreateField("Y", (UTinyType.Reference)UTinyType.Float32); vector3Type.CreateField("Z", (UTinyType.Reference)UTinyType.Float32); var transformType = registry.CreateType( UTinyId.New(), "Transform", UTinyTypeCode.Component); transformType.CreateField("Position", (UTinyType.Reference)vector3Type); transformType.CreateField("Scale", (UTinyType.Reference)vector3Type); const int kCount = 1000; var entities = new UTinyEntity[kCount]; var transformTypeReference = (UTinyType.Reference)transformType; { var watch = System.Diagnostics.Stopwatch.StartNew(); for (var i = 0; i < kCount; i++) { entities[i] = registry.CreateEntity(UTinyId.New(), "Entity_" + i); var transform = entities[i].AddComponent(transformTypeReference); // if (i < kCount) { transform.Refresh(null, true); var position = transform["Position"] as UTinyObject; position["X"] = i * 2f; } } watch.Stop(); Debug.Log($"Create Objects Entities=[{kCount}] {watch.ElapsedMilliseconds}ms"); } using (var binary = new MemoryStream()) using (var command = new MemoryStream()) { // Write the data model to a stream as json // mem -> command { var watch = System.Diagnostics.Stopwatch.StartNew(); Serialization.Binary.BackEnd.Persist(binary, (IEnumerable <UTinyEntity>)entities); watch.Stop(); Debug.Log($"Binary.BackEnd.Persist Entities=[{kCount}] {watch.ElapsedMilliseconds}ms Len=[{binary.Position}]"); } binary.Position = 0; // Push the types to the command stream before the entities Serialization.CommandStream.BackEnd.Persist(command, vector3Type, transformType); { var watch = System.Diagnostics.Stopwatch.StartNew(); Serialization.Binary.FrontEnd.Accept(binary, command); watch.Stop(); Debug.Log($"Binary.FrontEnd.Accept Entities=[{kCount}] {watch.ElapsedMilliseconds}ms Len=[{command.Position}]"); } command.Position = 0; // Create a registry to hold accepted objects var output = new UTinyRegistry(); // Process the command // commands -> mem { var watch = System.Diagnostics.Stopwatch.StartNew(); Serialization.CommandStream.FrontEnd.Accept(command, output); watch.Stop(); Debug.Log($"CommandStream.FrontEnd.Accept Entities=[{kCount}] {watch.ElapsedMilliseconds}ms"); } } }
public void SetUp() { m_Registry = new UTinyRegistry(); // Create a component with an int array field m_IntArrayComponentType = m_Registry.CreateType( UTinyId.New(), "TestComponent", UTinyTypeCode.Component); m_IntArrayComponentType.CreateField( "TestIntArrayField", (UTinyType.Reference)UTinyType.Int32, true); m_IntArrayEntity = m_Registry.CreateEntity(UTinyId.New(), "TestEntity"); var component = m_IntArrayEntity.AddComponent((UTinyType.Reference)m_IntArrayComponentType); component.Refresh(); component["TestIntArrayField"] = new UTinyList(m_Registry, (UTinyType.Reference)UTinyType.Int32) { 3, 6, 9 }; m_StructType = m_Registry.CreateType( UTinyId.New(), "TestStruct", UTinyTypeCode.Struct); m_StructType.CreateField( "TestIntField", (UTinyType.Reference)UTinyType.Int32); m_StructArrayComponentType = m_Registry.CreateType( UTinyId.New(), "TestComponent2", UTinyTypeCode.Component); m_StructArrayComponentType.CreateField( "TestStructArrayField", (UTinyType.Reference)m_StructType, true); m_StructArrayEntity = m_Registry.CreateEntity(UTinyId.New(), "TestEntity2"); var component2 = m_StructArrayEntity.AddComponent((UTinyType.Reference)m_StructArrayComponentType); component2.Refresh(); component2["TestStructArrayField"] = new UTinyList(m_Registry, (UTinyType.Reference)m_StructType) { new UTinyObject(m_Registry, (UTinyType.Reference)m_StructType) { ["TestIntField"] = 3 }, new UTinyObject(m_Registry, (UTinyType.Reference)m_StructType) { ["TestIntField"] = 6 }, new UTinyObject(m_Registry, (UTinyType.Reference)m_StructType) { ["TestIntField"] = 9 } }; }
protected override void OnRemoveBinding(UTinyEntity entity, UTinyObject component) { RemoveComponent <CellGraphNode>(entity); }
protected override void OnAddBinding(UTinyEntity entity, UTinyObject component) { AddMissingComponent <CellGraphNode>(entity); }