void DrawConfigItem(Type type, XmlNode configItemNode) { string memberName = configItemNode.LocalName; PropertyInfo property = null; FieldInfo field = null; MethodInfo method = null; MemberInfo member; member = FindMember(type, memberName); Type valueType = null; if (member is PropertyInfo) { property = (PropertyInfo)member; valueType = property.PropertyType; } else if (member is FieldInfo) { field = (FieldInfo)member; valueType = field.FieldType; } else if (member is MethodInfo) { method = (MethodInfo)member; } bool handle = false; using (var scope = new GUILayout.HorizontalScope()) { string displayName; XmlNode valueNode = configItemNode; if (field != null || property != null) { var first = configItemNode.SelectSingleNode("ns:*", nsMgr); if (first != null) { valueNode = first; } } using (new GUILayout.HorizontalScope(GUILayout.Width(EditorGUIUtility.labelWidth))) { displayName = memberName; EditorGUILayoutx.MenuButton <object>(new GUIContent(displayName), "label", (d) => { GenericMenu menu = new GenericMenu(); if (property != null || field != null) { SetValueNodeMenu(configItemNode, configItemNode, menu); } menu.AddItem(new GUIContent("Delete".Localization()), false, () => { using (EditorOneBuild.EditorLocalizationValues.BeginScope()) { if (EditorUtility.DisplayDialog($"Delete".Localization(), string.Format("msg_del_item_content".Localization(), displayName), "ok", "cancel")) { configItemNode.ParentNode.RemoveChild(configItemNode); DirtyConfig(); } } }); return(menu); }, null); GUILayout.FlexibleSpace(); DrawLabelOptions(valueNode); DrawCombineNodeValue(configItemNode, valueNode); } if (field != null || property != null) { DrawValueNode(valueNode, valueType); handle = true; } } if (member == null) { EditorGUILayout.HelpBox("member null", MessageType.Error); return; } if (!handle) { if (method != null) { using (new EditorGUILayoutx.Scopes.IndentLevelVerticalScope()) { int paramIndex = 0; var paramNodes = configItemNode.SelectNodes("ns:*", nsMgr); foreach (var parameter in method.GetParameters()) { if (paramIndex >= paramNodes.Count) { EditorGUILayout.HelpBox("Parameter length error" + method.GetParameters().Length, MessageType.Error, false); break; } XmlNode paramNode = paramNodes[paramIndex]; using (new GUILayout.HorizontalScope()) { using (new GUILayout.HorizontalScope(GUILayout.Width(EditorGUIUtility.labelWidth))) { EditorGUILayoutx.MenuButton(new GUIContent(parameter.Name), "label", (d) => { GenericMenu menu = new GenericMenu(); SetValueNodeMenu(configItemNode, d, menu); return(menu); }, paramNode, GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace(); DrawLabelOptions(paramNode); DrawCombineNodeValue(configItemNode, paramNode); } DrawValueNode(paramNode, parameter.ParameterType); } paramIndex++; } } } else { } } }
void DrawTypeNode(XmlElement typeNode) { XmlAttribute attr; string typeName; typeName = typeNode.GetAttributeValue("type", string.Empty); attr = typeNode.GetOrAddAttribute("name", string.Empty); Type type = null; if (!string.IsNullOrEmpty(typeName)) { type = FindType(typeName); } object obj = null; using (new EditorGUILayout.HorizontalScope()) { EditorGUILayoutx.MenuButton(new GUIContent(typeName), "label", () => { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Delete".Localization()), false, () => { using (EditorOneBuild.EditorLocalizationValues.BeginScope()) { if (EditorUtility.DisplayDialog("Delete".Localization(), string.Format("msg_del_type_content".Localization(), typeName), "ok", "cancel")) { typeNode.ParentNode.RemoveChild(typeNode); DirtyConfig(); } } }); return(menu); }); attr.Value = EditorGUILayoutx.DelayedPlaceholderField(attr.Value ?? string.Empty, new GUIContent("Alias".Localization()), GUILayout.Width(120)); EditorGUILayoutx.MenuButton(new GUIContent("+"), "label", () => { GenericMenu menu = new GenericMenu(); var members = new Dictionary <string, MemberInfo>(EditorOneBuild.GetSetMembers(type)); foreach (XmlNode itemNode in typeNode.SelectNodes("ns:*", nsMgr)) { if (itemNode.NodeType == XmlNodeType.Element) { members.Remove(itemNode.Name); } } foreach (var member in members.Values.OrderBy(o => o.Name)) { if (member.IsDefined(typeof(System.ObsoleteAttribute), true)) { continue; } MethodInfo method1 = member as MethodInfo; if (method1 != null) { if (member.Name.StartsWith("Get") && method1.ReturnType != typeof(void)) { continue; } } menu.AddItem(new GUIContent(member.Name), false, (data) => { MemberInfo mInfo = (MemberInfo)data; XmlNode memberNode = typeNode.OwnerDocument.CreateElement(mInfo.Name, EditorOneBuild.XMLNS); if (mInfo.MemberType == MemberTypes.Field || mInfo.MemberType == MemberTypes.Property) { Type valueType; if (mInfo.MemberType == MemberTypes.Field) { FieldInfo fInfo = (FieldInfo)mInfo; valueType = fInfo.FieldType; } else { PropertyInfo pInfo = (PropertyInfo)mInfo; valueType = pInfo.PropertyType; } memberNode.InnerText = valueType.GetDefaultValue().ToStringOrEmpty(); } else if (mInfo.MemberType == MemberTypes.Method) { MethodInfo method = (MethodInfo)mInfo; foreach (var p in method.GetParameters()) { XmlNode paramNode = memberNode.OwnerDocument.CreateElement(p.Name, EditorOneBuild.XMLNS); paramNode.InnerText = p.ParameterType.GetDefaultValue().ToStringOrEmpty(); memberNode.AppendChild(paramNode); } } typeNode.AppendChild(memberNode); DirtyConfig(); }, member); } return(menu); }, GUILayout.ExpandWidth(false)); } if (string.IsNullOrEmpty(typeName)) { //EditorGUILayout.HelpBox("type name empty", MessageType.Error); // GUIUtility.ExitGUI(); } if (type == null) { //if (Event.current.type == EventType.Repaint) //EditorGUILayout.HelpBox($"type null, <{typeName}>", MessageType.Error); return; } using (new EditorGUILayoutx.Scopes.IndentLevelVerticalScope()) { foreach (var itemNode in ToEnumerable(typeNode.SelectNodes("*"))) { DrawConfigItem(type, itemNode); } } }