Last active
December 28, 2015 20:29
-
-
Save cnsoft/7557501 to your computer and use it in GitHub Desktop.
Dynamic GetMethod and call it!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//client.Photon.SupportClass. | |
public static List<MethodInfo> GetMethods (Type type, Type attribute) | |
{ | |
List<MethodInfo> list = new List<MethodInfo> (); | |
List<MethodInfo> result; | |
if (type == null) | |
{ | |
result = list; | |
} | |
else | |
{ | |
MethodInfo[] methods = type.GetMethods (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); | |
MethodInfo[] array = methods; | |
for (int i = 0; i < array.Length; i++) | |
{ | |
MethodInfo methodInfo = array [i]; | |
if (attribute == null || methodInfo.IsDefined (attribute, false)) | |
{ | |
list.Add (methodInfo); | |
} | |
} | |
result = list; | |
} | |
return result; | |
} | |
// | |
internal protected static bool GetMethod(MonoBehaviour monob, string methodType, out MethodInfo mi) | |
{ | |
mi = null; | |
if (monob == null || string.IsNullOrEmpty(methodType)) | |
{ | |
return false; | |
} | |
List<MethodInfo> methods = SupportClass.GetMethods(monob.GetType(), null); | |
for (int index = 0; index < methods.Count; index++) | |
{ | |
MethodInfo methodInfo = methods[index]; | |
if (methodInfo.Name.Equals(methodType)) | |
{ | |
mi = methodInfo; | |
return true; | |
} | |
} | |
return false; | |
} | |
//call it | |
internal protected void ExecuteOnSerialize(PhotonStream pStream, PhotonMessageInfo info) | |
{ | |
if (failedToFindOnSerialize) | |
{ | |
return; | |
} | |
if (OnSerializeMethodInfo == null) | |
{ | |
if (!NetworkingPeer.GetMethod(this.observed as MonoBehaviour, PhotonNetworkingMessage.OnPhotonSerializeView.ToString(), out OnSerializeMethodInfo)) | |
{ | |
Debug.LogError("The observed monobehaviour (" + this.observed.name + ") of this PhotonView does not implement OnPhotonSerialize()!"); | |
failedToFindOnSerialize = true; | |
return; | |
} | |
} | |
OnSerializeMethodInfo.Invoke((object)this.observed, new object[] { pStream, info }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
support ios? GetType().GetMethods