Skip to content

Open-source unity editor extension that allows you to automatically select inherited implementations of a base class directly on the editor.

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

Guillemsc/ImplementationSelector

Repository files navigation

Welcome to Implementation Selector

License: MIT contributions welcome Twitter Follow Release

Welcome to Implementation Selector: a small Unity editor extension that allows you to automatically select an interface/base class's implementations directly on the editor. This is very useful for rapdily create configuration files for your applications.

Logo

Contents

Installing

- Via Github

Download the full repositories, and then place it under the Assets folder of your Unity project.

And that's all, with that you should be ready to go!

- Via UPM

Add the following line to your manifest.json.

"dependencies": {
   "com.juce.implementationselector": "git+https://github.com/Juce-Assets/Juce-ImplementationSelector",
},

Basic Usage

- SelectImplementationAttribute

You can turn an interface/base class to a selectable one using the attribute SelectImplementationAttribute. You also need to use the SerializeReference Unity attribute.

[SelectImplementation(typeof(IFood))]
[SerializeField, SerializeReference] private IFood food = default;

Logo

Logo

Logo

It works with lists too!

[SelectImplementation(typeof(IFood))]
[SerializeField, SerializeReference] private List<IFood> food = default;

Logo

SelectImplementation has two default values that can be changed:

  • DisplayLabel: determines if the variable name is shown on the inspector. It's enabled by default.
  • ForceExpanded: determines if the properties of the class can be collapsed with a dropdown, or ar shown all the time. It's disabled by default.
[SelectImplementation(typeof(IFood), displayLabel: true, forceExpanded: false)]
[SerializeField, SerializeReference] private IFood food = default;

The classes that inherit from the base one need to be marked as serializable with the System.Serializable attribute. They also need to have the default constructor, or a public parameterless one.

[System.Serializable]
public class AppleFood : IFood
{
    [SerializeField] private string appleName = default;
}

 

- SelectImplementationTrimDisplayName

You can use the attribute SelectImplementationTrimDisplayName, on the base interface/class, to define a string that will always be trimmed from the name displayed of the classes that implement this interface.

For example, if you have a base interface named IFood, and classes that inherit from it, like AppleFood, GrapesFood, PizzaFood, by using the SelectImplementationTrimDisplayName("Food"), the class names will be desplayed as Apple, Grapes, Pizza.

[SelectImplementationTrimDisplayName("Food")]
public interface IFood
{
   
}

 

- SelectImplementationDefaultType

You can use the attribute SelectImplementationDefaultType, on one of the classes that inherits from the base interface/class, to mark it as the default one that's going to appear on the editor the first time the user sees it.

[System.Serializable]
[SelectImplementationDefaultType]
public class AppleFood : IFood
{
    [SerializeField] private string appleName = default;
}

 

- SelectImplementationTooltip

You can use the attribute SelectImplementationTooltip, on one of the classes that inherits from the base interface/class, to show a tooltip when the user hovers this specific type with the mouse

[System.Serializable]
[SelectImplementationTooltip("Apple tooltip")]
public class AppleFood : IFood
{
    [SerializeField] private string appleName = default;
}

Logo

 

- SelectImplementationCustomDisplayName

You can use the attribute SelectImplementationCustomDisplayName, on one of the classes that inherits from the base interface/class, to show a specific name on the selection dropdown.

[System.Serializable]
[SelectImplementationCustomDisplayName("Custom Apple display")]
public class AppleFood : IFood
{
    [SerializeField] private string appleName = default;
}

Logo

We are always aiming to improve this tool. You can always leave suggestions here.

Want to contribute?

Please follow these steps to get your work merged in.

  1. Clone the repo and make a new branch: $ git checkout https://github.com/Juce-Assets/Juce-ImplementationSelector/tree/main -b [name_of_new_branch].

  2. Add a feature, fix a bug, or refactor some code :)

  3. Update README.md contributors, if necessary.

  4. Open a Pull Request with a comprehensive description of changes.

Contributors

About

Open-source unity editor extension that allows you to automatically select inherited implementations of a base class directly on the editor.

Topics

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages