From 4ccd4bc6d126e0e0f51a50aa10c85b9bf48b1210 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 18 Oct 2023 10:16:32 +0800 Subject: + init --- .../Runtime/InvokableCallback.cs | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/InvokableCallback.cs (limited to 'ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/InvokableCallback.cs') diff --git a/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/InvokableCallback.cs b/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/InvokableCallback.cs new file mode 100644 index 0000000..2819874 --- /dev/null +++ b/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/Runtime/InvokableCallback.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class InvokableCallback : InvokableCallbackBase { + + public Func func; + + public TReturn Invoke() { + return func(); + } + + public override TReturn Invoke(params object[] args) { + return func(); + } + + /// Constructor + public InvokableCallback(object target, string methodName) { + if (target == null || string.IsNullOrEmpty(methodName)) { + func = () => default(TReturn); + } else { + func = (System.Func) System.Delegate.CreateDelegate(typeof(System.Func), target, methodName); + } + } +} + +public class InvokableCallback : InvokableCallbackBase { + + public Func func; + + public TReturn Invoke(T0 arg0) { + return func(arg0); + } + + public override TReturn Invoke(params object[] args) { + // Convert from special "unity-nulls" to true null + if (args[0] is UnityEngine.Object && (UnityEngine.Object) args[0] == null) args[0] = null; + return func((T0) args[0]); + } + + /// Constructor + public InvokableCallback(object target, string methodName) { + if (target == null || string.IsNullOrEmpty(methodName)) { + func = x => default(TReturn); + } else { + func = (System.Func) System.Delegate.CreateDelegate(typeof(System.Func), target, methodName); + } + } +} + +public class InvokableCallback : InvokableCallbackBase { + + public Func func; + + public TReturn Invoke(T0 arg0, T1 arg1) { + return func(arg0, arg1); + } + + public override TReturn Invoke(params object[] args) { + // Convert from special "unity-nulls" to true null + if (args[0] is UnityEngine.Object && (UnityEngine.Object) args[0] == null) args[0] = null; + if (args[1] is UnityEngine.Object && (UnityEngine.Object) args[1] == null) args[1] = null; + return func((T0) args[0], (T1) args[1]); + } + + /// Constructor + public InvokableCallback(object target, string methodName) { + if (target == null || string.IsNullOrEmpty(methodName)) { + func = (x, y) => default(TReturn); + } else { + func = (System.Func) System.Delegate.CreateDelegate(typeof(System.Func), target, methodName); + } + } +} + +public class InvokableCallback : InvokableCallbackBase { + + public Func func; + + public TReturn Invoke(T0 arg0, T1 arg1, T2 arg2) { + return func(arg0, arg1, arg2); + } + + public override TReturn Invoke(params object[] args) { + // Convert from special "unity-nulls" to true null + if (args[0] is UnityEngine.Object && (UnityEngine.Object) args[0] == null) args[0] = null; + if (args[1] is UnityEngine.Object && (UnityEngine.Object) args[1] == null) args[1] = null; + if (args[2] is UnityEngine.Object && (UnityEngine.Object) args[2] == null) args[2] = null; + return func((T0) args[0], (T1) args[1], (T2) args[2]); + } + + /// Constructor + public InvokableCallback(object target, string methodName) { + if (target == null || string.IsNullOrEmpty(methodName)) { + func = (x, y, z) => default(TReturn); + } else { + func = (System.Func) System.Delegate.CreateDelegate(typeof(System.Func), target, methodName); + } + } +} + +public class InvokableCallback : InvokableCallbackBase { + + public Func func; + + public TReturn Invoke(T0 arg0, T1 arg1, T2 arg2, T3 arg3) { + return func(arg0, arg1, arg2, arg3); + } + + public override TReturn Invoke(params object[] args) { + // Convert from special "unity-nulls" to true null + if (args[0] is UnityEngine.Object && (UnityEngine.Object) args[0] == null) args[0] = null; + if (args[1] is UnityEngine.Object && (UnityEngine.Object) args[1] == null) args[1] = null; + if (args[2] is UnityEngine.Object && (UnityEngine.Object) args[2] == null) args[2] = null; + if (args[3] is UnityEngine.Object && (UnityEngine.Object) args[3] == null) args[3] = null; + return func((T0) args[0], (T1) args[1], (T2) args[2], (T3) args[3]); + } + + /// Constructor + public InvokableCallback(object target, string methodName) { + if (target == null || string.IsNullOrEmpty(methodName)) { + func = (x, y, z, w) => default(TReturn); + } else { + func = (System.Func) System.Delegate.CreateDelegate(typeof(System.Func), target, methodName); + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0