/// <summary> /// Draws the dropdown for selecting a method from bindableViewModelMethods /// </summary> private void ShowMethodMenu(EventBinding targetScript, MethodInfo[] bindableMethods) { var tooltip = "Method on the view-model to bind to."; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(new GUIContent("View-model method", tooltip)); var dropdownPosition = GUILayoutUtility.GetLastRect(); dropdownPosition.x += dropdownPosition.width; if (GUILayout.Button(new GUIContent(targetScript.viewModelMethodName, tooltip), EditorStyles.popup)) { InspectorUtils.ShowMenu( method => method.ReflectedType + "/" + method.Name, method => true, method => MemberInfoToString(method) == targetScript.viewModelMethodName, method => UpdateProperty( updatedValue => targetScript.viewModelMethodName = updatedValue, targetScript.viewModelMethodName, MemberInfoToString(method) ), bindableMethods .OrderBy(method => method.ReflectedType.Name) .ThenBy(method => method.Name) .ToArray(), dropdownPosition ); } EditorGUILayout.EndHorizontal(); }
/// <summary> /// Display a popup menu for selecting a property from a view-model. /// </summary> protected void ShowViewModelPropertyMenu( GUIContent label, PropertyInfo[] bindableProperties, Action <string> propertyValueSetter, string curPropertyValue, Func <PropertyInfo, bool> menuEnabled ) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(label); var dropdownPosition = GUILayoutUtility.GetLastRect(); dropdownPosition.x += dropdownPosition.width; if (GUILayout.Button(new GUIContent(curPropertyValue, label.tooltip), EditorStyles.popup)) { InspectorUtils.ShowMenu( property => string.Concat(property.ReflectedType, "/", property.Name, " : ", property.PropertyType.Name), menuEnabled, property => MemberInfoToString(property) == curPropertyValue, property => UpdateProperty( propertyValueSetter, curPropertyValue, MemberInfoToString(property) ), bindableProperties .OrderBy(property => property.ReflectedType.Name) .ThenBy(property => property.Name) .ToArray(), dropdownPosition ); } EditorGUILayout.EndHorizontal(); }