From 002ca5d086d84505332992cb368ce4983e564fb6 Mon Sep 17 00:00:00 2001 From: TheDudeFromCI Date: Mon, 8 Jun 2020 00:40:11 -0700 Subject: [PATCH] Updated readme. --- .../Documentation~/UnityInterfaceSupport.md | 2 +- README.md | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Packages/net.wraithavengames.unityinterfacesupport/Documentation~/UnityInterfaceSupport.md b/Packages/net.wraithavengames.unityinterfacesupport/Documentation~/UnityInterfaceSupport.md index 614eb9c..85fc3c2 100644 --- a/Packages/net.wraithavengames.unityinterfacesupport/Documentation~/UnityInterfaceSupport.md +++ b/Packages/net.wraithavengames.unityinterfacesupport/Documentation~/UnityInterfaceSupport.md @@ -14,7 +14,7 @@ When placing an interface field in the Unity inspector which you want to seriali Full Example: -``` +```cs // Here, we want to accept objects of the specific interface. // The field should always be specified as a UnityEngine.Object type. // We can now be promised that the object field will be correctly diff --git a/README.md b/README.md index 708d7f8..48d0ba2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

Unity Interface Support

-

A small Unity package which adds a simple attribute which allows for usage of interfaces on MonoBehaviours in the Unity inspector. Interfaces are fully serialized and blend seemlessly with standard Unity workflows.

+

A small Unity package which adds a simple attribute which allows for usage of interfaces on MonoBehaviours in the Unity inspector. Interfaces are fully serialized and blend seamlessly with standard Unity workflows.

@@ -41,6 +41,41 @@ This tiny Unity package allows for a user to quickly and easily add interface su In modern programming, proper dependency injection is essential for scaling up a project. Sadly, Unity's serializer does not currently allow for an easy implementation of interface-based components. This plugin adds a quick-and-simple approach to allowing an interface to be used within your MonoBehavior safe to assign from the editor without any fears of serialization getting in the way, or adding components of the wrong type. +### Usage + +Using interfaces is as simple as adding an attribute, and writing a single property field. + +Example: + +```cs +// Here, we want to accept objects of the specific interface. +// The field should always be specified as a UnityEngine.Object type. +// We can now be promised that the object field will be correctly +// serialized exactly as expected. The field will always be of +// the requested interface type, or null if not assigned. +[SerializeField, InterfaceType(typeof(IMyInterface))] +private Object myObject; + +// Optionally, adding a private property is recommended for +// automatically casting the object field to the interface. +private IMyInterface MyInterface => myObject as IMyInterface; + + +// ... + +// If using the property field, you can reference the property +// directly and us it as the interface. +void Start() +{ + if (MyInterface != null) + MyInterface.SayHi(); +} +``` + +### Additional Information + +You can find more information about using this Unity package by checking out the Documentation page. This page is also included in local installations within the UnityInterfaceSupport/Documentation~ folder in your Unity Packages directory. + ### Video Demo https://www.youtube.com/watch?v=2xYdQgXGhe0