All Projects → TheDudeFromCI → Unity-Interface-Support

TheDudeFromCI / Unity-Interface-Support

Licence: MIT license
A simple implementation which allows for interface-type fields to be accepted in the Unity inspector.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Unity-Interface-Support

Unity-SerializeReferenceExtensions
Provide popup to specify the type of the field serialized by the [SerializeReference] attribute in the inspector.
Stars: ✭ 255 (+466.67%)
Mutual labels:  serialization, interface
parco
🏇🏻 generalist, fast and tiny binary parser and compiler generator, powered by Go 1.18+ Generics
Stars: ✭ 57 (+26.67%)
Mutual labels:  serialization
borsh-rs
Rust implementation of Binary Object Representation Serializer for Hashing
Stars: ✭ 149 (+231.11%)
Mutual labels:  serialization
ElvUI
ElvUI for World of Warcraft - Vanilla (1.12.1)
Stars: ✭ 67 (+48.89%)
Mutual labels:  interface
c-plus-plus-serializer
A minimal C++11 header only serializer. Can serialize basic types, strings, containers, maps and custom classes. No suppprt yet for pointer types.
Stars: ✭ 36 (-20%)
Mutual labels:  serialization
GenericProtocol
⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐
Stars: ✭ 38 (-15.56%)
Mutual labels:  serialization
crab
JavaScript library for building user interfaces with Custom Elements, Shadow DOM and React like API
Stars: ✭ 22 (-51.11%)
Mutual labels:  interface
moko-network
Network components with codegeneration of rest api for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 107 (+137.78%)
Mutual labels:  serialization
Java-Programs
Java Practiced Problems including concepts of OOPS, Interface, String , Collection.
Stars: ✭ 51 (+13.33%)
Mutual labels:  interface
Cemu-UI
A user interface for the Wii U emulator, Cemu
Stars: ✭ 21 (-53.33%)
Mutual labels:  interface
cattrs
Complex custom class converters for attrs.
Stars: ✭ 565 (+1155.56%)
Mutual labels:  serialization
mainsail
Mainsail is the popular web interface for Klipper
Stars: ✭ 960 (+2033.33%)
Mutual labels:  interface
avrow
Avrow is a pure Rust implementation of the avro specification https://avro.apache.org/docs/current/spec.html with Serde support.
Stars: ✭ 27 (-40%)
Mutual labels:  serialization
fdat.cljc
Function serialization between Clojure processes and dialects
Stars: ✭ 49 (+8.89%)
Mutual labels:  serialization
moonblob
Binary serialization for moonscript + LuaJIT
Stars: ✭ 22 (-51.11%)
Mutual labels:  serialization
ngx-localstorage
An Angular wrapper for localstorage/sessionstorage access.
Stars: ✭ 27 (-40%)
Mutual labels:  serialization
GCPEditorPro
Amazingly fast and simple ground control points interface. ◎
Stars: ✭ 33 (-26.67%)
Mutual labels:  interface
NBT
A java implementation of the NBT protocol, including a way to implement custom tags.
Stars: ✭ 128 (+184.44%)
Mutual labels:  serialization
coqpit
Simple but maybe too simple config management through python data classes. We use it for machine learning.
Stars: ✭ 67 (+48.89%)
Mutual labels:  serialization
node-qemu-server
Free GUI / Frontend / Management tool for simple setup, configure and control virtual machines (qemu / kvm) within your HTML5 Webbrowser. Virtualization with Node.js / Currently under complete rewrite.
Stars: ✭ 41 (-8.89%)
Mutual labels:  interface

Unity Interface Support

Unity Interface Support is a small Unity package that adds an attribute for allowing interfaces to be used on MonoBehaviours in the Unity inspector. Interfaces are fully serialized and blend seamlessly with standard Unity workflows.


Summary

This tiny Unity package allows for a user to quickly and easily add interface support to the Unity inspector.

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:

// 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();
}

Arrays & Lists

Using collections is nearly identical, but each element in the array must be casted individually. The simplest way to do this is via System.Linq.

public IMyInterface[] MyInterfaceArray => myObjects.OfType<IMyInterface>().ToArray();
public IMyInterface[] MyInterfaceList => myObjects.OfType<IMyInterface>().ToList();

// For performance reasons, it's recommended that you cache your collection wherever possible,
// as you may not want this being calculated every time you reference this property.
IMyInterface[] _myInterfaceArray;

void Awake()
{
    _myInterfaceArray = MyInterfaceArray;
}

If you would like to avoid using Linq, you can make a quick getter and setter function.

[SerializeField, InterfaceType(typeof(IMyInterface))]
private Object[] myObjects;

public IMyInterface MyInterface(int index) => myObjects[index] as IMyInterface;
public IMyInterface MyInterface(int index, IMyInterface value) => myObjects[index] = value;

Namespace

The InterfaceType attribute exists under the WraithavenGames.UnityInterfaceSupport namespace.

If you're using an assembly definition, in same rare cares, the GUID of the assemblies may not load correctly when importing the package. This can be fixed by opening the UnityInterfaceSupport.Editor assembly definition file in the package directly and pointing the the GUID link back to the UnityInterfaceSupport runtime. This can be seen here.

Installation

You can install this package by using the following line in the Unity package manager:

"net.wraithavengames.unityinterfacesupport": "https://github.com/TheDudeFromCI/Unity-Interface-Support.git?path=/Packages/net.wraithavengames.unityinterfacesupport",

(Please see the Official Unity Documention for more information.)

This project can also be installed through OpenUPM, here.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].