forked from Siccity/SerializableCallback
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializableEventBase.cs
More file actions
40 lines (36 loc) · 1.08 KB
/
Copy pathSerializableEventBase.cs
File metadata and controls
40 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public abstract class SerializableEventBase : SerializableCallbackBase {
public InvokableEventBase invokable;
public override void ClearCache() {
base.ClearCache();
invokable = null;
}
protected InvokableEventBase GetPersistentMethod() {
Type[] types = new Type[ArgTypes.Length];
Array.Copy(ArgTypes, types, ArgTypes.Length);
Type genericType = null;
switch (types.Length) {
case 0:
genericType = typeof(InvokableEvent);
break;
case 1:
genericType = typeof(InvokableEvent<>).MakeGenericType(types);
break;
case 2:
genericType = typeof(InvokableEvent<,>).MakeGenericType(types);
break;
case 3:
genericType = typeof(InvokableEvent<, ,>).MakeGenericType(types);
break;
case 4:
genericType = typeof(InvokableEvent<, , ,>).MakeGenericType(types);
break;
default:
throw new ArgumentException(types.Length + "args");
}
return Activator.CreateInstance(genericType, new object[] { target, methodName }) as InvokableEventBase;
}
}