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 --- .../ThirdParty/SerializableCallback/README.md | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ActiveRagdoll/Assets/ThirdParty/SerializableCallback/README.md (limited to 'ActiveRagdoll/Assets/ThirdParty/SerializableCallback/README.md') diff --git a/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/README.md b/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/README.md new file mode 100644 index 0000000..a9a7c62 --- /dev/null +++ b/ActiveRagdoll/Assets/ThirdParty/SerializableCallback/README.md @@ -0,0 +1,49 @@ +### 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](https://user-images.githubusercontent.com/6402525/34294989-46de127e-e70b-11e7-84f0-99bc4525a8f5.png) +```csharp +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 {} + + // Last generic type parameter is the return type, staying consistent with System.Func + [Serializable] + public class GetProduct : SerializableCallback {} +} +``` + +| Performance (100000 iterations) | Time | +| -------------------------------------------- | --------- | +| bool Method(float) | 00.00304s | +| SerializedCallback (Persistent) | 00.01026s | +| SerializedCallback (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](https://discord.gg/qgPrHv4 "Join Discord server") server to leave feedback or get support. + + -- cgit v1.1-26-g67d0