andoowhy / EgoCS

EgoCS: An Entity (GameObject) Component System framework for Unity3D
MIT License
225 stars 31 forks source link

Does EgoCS support subtractive components? #14

Closed starikcetin closed 6 years ago

andoowhy commented 6 years ago

Due to (on purpose) limitations with C# Generics, EgoConstrants can't define subtractive / negative Components.

However, you can early-out in a ForEachGameObject callback with EgoComponent.HasComponents<>():

// ExampleSystem.cs
using UnityEngine;

public class ExampleSystem : EgoSystem<
    EgoConstraint<Transform, Example>
>{
    public override void Update()
    {
        constraint.ForEachGameObject( ( egoComponent, transform, example ) =>
        {
            if( egoComponent.HasComponents<SkipMe>() ) { return; }
            // ...
        } );
    }
}
starikcetin commented 6 years ago

I see. Thanks.