private ImportNode(ImportNode parent, SettingsExporter.Node node) { this.parent = parent; this.node = node; this.arrayExportOptions = ExportableAttribute.ArrayOptions.Immutable | ExportableAttribute.ArrayOptions.Overwrite; this.arrayImportOption = ArrayImportOption.Overwrite; this.instanceType = Type.GetType(node.name); if (this.instanceType != null) { UnityEngine.Object[] instances = Resources.FindObjectsOfTypeAll(this.instanceType); if (instances.Length > 0) { this.instance = instances[0]; this.children = new ImportNode[node.children.Count]; for (int i = 0; i < this.children.Length; i++) { this.children[i] = new ImportNode(this, node.children[i], this.instanceType, this.instance); } } } }
private void DrawNode(SettingsExporter.Node node) { EditorGUILayout.BeginHorizontal(); { GUILayout.Space((GUI.depth - 1) * 16F); node.include = GUILayout.Toggle(node.include, Utility.NicifyVariableName(node.name)); if (node.value != null) { GUILayout.Label("<color=cyan>" + node.value + "</color>", this.richTextField); } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); ++GUI.depth; for (int i = 0; i < node.children.Count; i++) { if (node.children[i].options == SettingsExporter.Node.Option.Normal) { EditorGUI.BeginDisabledGroup(GUI.enabled == false || node.include == false); { this.DrawNode(node.children[i]); } EditorGUI.EndDisabledGroup(); } } --GUI.depth; }
private void OutputNode(SettingsExporter.Node node, int depth = 0) { Debug.Log(new string(' ', depth) + node.name + "=" + node.value); for (int i = 0; i < node.children.Count; i++) { this.OutputNode(node.children[i], depth + 1); } }
public ImportNode(SettingsExporter.Node node) { this.parent = null; this.node = node; this.instance = null; this.instanceType = null; this.children = new ImportNode[node.children.Count]; for (int i = 0; i < this.children.Length; i++) { this.children[i] = new ImportNode(this, node.children[i]); } }
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 ImportNode(ImportNode parent, SettingsExporter.Node node, Type workingType, object workingInstance) { this.parent = parent; this.node = node; // Instance is null only when the parent is an array. this.instanceType = workingType; // Look for class. //if (this.instanceType.FullName == node.name) // this.instance = instance; // Look for array element. if (typeof(IEnumerable).IsAssignableFrom(this.instanceType) == true) { this.arrayElementType = Type.GetType(node.name); if (this.arrayElementType == null) { Debug.LogWarning("Type \"" + node.name + "\" was not recognized."); } else { foreach (ExportableAttribute attribute in this.arrayElementType.EachCustomAttributesIncludingBaseInterfaces <ExportableAttribute>()) { this.arrayExportOptions = attribute.options; if ((attribute.options & ExportableAttribute.ArrayOptions.Add) != 0) { this.arrayImportOption = ArrayImportOption.Add; } else if ((attribute.options & ExportableAttribute.ArrayOptions.Overwrite) != 0) { this.arrayImportOption = ArrayImportOption.Overwrite; } } } this.instance = null; this.instanceType = this.arrayElementType; if (workingInstance != null) { IEnumerable array = workingInstance as IEnumerable; foreach (var item in array) { if (item.GetType() == this.arrayElementType && ImportSettingsWizard.trackObjects.Contains(item) == false) { this.instance = item; ImportSettingsWizard.trackObjects.Add(item); break; } } } //if (this.instance == null) // this.instance = Activator.CreateInstance(this.arrayElementType); } // Look for field. else { FieldInfo fieldInfo = this.instanceType.GetField(node.name, SettingsExporter.SearchFlags); if (fieldInfo != null) { if (fieldInfo.IsDefined(typeof(HideFromExportAttribute), true) == true) { node.options = SettingsExporter.Node.Option.Hidden; } this.fieldInfo = new FieldModifier(fieldInfo); if (this.fieldInfo.IsDefined(typeof(ExportableAttribute), true) == true) { this.arrayExportOptions = (this.fieldInfo.GetCustomAttributes(typeof(ExportableAttribute), true)[0] as ExportableAttribute).options; this.instanceType = this.fieldInfo.Type; if (workingInstance != null) { this.instance = this.fieldInfo.GetValue(workingInstance); } } } else { PropertyInfo propertyInfo = this.instanceType.GetProperty(node.name, SettingsExporter.SearchFlags); if (propertyInfo == null) { Debug.LogWarning("Name \"" + node.name + "\" was not found in " + this.instanceType.FullName + "."); } else { if (propertyInfo.IsDefined(typeof(HideFromExportAttribute), true) == true) { node.options = SettingsExporter.Node.Option.Hidden; } this.fieldInfo = new PropertyModifier(propertyInfo); if (this.fieldInfo.IsDefined(typeof(ExportableAttribute), true) == true) { this.arrayExportOptions = (this.fieldInfo.GetCustomAttributes(typeof(ExportableAttribute), true)[0] as ExportableAttribute).options; this.instanceType = this.fieldInfo.Type; if (workingInstance != null) { this.instance = this.fieldInfo.GetValue(workingInstance); } } } } //else // Debug.LogWarning("Field \"" + node.name + "\" is not decorated with the attribute \"" + typeof(ExportableAttribute) + "\" in " + this.instanceType.FullName + "."); } //if (this.instance != null) //{ this.children = new ImportNode[node.children.Count]; for (int i = 0; i < this.children.Length; i++) { this.children[i] = new ImportNode(this, node.children[i], this.instanceType, this.instance); } //} //else // this.children = new ImportNode[0]; }
public void Init(SettingsExporter.Node root) { this.root = new ImportNode(root); }