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)); }
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); }
public void UpdateComponent <T>(int componentTypeId, T newValue) where T : struct, IComponent { var allocationId = InternalComponentAllocations[componentTypeId]; ComponentDatabase.Set(componentTypeId, allocationId, newValue); }