218 lines
6.6 KiB
C#
218 lines
6.6 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using UnityEngine.Scripting;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace UnityEngine.Events
|
|
{
|
|
// Token: 0x02000480 RID: 1152
|
|
[UsedByNativeCode]
|
|
[Serializable]
|
|
public abstract class UnityEventBase : ISerializationCallbackReceiver
|
|
{
|
|
// Token: 0x060039C9 RID: 14793 RVA: 0x00064D50 File Offset: 0x00062F50
|
|
protected UnityEventBase()
|
|
{
|
|
this.m_Calls = new InvokableCallList();
|
|
this.m_PersistentCalls = new PersistentCallGroup();
|
|
this.m_TypeName = base.GetType().AssemblyQualifiedName;
|
|
}
|
|
|
|
// Token: 0x060039CA RID: 14794 RVA: 0x00064D88 File Offset: 0x00062F88
|
|
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
|
{
|
|
}
|
|
|
|
// Token: 0x060039CB RID: 14795 RVA: 0x00064D8C File Offset: 0x00062F8C
|
|
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
|
{
|
|
this.DirtyPersistentCalls();
|
|
this.m_TypeName = base.GetType().AssemblyQualifiedName;
|
|
}
|
|
|
|
// Token: 0x060039CC RID: 14796
|
|
protected abstract MethodInfo FindMethod_Impl(string name, object targetObj);
|
|
|
|
// Token: 0x060039CD RID: 14797
|
|
internal abstract BaseInvokableCall GetDelegate(object target, MethodInfo theFunction);
|
|
|
|
// Token: 0x060039CE RID: 14798 RVA: 0x00064DA8 File Offset: 0x00062FA8
|
|
internal MethodInfo FindMethod(PersistentCall call)
|
|
{
|
|
Type type = typeof(Object);
|
|
if (!string.IsNullOrEmpty(call.arguments.unityObjectArgumentAssemblyTypeName))
|
|
{
|
|
type = Type.GetType(call.arguments.unityObjectArgumentAssemblyTypeName, false) ?? typeof(Object);
|
|
}
|
|
return this.FindMethod(call.methodName, call.target, call.mode, type);
|
|
}
|
|
|
|
// Token: 0x060039CF RID: 14799 RVA: 0x00064E1C File Offset: 0x0006301C
|
|
internal MethodInfo FindMethod(string name, object listener, PersistentListenerMode mode, Type argumentType)
|
|
{
|
|
MethodInfo methodInfo;
|
|
switch (mode)
|
|
{
|
|
case PersistentListenerMode.EventDefined:
|
|
methodInfo = this.FindMethod_Impl(name, listener);
|
|
break;
|
|
case PersistentListenerMode.Void:
|
|
methodInfo = UnityEventBase.GetValidMethodInfo(listener, name, new Type[0]);
|
|
break;
|
|
case PersistentListenerMode.Object:
|
|
methodInfo = UnityEventBase.GetValidMethodInfo(listener, name, new Type[] { argumentType ?? typeof(Object) });
|
|
break;
|
|
case PersistentListenerMode.Int:
|
|
methodInfo = UnityEventBase.GetValidMethodInfo(listener, name, new Type[] { typeof(int) });
|
|
break;
|
|
case PersistentListenerMode.Float:
|
|
methodInfo = UnityEventBase.GetValidMethodInfo(listener, name, new Type[] { typeof(float) });
|
|
break;
|
|
case PersistentListenerMode.String:
|
|
methodInfo = UnityEventBase.GetValidMethodInfo(listener, name, new Type[] { typeof(string) });
|
|
break;
|
|
case PersistentListenerMode.Bool:
|
|
methodInfo = UnityEventBase.GetValidMethodInfo(listener, name, new Type[] { typeof(bool) });
|
|
break;
|
|
default:
|
|
methodInfo = null;
|
|
break;
|
|
}
|
|
return methodInfo;
|
|
}
|
|
|
|
// Token: 0x060039D0 RID: 14800 RVA: 0x00064F24 File Offset: 0x00063124
|
|
public int GetPersistentEventCount()
|
|
{
|
|
return this.m_PersistentCalls.Count;
|
|
}
|
|
|
|
// Token: 0x060039D1 RID: 14801 RVA: 0x00064F44 File Offset: 0x00063144
|
|
public Object GetPersistentTarget(int index)
|
|
{
|
|
PersistentCall listener = this.m_PersistentCalls.GetListener(index);
|
|
return (listener == null) ? null : listener.target;
|
|
}
|
|
|
|
// Token: 0x060039D2 RID: 14802 RVA: 0x00064F78 File Offset: 0x00063178
|
|
public string GetPersistentMethodName(int index)
|
|
{
|
|
PersistentCall listener = this.m_PersistentCalls.GetListener(index);
|
|
return (listener == null) ? string.Empty : listener.methodName;
|
|
}
|
|
|
|
// Token: 0x060039D3 RID: 14803 RVA: 0x00064FB0 File Offset: 0x000631B0
|
|
private void DirtyPersistentCalls()
|
|
{
|
|
this.m_Calls.ClearPersistent();
|
|
this.m_CallsDirty = true;
|
|
}
|
|
|
|
// Token: 0x060039D4 RID: 14804 RVA: 0x00064FC8 File Offset: 0x000631C8
|
|
private void RebuildPersistentCallsIfNeeded()
|
|
{
|
|
if (this.m_CallsDirty)
|
|
{
|
|
this.m_PersistentCalls.Initialize(this.m_Calls, this);
|
|
this.m_CallsDirty = false;
|
|
}
|
|
}
|
|
|
|
// Token: 0x060039D5 RID: 14805 RVA: 0x00064FF4 File Offset: 0x000631F4
|
|
public void SetPersistentListenerState(int index, UnityEventCallState state)
|
|
{
|
|
PersistentCall listener = this.m_PersistentCalls.GetListener(index);
|
|
if (listener != null)
|
|
{
|
|
listener.callState = state;
|
|
}
|
|
this.DirtyPersistentCalls();
|
|
}
|
|
|
|
// Token: 0x060039D6 RID: 14806 RVA: 0x00065024 File Offset: 0x00063224
|
|
protected void AddListener(object targetObj, MethodInfo method)
|
|
{
|
|
this.m_Calls.AddListener(this.GetDelegate(targetObj, method));
|
|
}
|
|
|
|
// Token: 0x060039D7 RID: 14807 RVA: 0x0006503C File Offset: 0x0006323C
|
|
internal void AddCall(BaseInvokableCall call)
|
|
{
|
|
this.m_Calls.AddListener(call);
|
|
}
|
|
|
|
// Token: 0x060039D8 RID: 14808 RVA: 0x0006504C File Offset: 0x0006324C
|
|
protected void RemoveListener(object targetObj, MethodInfo method)
|
|
{
|
|
this.m_Calls.RemoveListener(targetObj, method);
|
|
}
|
|
|
|
// Token: 0x060039D9 RID: 14809 RVA: 0x0006505C File Offset: 0x0006325C
|
|
public void RemoveAllListeners()
|
|
{
|
|
this.m_Calls.Clear();
|
|
}
|
|
|
|
// Token: 0x060039DA RID: 14810 RVA: 0x0006506C File Offset: 0x0006326C
|
|
protected void Invoke(object[] parameters)
|
|
{
|
|
this.RebuildPersistentCallsIfNeeded();
|
|
this.m_Calls.Invoke(parameters);
|
|
}
|
|
|
|
// Token: 0x060039DB RID: 14811 RVA: 0x00065084 File Offset: 0x00063284
|
|
public override string ToString()
|
|
{
|
|
return base.ToString() + " " + base.GetType().FullName;
|
|
}
|
|
|
|
// Token: 0x060039DC RID: 14812 RVA: 0x000650B4 File Offset: 0x000632B4
|
|
public static MethodInfo GetValidMethodInfo(object obj, string functionName, Type[] argumentTypes)
|
|
{
|
|
Type type = obj.GetType();
|
|
while (type != typeof(object) && type != null)
|
|
{
|
|
MethodInfo method = type.GetMethod(functionName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, argumentTypes, null);
|
|
if (method != null)
|
|
{
|
|
ParameterInfo[] parameters = method.GetParameters();
|
|
bool flag = true;
|
|
int num = 0;
|
|
foreach (ParameterInfo parameterInfo in parameters)
|
|
{
|
|
Type type2 = argumentTypes[num];
|
|
Type parameterType = parameterInfo.ParameterType;
|
|
flag = type2.IsPrimitive == parameterType.IsPrimitive;
|
|
if (!flag)
|
|
{
|
|
break;
|
|
}
|
|
num++;
|
|
}
|
|
if (flag)
|
|
{
|
|
return method;
|
|
}
|
|
}
|
|
type = type.BaseType;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// Token: 0x0400118E RID: 4494
|
|
private InvokableCallList m_Calls;
|
|
|
|
// Token: 0x0400118F RID: 4495
|
|
[FormerlySerializedAs("m_PersistentListeners")]
|
|
[SerializeField]
|
|
private PersistentCallGroup m_PersistentCalls;
|
|
|
|
// Token: 0x04001190 RID: 4496
|
|
[SerializeField]
|
|
private string m_TypeName;
|
|
|
|
// Token: 0x04001191 RID: 4497
|
|
private bool m_CallsDirty = true;
|
|
}
|
|
}
|