예제 #1
0
        protected virtual GenericMenu CreateMenu(GameObject go, SerializedProperty property)
        {
            var menu    = new GenericMenu();
            var hotCall = property.GetTargetObject() as Call;

            if (go != null)
            {
                var item = "GameObject/";
                foreach (var mi in typeof(GameObject).GetMethods().OrderBy(x => x.Name))
                {
                    if (IsSupportedMethod(mi, property, hotCall))
                    {
                        menu.AddItem(new GUIContent(item + SurrogateEditorExtensions.GetNiceName(typeof(GameObject), mi)), false, AddCall(go, property, null, mi));
                    }
                }
                foreach (var c in go.GetComponents(typeof(Component)).OrderBy(x => x.GetType().Name))
                {
                    var ct = c.GetType();
                    item = $"{ct.Name}/";
                    foreach (var mi in ct.GetMethods().OrderBy(x => x.Name))
                    {
                        if (IsSupportedMethod(mi, property, hotCall))
                        {
                            menu.AddItem(new GUIContent(item + SurrogateEditorExtensions.GetNiceName(ct, mi)), false, AddCall(go, property, c, mi));
                        }
                    }
                }
            }
            return(menu);
        }
예제 #2
0
 protected virtual bool IsSupportedMethod(MethodInfo mi, SerializedProperty property, Call hotCall)
 {
     if (hotCall.GetType() == typeof(MethodCall))
     {
         return(SurrogateEditorExtensions.IsSupportedMethod(mi.DeclaringType, mi));
     }
     if (hotCall.GetType() == typeof(PredicateCall))
     {
         return(SurrogateEditorExtensions.IsSupportedMethod(mi.DeclaringType, mi));
     }
     return(false);
 }
예제 #3
0
 protected static GenericMenu.MenuFunction AddCall(GameObject gameObject, SerializedProperty property, Component component, MethodInfo mi)
 {
     return(() =>
     {
         var componentType = component == null ? typeof(GameObject) : component.GetType();
         property.FindPropertyRelative("component").objectReferenceValue = component;
         var metaMethodInfo = property.FindPropertyRelative("metaMethodInfo");
         metaMethodInfo.FindPropertyRelative("className").stringValue = SurrogateEditorExtensions.GetClassName(componentType, mi);
         metaMethodInfo.FindPropertyRelative("type").stringValue = componentType.AssemblyQualifiedName;
         metaMethodInfo.FindPropertyRelative("name").stringValue = mi.Name;
         metaMethodInfo.FindPropertyRelative("niceName").stringValue = SurrogateEditorExtensions.GetNiceName(componentType, mi);
         var typeNames = SurrogateEditorExtensions.GetParameterTypeNames(mi);
         var typeNamesProperty = metaMethodInfo.FindPropertyRelative("parameterTypeNames");
         typeNamesProperty.ClearArray();
         foreach (var typeName in typeNames)
         {
             typeNamesProperty.InsertArrayElementAtIndex(typeNamesProperty.arraySize);
             typeNamesProperty.GetArrayElementAtIndex(typeNamesProperty.arraySize - 1).stringValue = typeName;
         }
         property.serializedObject.ApplyModifiedProperties();
         // UniventCodeGenerator.Instance.AddMethod(componentType, mi);
     });
 }