Doraku / DefaultEcs.Analyzer

Roslyn analyzers for DefaultEcs users.
MIT No Attribution
13 stars 1 forks source link

[With<T>] and [Without<T>] attributes don't have any effect #15

Open awalltoo opened 2 months ago

awalltoo commented 2 months ago

Hello,

I'm attempting to use the [With<T>] attribute on a system to restrict it to operating on entities with a certain component, but it doesn't appear to be having any effect. In the following minimal example, I'd expect both System1 and System2 to operate on the same set of entities, with the only difference being that the former passes the value of the Bar component into the update function and the latter doesn't:

struct Foo { }

struct Bar { }

public partial class System1 : AEntitySetSystem<float>
{
    [Update] void Update(in Foo f, in Bar b) {}
}

[With<Bar>]
public partial class System2 : AEntitySetSystem<float>
{
    [Update]
    void Update(in Foo f) {}
}

However, when I look at the generated code for these, System1 correctly includes both Foo and Bar as required components in its query, whereas System2 seems to ignore the [With<Bar>] attribute and only require Foo.

System1

[CompilerGenerated]
private static EntitySet CreateEntityContainer(object sender, World world)
{
    var query = world
        .GetEntities()
        .With<global::Test.Foo>()
        .With<global::Test.Bar>();
    return query.AsSet();
}

System2

[CompilerGenerated]
private static EntitySet CreateEntityContainer(object sender, World world)
{
    var query = world
        .GetEntities()
        .With<global::Test.Foo>();
    return query.AsSet();
}

In addition, the [Without<T>] attribute also appears to have no effect. Given the following code:

[Without<Bar>]
public partial class System3 : AEntitySetSystem<float>
{
    [Update]
    void Update(in Foo f) {}
}

... the output is exactly the same as System2 above:

[CompilerGenerated]
private static EntitySet CreateEntityContainer(object sender, World world)
{
    var query = world
        .GetEntities()
        .With<global::Test.Foo>();
    return query.AsSet();
}

This also occurs if I use the version of these attributes that isn't templated (i.e. [With(typeof(Bar))]).

I read through what SystemGenerator.cs is doing and didn't see anything specifically related to parsing [With<T>] and [Without<T>] attributes. Is there another way I'm intended to use these, or is this an oversight?

Thank you!