Ejemplo n.º 1
0
        public ref T AddComponent <T>(int componentTypeId) where T : IComponent, new()
        {
            var defaultComponent = ComponentTypeLookup.CreateDefault <T>();
            var allocationId     = ComponentDatabase.Allocate(componentTypeId);

            InternalComponentAllocations[componentTypeId] = allocationId;
            ComponentDatabase.Set(componentTypeId, allocationId, defaultComponent);

            _onComponentsAdded.OnNext(new [] { componentTypeId });

            return(ref ComponentDatabase.GetRef <T>(componentTypeId, allocationId));
        }
Ejemplo n.º 2
0
        public void should_correctly_allocate_instance_when_adding()
        {
            var mockComponentLookup = Substitute.For <IComponentTypeLookup>();

            mockComponentLookup.GetAllComponentTypes().Returns(new Dictionary <Type, int>
            {
                { typeof(TestComponentOne), 0 }
            });
            var database   = new ComponentDatabase(mockComponentLookup);
            var allocation = database.Allocate(0);

            Assert.Equal(0, allocation);
        }
Ejemplo n.º 3
0
        public void AddComponents(IReadOnlyList <IComponent> components)
        {
            var componentTypeIds = new int[components.Count];

            for (var i = 0; i < components.Count; i++)
            {
                var componentTypeId = ComponentTypeLookup.GetComponentType(components[i].GetType());
                var allocationId    = ComponentDatabase.Allocate(componentTypeId);
                InternalComponentAllocations[componentTypeId] = allocationId;
                ComponentDatabase.Set(componentTypeId, allocationId, components[i]);
            }

            _onComponentsAdded.OnNext(componentTypeIds);
        }