protected virtual void OnGUI() { if (this.richTextField == null) { this.richTextField = new GUIStyle(GUI.skin.textField); this.richTextField.richText = true; } this.DrawWizardGUI(); using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton)) { if (GUILayout.Button(LC.G("ExportSettings_Export")) == true) { if (SettingsExporter.Export(this.instances, this.root, exportFile) == true) { InternalNGDebug.Log(LC.G("ExportSettings_ExportSuccess")); } else { InternalNGDebug.LogError(LC.G("ExportSettings_ExportFailed")); } } } this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition); this.DrawNode(this.root); EditorGUILayout.EndScrollView(); }
private static Node Browse(Node parent, object instance) { Type type = instance.GetType(); Node node = new Node(parent, type.FullName); foreach (FieldInfo field in Utility.EachFieldHierarchyOrdered(type, typeof(object), SettingsExporter.SearchFlags)) { if (field.IsDefined(typeof(ExportableAttribute), true) == true) { node.children.Add(SettingsExporter.Browse(node, field, field.GetValue(instance))); } } foreach (PropertyInfo property in Utility.EachPropertyHierarchyOrdered(type, typeof(object), SettingsExporter.SearchFlags)) { if (property.IsDefined(typeof(ExportableAttribute), true) == true) { node.children.Add(SettingsExporter.Browse(node, property, property.GetValue(instance, null))); } } if (type.IsDefined(typeof(HideFromExportAttribute), true) == true) { node.options = Node.Option.Hidden; } return(node); }
public static Node Collect(params object[] instances) { Node root = new Node(null, "ROOT"); for (int i = 0; i < instances.Length; i++) { root.children.Add(SettingsExporter.Browse(null, instances[i])); } return(root); }
protected virtual void OnEnable() { this.instances = new List <object>(); foreach (Type type in Utility.EachAllSubClassesOf(typeof(EditorWindow), (Type t) => t.IsDefined(typeof(ExportableAttribute), false))) { Object[] instances = Resources.FindObjectsOfTypeAll(type); if (instances.Length > 0) { this.instances.Add(instances[0]); } } this.root = SettingsExporter.Collect(this.instances.ToArray()); //this.OutputNode(this.root); Utility.LoadEditorPref(this); }
private static void StringifyNode(StringBuilder buffer, SettingsExporter.Node node, int depth = 0) { if (node.include == true) { buffer.Append(' ', depth); buffer.Append(node.name); buffer.Append('='); if (node.value != null) { buffer.AppendLine(node.value); } else { buffer.AppendLine(); } } for (int i = 0; i < node.children.Count; i++) { SettingsExporter.StringifyNode(buffer, node.children[i], depth + 1); } }
private static Node Browse(Node parent, PropertyInfo property, object instance) { Node node = new Node(parent, property.Name); if (instance == null) { return(node); } if (property.PropertyType.IsPrimitive == true || property.PropertyType == typeof(string)) { node.value = instance.ToString(); } else if (property.PropertyType.IsArray == true || instance is IEnumerable) { IEnumerable array = instance as IEnumerable; int count = 0; foreach (var item in array) { if (item.GetType().IsDefined(typeof(ExcludeFromExportAttribute), true) == false) { node.children.Add(SettingsExporter.Browse(node, item)); ++count; } } node.value = count.ToString(); } else if (property.PropertyType.IsClass == true || property.PropertyType.IsStruct() == true) { ExportableAttribute[] attributes = property.GetCustomAttributes(typeof(ExportableAttribute), true) as ExportableAttribute[]; if (attributes.Length > 0 && attributes[0].fields != null) { for (int j = 0; j < attributes[0].fields.Length; j++) { FieldInfo fi = property.PropertyType.GetField(attributes[0].fields[j]); InternalNGDebug.Assert(fi != null, "Field \"" + attributes[0].fields[j] + "\" was not found in type " + property.PropertyType + "."); node.children.Add(SettingsExporter.Browse(node, fi, fi.GetValue(instance))); } } foreach (FieldInfo subField in Utility.EachFieldHierarchyOrdered(property.PropertyType, typeof(object), SettingsExporter.SearchFlags)) { if (subField.IsDefined(typeof(ExportableAttribute), true) == true) { node.children.Add(SettingsExporter.Browse(node, subField, subField.GetValue(instance))); } } foreach (PropertyInfo subProperty in Utility.EachPropertyHierarchyOrdered(property.PropertyType, typeof(object), SettingsExporter.SearchFlags)) { if (subProperty.IsDefined(typeof(ExportableAttribute), true) == true) { node.children.Add(SettingsExporter.Browse(node, subProperty, subProperty.GetValue(instance, null))); } } } if (property.IsDefined(typeof(HideFromExportAttribute), true) == true) { node.options = Node.Option.Hidden; } return(node); }