# Editor Utilities __
To install this package you can do one of this:
-
Using Package Manager Window
- Opening the Package Manager Window: Window > Package Manager
- Wait for it to load
- Click on the top left button
+
> Add package from git URL - Copy paste the repository link
- Press enter
-
Modifying manifest.json file Add the following to your
manifest.json
file (which is under your project location inPackages
folder)
{
"dependancies": {
...
"com.rikoo.editor-utilities": "https://github.com/ErikRikoo/com.rikoo.editor-utilities.git",
...
}
}
Sometimes Unity has some hard time updating git dependencies so when you want to update the package, follow this steps:
- Go into
package-lock.json
file (same place thatmanifest.json
one) - It should look like this:
{
"dependencies": {
...
"com.rikoo.editor-utilities": {
"version": "https://github.com/ErikRikoo/com.rikoo.editor-utilities.git",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "hash-number-there"
},
...
}
- Remove the "com.rikoo.editor-utilities" and save the file
- Get back to Unity
- Let him refresh
- Package should be updated
Abstract Reference
This attribute is really handy when you want to choose in the Editor which subclass you want. Thus, you can easily go abstract and respect solid principles right into Unity. Moreover, it works with arrays and with nested AbstractReferences I will show you how to use it with basic use case: you will have a base class and two subclasses. One will contain a float and the other a string.
// The base class
// The serializable attribute is really important
[System.Serializable]
public abstract class ABase {}
// First subclass
[System.Serializable]
public class Implementation1 : ABase
{
[SerializeField] private float foo;
}
// Second subclass
[System.Serializable]
public class Implementation2 : ABase
{
[SerializeField] private string foo;
}
There the MonoBehaviour to test it:
public class Test : UnityEngine.MonoBehaviour
{
[AbstractReference]
[SerializeReference] private ABase m_Object;
[AbstractReference]
[SerializeReference] private ABase[] m_Array;
}
On this one you can see, that:
- The type used is the base type and not one of the subclasses.
- We use the SerializeReference attribute, don't forget it.
- We use the custom attribute AbstractReference.
Here the result in the editor:
Feel free to suggest features by creating an issue, any idea is welcome !