2016-08-23 260 views
0

我需要將事件從一個UnityEvent複製到另一個UnityEvent,因爲一旦我知道了這一點,我將在運行時切換到另一個對象,到目前爲止我是:C# - 使用反射覆制UnityEvent信息

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

event2.AddListener (action); 

我得到ArgumentNullException: Argument cannot be null.,如果我改變Type.EmptyTypesnew Type[] { typeof (float) },我得到ArgumentException: method argument length mismatch

的問題是,我不知道要放什麼東西在那裏,因爲我不知道是什麼類型(因爲統一活動可以發送一個bool,float等)

統一文檔不要不會掩蓋這一點,所以希望別人在過去取得成功。

回答

0

對於任何人,在未來過這個失蹄,這工作:

MethodInfo info = UnityEventBase.GetValidMethodInfo (event1.GetPersistentTarget (i), event1.GetPersistentMethodName (i), new Type[] { typeof (float) }); 
      UnityAction execute =() => info.Invoke (event1.GetPersistentTarget (i), new object[] { 180f }); 
      event2.AddListener (execute); 

它只是不暴露在檢查複製的聽衆,所以仍然在尋找一個完美的解決方案。