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 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]; }