private static MonoGizmoMethod[] ExtractGizmos(Assembly assembly) { List <MonoGizmoMethod> list = new List <MonoGizmoMethod>(); System.Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly); foreach (System.Type type in typesFromAssembly) { MethodInfo[] methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); for (int i = 0; i < methods.GetLength(0); i++) { MethodInfo info = methods[i]; object[] customAttributes = info.GetCustomAttributes(typeof(DrawGizmo), false); foreach (DrawGizmo gizmo in customAttributes) { System.Reflection.ParameterInfo[] parameters = info.GetParameters(); if (parameters.Length != 2) { UnityEngine.Debug.LogWarning($"Method {info.DeclaringType.FullName}.{info.Name} is marked with the DrawGizmo attribute but does not take parameters (ComponentType, GizmoType) so will be ignored."); } else { MonoGizmoMethod item = new MonoGizmoMethod(); if (gizmo.drawnType == null) { item.drawnType = parameters[0].ParameterType; } else if (parameters[0].ParameterType.IsAssignableFrom(gizmo.drawnType)) { item.drawnType = gizmo.drawnType; } else { UnityEngine.Debug.LogWarning($"Method {info.DeclaringType.FullName}.{info.Name} is marked with the DrawGizmo attribute but the component type it applies to could not be determined."); goto Label_0198; } if ((parameters[1].ParameterType != typeof(GizmoType)) && (parameters[1].ParameterType != typeof(int))) { UnityEngine.Debug.LogWarning($"Method {info.DeclaringType.FullName}.{info.Name} is marked with the DrawGizmo attribute but does not take a second parameter of type GizmoType so will be ignored."); } else { item.drawGizmo = info; item.options = (int)gizmo.drawOptions; list.Add(item); } Label_0198 :; } } } } return(list.ToArray()); }
static MonoGizmoMethod[] ExtractGizmos(Assembly assembly) { var commands = new List <MonoGizmoMethod>(); foreach (var mi in EditorAssemblies.GetAllMethodsWithAttribute <DrawGizmo>(BindingFlags.Static).Where(m => m.DeclaringType.Assembly == assembly)) { var attrs = mi.GetCustomAttributes(typeof(DrawGizmo), false).Cast <DrawGizmo>(); foreach (var gizmoAttr in attrs) { var parameters = mi.GetParameters(); if (parameters.Length != 2) { Debug.LogWarningFormat( "Method {0}.{1} is marked with the DrawGizmo attribute but does not take parameters (ComponentType, GizmoType) so will be ignored.", mi.DeclaringType?.FullName, mi.Name ); continue; } if (mi.DeclaringType != null && mi.DeclaringType.IsGenericTypeDefinition) { Debug.LogWarningFormat( "Method {0}.{1} is marked with the DrawGizmo attribute but is defined on a generic type definition, so will be ignored.", mi.DeclaringType.FullName, mi.Name ); continue; } var item = new MonoGizmoMethod(); if (gizmoAttr.drawnType == null) { item.drawnType = parameters[0].ParameterType; } else if (parameters[0].ParameterType.IsAssignableFrom(gizmoAttr.drawnType)) { item.drawnType = gizmoAttr.drawnType; } else { Debug.LogWarningFormat( "Method {0}.{1} is marked with the DrawGizmo attribute but the component type it applies to could not be determined.", mi.DeclaringType?.FullName, mi.Name ); continue; } if (parameters[1].ParameterType != typeof(GizmoType) && parameters[1].ParameterType != typeof(int)) { Debug.LogWarningFormat( "Method {0}.{1} is marked with the DrawGizmo attribute but does not take a second parameter of type GizmoType so will be ignored.", mi.DeclaringType?.FullName, mi.Name ); continue; } item.drawGizmo = mi; item.options = (int)gizmoAttr.drawOptions; commands.Add(item); } } return(commands.ToArray()); }