• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 2 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A wrapper that allows you to serialize interfaces

Serializable Interface

GitHub package.json version GitHub issues GitHub pull requests GitHub license GitHub last commit

A wrapper that allows you to serialize interfaces. Both UnityEngine.Object and regular object implementers work!

Installation

  1. The package is available on the openupm registry. You can install it via openupm-cli.
openupm add net.tnrd.serializableinterface
  1. Installing through a Unity Package created by the Package Installer Creator from Needle

Usage

Usage is pretty easy and straightforward. Assuming you have the following interface

public interface IMyInterface
{
    void Greet();
}

You can add it to a behaviour like so

using TNRD;
using UnityEngine;

public class MyBehaviour : MonoBehaviour
{
    [SerializeField] private SerializableInterface<IMyInterface> mySerializableInterface;

    private void Awake()
    {
        mySerializableInterface.Value.Greet();
    }
}

Back in the Unity inspector it will look like this

image

And when you click on the object selector button you will be shown a dropdown window with all possible options like this

image

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

using UnityEngine;

public class MyComponent : MonoBehaviour, IMyInterface
{
    /// <inheritdoc />
    public void Greet()
    {
        Debug.Log("Hello, World! I'm MyComponent");
    }
}
using UnityEngine;

public class MyPoco : IMyInterface
{
    /// <inheritdoc />
    public void Greet()
    {
        Debug.Log("Hello, World! I'm MyPoco");
    }
}
using UnityEngine;

[CreateAssetMenu(menuName = "MyScriptable")]
public class MyScriptable : ScriptableObject, IMyInterface
{
    /// <inheritdoc />
    public void Greet()
    {
        Debug.Log("Hello, World! I'm MyScriptable");
    }
}

Support

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.

ko-fi

Contributions

Pull requests are welcomed. Please feel free to fix any issues you find, or add new features.

More Repositories

1

Unity3D-ExtendedEvent

A UnityEvent replacement
C#
131
star
2

Unity3D-IconManager

A small script allowing you to set icons for GameObjects through code
C#
63
star
3

Unity3D-ComponentAttribute

An attribute that let's you auto-load components
C#
61
star
4

Unity3D-ExecutionOrderAttribute

An attribute that sets a script's execution order
C#
58
star
5

Unity3D-ExtendedEditor

Entity-like EditorWindow system for Unity3D
C#
56
star
6

Unity3D-NSubstitute

NSubstitute is designed as a friendly substitute for .NET mocking libraries.
42
star
7

Unity3D-AutoHook

A property drawer that automagically assigns a reference to your field
C#
26
star
8

Unity3D-Humanizr

Humanizer meets all your .NET needs for manipulating and displaying strings, enums, dates, times, timespans, numbers and quantities.
C#
25
star
9

Unity3D-CodeGenerator

C#
19
star
10

Unity3D-Histogrammer

A tool for Unity3D to help you pinpoint redundant data
C#
19
star
11

Unity3D-Reflectives

A set of utility classes to make it easier to access hidden functionality
C#
18
star
12

Unity3D-StateMachine

A State Machine for Unity3D
C#
16
star
13

Unity3D-LayersTagsGenerator

Code generators for Layers and Tags
C#
15
star
14

Unity3D-ConstrainedRect

A simple helper for constraining rects to windows and other rects
C#
14
star
15

Unity3D-ScriptingDefineUtility

a small helper that allows you to more easily modify the scripting define symbols for your project
C#
14
star
16

Unity3D-EnumAsIndex

An attribute that allows you to use an enum as an index for arrays and lists
C#
13
star
17

Unity3D-Automatron

An automation tool for Unity3D
C#
11
star
18

Unity3D-ResourceAttribute

An attribute that let's you auto-load resources
C#
10
star
19

Unity3D-Extensions

A simple collection of extensions that I find useful when working with Unity and C#
C#
10
star
20

Unity3D-PackageManagerModules

A toolkit to create modules for the Package Manager Window
C#
8
star
21

Unity3D-PackageManifestEditor

A utility to edit package manifests through code
C#
7
star
22

Unity3D-SafeEvent

An event class for Unity3D that has extra checks to help prevent mistakes
C#
6
star
23

Unity3D-DeepInspector

C#
5
star
24

Unity3D-SerializableInterface.Generation

An automatic code generation addon to SerializableInterface
C#
4
star
25

Modkist

A Zeepkist mod manager
C#
4
star
26

Unity3D-CustomDrawers

Custom drawers that can be used with regular objects/types instead of SerializedObjects
C#
3
star
27

Unity3D-PackageManagerInjectionHelper

A set of classes that allow you to inject your own code into the Package Manager Window
C#
3
star
28

Spartan-Hub

Browser extension companion for Halo 5
JavaScript
2
star
29

Unity3D-SerializableInterface.Generator

C#
2
star
30

Zeepkist-LevelEditorTrails

C#
1
star