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

[FEATURE] Add abstract generic support #83

Open
Nitero opened this issue Dec 18, 2024 · 0 comments
Open

[FEATURE] Add abstract generic support #83

Nitero opened this issue Dec 18, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Nitero
Copy link

Nitero commented Dec 18, 2024

Feature description

First of all thanks for the great package, it works like a charm!

So I'm not sure if this is possible, but it would be nice if we could use SubclassSelector on abstract classes with a generic type. This way we could add an interface to the abstract class that does not have a generic type. Then we could use this to specify config values in a dictionary without a type.

My workaround for this is to use a generic interface and have a second plain interface just for selecting targets easily in configs.

public class Example : MonoBehaviour
{
    [SerializeReference, SubclassSelector]
    private Target<Character> _target;// does NOT show ConcreteTarget

    [SerializeReference, SubclassSelector]
    private ITarget<Character> _target2;// DOES show ConcreteTarget

    // [SerializeReference, SubclassSelector]
    // private SerializedDictionary<ITarget, float> _configs;// not possible as the interface needs a generic type
    
    [SerializeReference, SubclassSelector]
    private SerializedDictionary<ITargetConfigurable, float> _configs2;// possible workaround
}


// ideally we could add the generic type in the abstract class instead
public interface ITarget<T>
{
    T GetTargets();
}

// using an extra interface instead of ITarget allows us to select a target without type eg. in a config
public interface ITargetConfigurable { }

public abstract class Target<T> : ITarget<T>, ITargetConfigurable
{
    public abstract T GetTargets();
}

[Serializable]
public class ConcreteTarget : Target<Character>
{
    public override Character GetTargets() => null;
}

public class Character { }
@Nitero Nitero added the enhancement New feature or request label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants