Пример #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));
        }
Пример #2
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);
        }
Пример #3
0
        public void UpdateComponent <T>(int componentTypeId, T newValue) where T : struct, IComponent
        {
            var allocationId = InternalComponentAllocations[componentTypeId];

            ComponentDatabase.Set(componentTypeId, allocationId, newValue);
        }