Siccity / SerializableCallback

UnityEvent and System.Func had a child
MIT License
359 stars 53 forks source link

Support for non value types. #6

Open fscigliano opened 5 years ago

fscigliano commented 5 years ago

UnityEvent has support for common serialized types not inherited from UnityEngine.Object. By debugging the code, it seems that SerializableCallback has a validation method for parameters that checks if they are a value type and inherits from UnityEngine.Object, and returns invalid if they not. So for feature parity with UnityEvent, SerializableCallback should support these custom types.

Example: Add this Component to a GameObject, and try to select the dynamic method TestMethod from both the UnityEvent and the SerializableEvent. Only the UnityEvent will provide the option.

using UnityEngine;
using UnityEngine.Events;

public class TestCallbackReceiver : MonoBehaviour {

    [System.Serializable]
    public class TestClass
    {
        public int a;
        public int b;
    }
    [System.Serializable] public class TestUnityEvent: UnityEvent<TestClass, bool, bool> {}
    [System.Serializable] public class TestSerializableCallback: SerializableEvent<TestClass, bool, bool> {}

    public TestUnityEvent testEvent;
    public TestSerializableCallback testSerializableCallback;

    public void TestMethod(TestClass a, bool b, bool c)
    {
        Debug.Log("only detected by UnityEvent");
    }
}
mnicolas94 commented 11 months ago

I added this feature here. You can use my fork.