lundi 22 août 2016

C# - Copying UnityEvent information using reflection

I need to copy the events from one UnityEvent to another, as once I figure this out I will be switching out the target at runtime to another object, what I have so far is:

MethodInfo info = UnityEventBase.GetValidMethodInfo (event1.GetPersistentTarget (i), event1.GetPersistentMethodName (i), Type.EmptyTypes);
UnityAction action = Delegate.CreateDelegate (typeof (UnityAction), info) as UnityAction;

event2.AddListener (action);

I get ArgumentNullException: Argument cannot be null., and if I change Type.EmptyTypes to new Type[] { typeof (float) }, I get ArgumentException: method argument length mismatch.

The problem being that I don't know what to put in there since I don't know what the type is (since Unity Events can send a bool, float, etc.)

Unity Docs don't cover this, so hopefully someone else has had success in the past.





Aucun commentaire:

Enregistrer un commentaire