forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersistentCall.cs
More file actions
142 lines (142 loc) · 3.76 KB
/
Copy pathPersistentCall.cs
File metadata and controls
142 lines (142 loc) · 3.76 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Reflection;
using UnityEngine.Serialization;
namespace UnityEngine.Events
{
[Serializable]
internal class PersistentCall
{
[FormerlySerializedAs("instance"), SerializeField]
private UnityEngine.Object m_Target;
[FormerlySerializedAs("methodName"), SerializeField]
private string m_MethodName;
[FormerlySerializedAs("mode"), SerializeField]
private PersistentListenerMode m_Mode;
[FormerlySerializedAs("arguments"), SerializeField]
private ArgumentCache m_Arguments = new ArgumentCache();
[FormerlySerializedAs("enabled"), FormerlySerializedAs("m_Enabled"), SerializeField]
private UnityEventCallState m_CallState = UnityEventCallState.RuntimeOnly;
public UnityEngine.Object target
{
get
{
return this.m_Target;
}
}
public string methodName
{
get
{
return this.m_MethodName;
}
}
public PersistentListenerMode mode
{
get
{
return this.m_Mode;
}
set
{
this.m_Mode = value;
}
}
public ArgumentCache arguments
{
get
{
return this.m_Arguments;
}
}
public UnityEventCallState callState
{
get
{
return this.m_CallState;
}
set
{
this.m_CallState = value;
}
}
public bool IsValid()
{
return this.target != null && !string.IsNullOrEmpty(this.methodName);
}
public BaseInvokableCall GetRuntimeCall(UnityEventBase theEvent)
{
if (this.m_CallState == UnityEventCallState.RuntimeOnly && !Application.isPlaying)
{
return null;
}
if (this.m_CallState == UnityEventCallState.Off || theEvent == null)
{
return null;
}
MethodInfo methodInfo = theEvent.FindMethod(this);
if (methodInfo == null)
{
return null;
}
switch (this.m_Mode)
{
case PersistentListenerMode.EventDefined:
return theEvent.GetDelegate(this.target, methodInfo);
case PersistentListenerMode.Void:
return new InvokableCall(this.target, methodInfo);
case PersistentListenerMode.Object:
return PersistentCall.GetObjectCall(this.target, methodInfo, this.m_Arguments);
case PersistentListenerMode.Int:
return new CachedInvokableCall<int>(this.target, methodInfo, this.m_Arguments.intArgument);
case PersistentListenerMode.Float:
return new CachedInvokableCall<float>(this.target, methodInfo, this.m_Arguments.floatArgument);
case PersistentListenerMode.String:
return new CachedInvokableCall<string>(this.target, methodInfo, this.m_Arguments.stringArgument);
case PersistentListenerMode.Bool:
return new CachedInvokableCall<bool>(this.target, methodInfo, this.m_Arguments.boolArgument);
default:
return null;
}
}
private static BaseInvokableCall GetObjectCall(UnityEngine.Object target, MethodInfo method, ArgumentCache arguments)
{
Type type = typeof(UnityEngine.Object);
if (!string.IsNullOrEmpty(arguments.unityObjectArgumentAssemblyTypeName))
{
type = (Type.GetType(arguments.unityObjectArgumentAssemblyTypeName, false) ?? typeof(UnityEngine.Object));
}
Type typeFromHandle = typeof(CachedInvokableCall<>);
Type type2 = typeFromHandle.MakeGenericType(new Type[]
{
type
});
ConstructorInfo constructor = type2.GetConstructor(new Type[]
{
typeof(UnityEngine.Object),
typeof(MethodInfo),
type
});
UnityEngine.Object @object = arguments.unityObjectArgument;
if (@object != null && !type.IsAssignableFrom(@object.GetType()))
{
@object = null;
}
return constructor.Invoke(new object[]
{
target,
method,
@object
}) as BaseInvokableCall;
}
public void RegisterPersistentListener(UnityEngine.Object ttarget, string mmethodName)
{
this.m_Target = ttarget;
this.m_MethodName = mmethodName;
}
public void UnregisterPersistentListener()
{
this.m_MethodName = string.Empty;
this.m_Target = null;
}
}
}