Skip to content

Commit

Permalink
Updated readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDudeFromCI committed Jun 8, 2020
1 parent fd0127c commit 002ca5d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align="center">Unity Interface Support</h1>
<p align="center"><i>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.</i></p>
<p align="center"><i>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.</i></p>

<p align="center">
<img src="https://img.shields.io/github/license/Wraithaven-UnityTools/Unity-Interface-Support" />
Expand Down Expand Up @@ -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

0 comments on commit 002ca5d

Please sign in to comment.