Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i need to declare many signals. is there a solution for that? #275

Open
virtouso opened this issue Nov 7, 2022 · 1 comment
Open

i need to declare many signals. is there a solution for that? #275

virtouso opened this issue Nov 7, 2022 · 1 comment

Comments

@virtouso
Copy link

virtouso commented Nov 7, 2022

there are many classes that i finish the name with "Signal" and i define them with DeclareSignal.

I think there can be a solution that declares many signal classes automatically like using reflection and attributes.

@artisan-jack
Copy link

artisan-jack commented May 23, 2023

    public override void InstallBindings()
    {
        SignalBusInstaller.Install(Container);
        
        InstallBindingsOfType<GameSignalBase>(false);
        InstallBindingsOfType<OptionalGameSignalBase>(true);
    }

    private void InstallBindingsOfType<T>(bool bOptional)
    {
        var signalTypeEnumerator = Assembly.GetAssembly(GetType()).GetTypes()
            .Where(t => t.IsClass && !t.IsAbstract && typeof(T).IsAssignableFrom(t));

        var typeEnumerator = signalTypeEnumerator.ToList();
        if (typeEnumerator.Any())
        {
            foreach (var type in typeEnumerator)
            {
                if (bOptional)
                {
                    Container.DeclareSignal(type).OptionalSubscriber();
                }
                else
                {
                    Container.DeclareSignal(type);
                }
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants