Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork20
A wrapper that allows you to serialize interfaces
License
Thundernerd/Unity3D-SerializableInterface
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A wrapper that allows you to serialize interfaces. Both UnityEngine.Object and regular object implementers work!
- The package is available on theopenupm registry. You can install it viaopenupm-cli.
openupm add net.tnrd.serializableinterface
- Installing through aUnity Package created by thePackage Installer Creator fromNeedle
Usage is pretty easy and straightforward. Assuming you have the following interface
publicinterfaceIMyInterface{voidGreet();}
You can add it to a behaviour like so
usingTNRD;usingUnityEngine;publicclassMyBehaviour:MonoBehaviour{[SerializeField]privateSerializableInterface<IMyInterface>mySerializableInterface;privatevoidAwake(){mySerializableInterface.Value.Greet();}}
Back in the Unity inspector it will look like this
And when you click on the object selector button you will be shown a dropdown window with all possible options like this
As you can see you can select items from multiple locations:
- Assets (Scriptable Objects and Prefabs that implement said interface)
- Classes (custom classes that implement said interface)
- Scene (objects in the scene that implement said interface)
For the sake of example for the image above I have created some simple implementations
usingUnityEngine;publicclassMyComponent:MonoBehaviour,IMyInterface{/// <inheritdoc />publicvoidGreet(){Debug.Log("Hello, World! I'm MyComponent");}}
usingUnityEngine;publicclassMyPoco:IMyInterface{/// <inheritdoc />publicvoidGreet(){Debug.Log("Hello, World! I'm MyPoco");}}
usingUnityEngine;[CreateAssetMenu(menuName="MyScriptable")]publicclassMyScriptable:ScriptableObject,IMyInterface{/// <inheritdoc />publicvoidGreet(){Debug.Log("Hello, World! I'm MyScriptable");}}
Serializable Interface is a small and open-source utility that I hope helps other people. It is by no means necessary but if you feel generous you can support me by donating.
Pull requests are welcomed. Please feel free to fix any issues you find, or add new features.
About
A wrapper that allows you to serialize interfaces
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.