Welcome to Implementation Selector
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.
Installing
- Via Github
Contents
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#1.0.2",
},
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;
It works with lists too!
[SelectImplementation(typeof(IFood))]
[SerializeField, SerializeReference] private List<IFood> food = default;
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;
}
- 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;
}
We are always aiming to improve this tool. You can always leave suggestions on the Issues.
Want to contribute?
Please follow these steps to get your work merged in.
-
Clone the repo and make a new branch:
$ git checkout https://github.com/Juce-Assets/Juce-ImplementationSelector/tree/main -b [name_of_new_branch]
. -
Add a feature, fix a bug, or refactor some code :)
-
Update
README.md
contributors, if necessary. -
Open a Pull Request with a comprehensive description of changes.
Contributors
- Guillem SC - @Guillemsc