Usage
Example
Section titled “Example”Given the interface:
public interface IPlayerCueInputProvider{ void DoSomething();}You can implement on any UnityEngine.Object type:
public class InputProvider : MonoBehaviour, IPlayerCueInputProvider{ void DoSomething();}or
public class ScriptableInputProvider : ScriptableObject, IPlayerCueInputProvider{ void DoSomething();}Then serialize private interfaces on any other type:
[SerializeField] IPlayerCueInputProvider _inputProvider;The field can then be used normally:
_inputProvider.DoSomething();Supported references
Section titled “Supported references”Direct interface fields support:
- Scene
MonoBehaviourinstances. ScriptableObjectassets.- Any
UnityEngine.Objectthat implements the target interface. GameObjectreferences — the drawer automatically finds a matching component.
Inspector behavior
Section titled “Inspector behavior”The Custom Property Drawer will:
- Display the resolved object type.
- Warn when the assigned object does not implement or inherit from the required type.
Drag and drop any MonoBehaviour or ScriptableObject instance onto the field to set the value.
If you drag a
GameObject, it will try to find a component on the GameObject that implements the interface
UnityObjectReference<T>
Section titled “UnityObjectReference<T>”UnityObjectReference<T> is also available when you want an explicit serializable wrapper around the reference:
[SerializeField] UnityObjectReference<IPlayerCueInputProvider> _inputProvider;Access the referenced object through .Value, or use the implicit conversion:
_inputProvider.Value.DoSomething();
IPlayerCueInputProvider input = _inputProvider;For most use cases, however, the direct interface syntax is the recommended approach:
[SerializeField] IPlayerCueInputProvider _inputProvider;