Spy-Shifty / BrokenBricksECS

Rebuild of Unity3D upcoming Entity Component System !OUT OF DEVELOPMENT!
MIT License
162 stars 28 forks source link

Polymorphism of systems #29

Open enzi opened 6 years ago

enzi commented 6 years ago

Currently I have an EquipmentEngineBase : ComponentSystem and

When I add these 2 systems the ECS throws an error in ComponentGroup.cs, the type has already been added to the dictionary. A check if it already contains this type is sufficient and both systems work correctly. I just wonder if it has any negative side effects.

The full code:

    public ComponentGroup(EntityManager entityManager, params Type[] componentTypes) {
        _entityManager = entityManager;
        _groupMatcher = new GroupMatcher(componentTypes);

        foreach (Type type in componentTypes) {
            Type componentArrayType = typeof(ComponentArray<>);
            Type genericComponentArrayType = componentArrayType.MakeGenericType(type);

            if (!_components.ContainsKey(type)) // added
                _components.Add(type, (ComponentArray)Activator.CreateInstance(genericComponentArrayType));                
        }
    }
Spy-Shifty commented 6 years ago

How do you add your systems?

enzi commented 6 years ago

Nothing special with AddSystem<EquipmentEngine>(); AddSystem<UnEquipmentEngine>();

in public class MainCore : ECSController<UnityStandardSystemRoot, UnityEntityManager>