GithubHelp home page GithubHelp logo

isabella232 / serializablecallback Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unity-technologies/serializablecallback

0.0 0.0 0.0 42 KB

UnityEvent and System.Func had a child

License: MIT License

C# 100.00%

serializablecallback's Introduction

SerializableCallback

Lets you drag-and-drop methods with or without return values / parameters in the Unity inspector. It uses expression trees and reflection to cache a delegate on first execution.

Usage is identical to UnityEvent

unity_inspector

public class MyClass : MonoBehaviour {
    //These fields are shown in the inspector
    public SerializableCallback callback; // supports all non-void return types
    public Condition condition; // supports bool return types only
    public GetProduct getProduct; // supports MyProduct return types only

    void Start() {
        // Callbacks can be invoked with or without parameters, and with different types
        Debug.Log(callback.Invoke()); // returns object
        Debug.Log(condition.Invoke()); // returns bool
        Debug.Log(getProduct.Invoke(2)); // returns MyProduct
    }

    // As with UnityEvents, custom callbacks must have a non-generic wrapper class marked as [Serializable] in order to be serialized by Unity
    [Serializable]
    public class Condition : SerializableCallback<bool> {}

    // Last generic type parameter is the return type, staying consistent with System.Func
    [Serializable]
    public class GetProduct : SerializableCallback<int, MyProduct> {}
}
Performance (100000 iterations) Time
bool Method(float) 00.00304s
SerializedCallback<float, bool> (Persistent) 00.01026s
SerializedCallback<float, bool> (Dynamic) 00.00797s

Installing with Unity Package Manager

To install this project as a dependency using the Unity Package Manager, add the following line to your project's manifest.json:

"com.github.siccity.serializablecallback": "git+https://github.com/Siccity/SerializableCallback.git"

Join the Discord server to leave feedback or get support.

serializablecallback's People

Contributors

alikamarainen avatar cheeseman5 avatar fahoom avatar kyuskoj avatar rfadeev avatar siccity avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.