GetAllSubTypesInScripts
How do I use Get All Sub Types In Scripts
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
914 | var types = GetAllSubTypesInScripts(typeof(MonoBehaviour)); | 1 |
975 | public static System.Type[] GetAllSubTypesInScripts(System.Type aBaseClass) | 2 |
File name: PhotonEditor.cs
Copy
909 public static void UpdateRpcList()
910 {
911 List
912 HashSet
913
914 var types = GetAllSubTypesInScripts(typeof(MonoBehaviour));
915
916 foreach (var mono in types)
917 {
918 MethodInfo[] methods = mono.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
919
920 foreach (MethodInfo method in methods)
921 {
922 if (method.IsDefined(typeof(UnityEngine.RPC), false))
923 {
924 currentRpcs.Add(method.Name);
925
926 if (!additionalRpcs.Contains(method.Name) && !PhotonEditor.Current.RpcList.Contains(method.Name))
927 {
928 additionalRpcs.Add(method.Name);
929 }
930 }
931 }
932 }
933
934 if (additionalRpcs.Count > 0)
935 {
936 // LIMITS RPC COUNT
937 if (additionalRpcs.Count + PhotonEditor.Current.RpcList.Count >= byte.MaxValue)
938 {
939 if (currentRpcs.Count <= byte.MaxValue)
940 {
941 bool clearList = EditorUtility.DisplayDialog(CurrentLang.IncorrectRPCListTitle, CurrentLang.IncorrectRPCListLabel, CurrentLang.RemoveOutdatedRPCsLabel, CurrentLang.CancelButton);
942 if (clearList)
943 {
944 PhotonEditor.Current.RpcList.Clear();
945 PhotonEditor.Current.RpcList.AddRange(currentRpcs);
946 }
947 else
948 {
949 return;
950 }
951 }
952 else
953 {
954 EditorUtility.DisplayDialog(CurrentLang.FullRPCListTitle, CurrentLang.FullRPCListLabel, CurrentLang.SkipRPCListUpdateLabel);
955 return;
956 }
957 }
958
959 additionalRpcs.Sort();
960 PhotonEditor.Current.RpcList.AddRange(additionalRpcs);
961 EditorUtility.SetDirty(PhotonEditor.Current);
962 }
963 }
File name: PhotonEditor.cs
Copy
975 public static System.Type[] GetAllSubTypesInScripts(System.Type aBaseClass)
976 {
977 var result = new System.Collections.Generic.List
978 System.Reflection.Assembly[] AS = System.AppDomain.CurrentDomain.GetAssemblies();
979 foreach (var A in AS)
980 {
981 // this skips all but the Unity-scripted assemblies for RPC-list creation. You could remove this to search all assemblies in project
982 if (!A.FullName.StartsWith("Assembly-"))
983 {
984 // Debug.Log("Skipping Assembly: " + A);
985 continue;
986 }
987
988 //Debug.Log("Assembly: " + A.FullName);
989 System.Type[] types = A.GetTypes();
990 foreach (var T in types)
991 {
992 if (T.IsSubclassOf(aBaseClass))
993 result.Add(T);
994 }
995 }
996 return result.ToArray();
997 }
GetAllSubTypesInScripts 147 lượt xem
Gõ tìm kiếm nhanh...