/// <summary> /// Returns a set of serialized properties in an object. /// <param name="serializedNode">The target serialized node.</param> /// <param name="target">The object to get the properties.</param> /// <param name="targetType">The target object type.</param> /// <param name="currentPath">The property path of the target.</param> /// <returns>The serialized properties in the target object.</returns> /// </summary> static SerializedNodeProperty[] GetPropertiesData(SerializedNode serializedNode, object target, Type targetType, string currentPath = "") { // Create the property data list var propertyData = new List <SerializedNodeProperty>(); // Get serialized fields for the target type FieldInfo[] serializedFields = NodeSerialization.GetSerializedFields(targetType); for (int i = 0; i < serializedFields.Length; i++) { // Get field FieldInfo field = serializedFields[i]; // Get field type var fieldType = field.FieldType; // Get the field property attribute var propertyAttr = AttributeUtility.GetAttribute <PropertyAttribute>(field, true); // Get the property type var propertyType = SerializedNode.GetPropertyType(fieldType); // Create the property data var currentSerializedField = new SerializedNodeField(serializedNode, currentPath + field.Name, propertyType, target, field); propertyData.Add(currentSerializedField); // Variable? if (propertyType == NodePropertyType.Variable) { // Get the field value object fieldValue = target != null?field.GetValue(target) : null; // Get the children fields SerializedNodeProperty[] children = SerializedNode.GetPropertiesData(serializedNode, fieldValue, fieldValue != null ? fieldValue.GetType() : fieldType, currentPath + field.Name + "."); // Create the property drawer for the "Value" child property if (propertyAttr != null && currentSerializedField.isConcreteVariable) { foreach (var child in children) { // It is the "Value" property? if (child.label == "Value") { child.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr); } } } // Set children currentSerializedField.SetChildren(children); } // Array? else if (propertyType == NodePropertyType.Array) { // Get the array value Array array = target != null?field.GetValue(target) as Array : null; // Get array element type var elementType = fieldType.GetElementType(); // Create the array children list var childrenList = new List <SerializedNodeProperty>(); // Create the array size childrenList.Add(new SerializedArraySize(target, serializedNode, currentSerializedField.path + ".size", currentSerializedField, array, elementType)); // Create children var variableInfo = AttributeUtility.GetAttribute <VariableInfoAttribute>(field, true) ?? new VariableInfoAttribute(); childrenList.AddRange(SerializedNode.GetPropertiesData(serializedNode, target, array, elementType, currentSerializedField.path + ".", variableInfo, propertyAttr)); // Set array data children currentSerializedField.SetChildren(childrenList.ToArray()); } // Get the property drawer else if (propertyAttr != null) { currentSerializedField.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr); } } return(propertyData.ToArray()); }
/// <summary> /// Returns a set of serialized properties in an object. /// <param name="serializedNode">The target serialized node.</param> /// <param name="target">The object to get the properties.</param> /// <param name="targetType">The target object type.</param> /// <param name="currentPath">The property path of the target.</param> /// <returns>The serialized properties in the target object.</returns> /// </summary> static SerializedNodeProperty[] GetPropertiesData (SerializedNode serializedNode, object target, Type targetType, string currentPath = "") { // Create the property data list var propertyData = new List<SerializedNodeProperty>(); // Get serialized fields for the target type FieldInfo[] serializedFields = NodeSerialization.GetSerializedFields(targetType); for (int i = 0; i < serializedFields.Length; i++) { // Get field FieldInfo field = serializedFields[i]; // Get field type var fieldType = field.FieldType; // Get the field property attribute var propertyAttr = AttributeUtility.GetAttribute<PropertyAttribute>(field, true); // Get the property type var propertyType = SerializedNode.GetPropertyType(fieldType); // Create the property data var currentSerializedField = new SerializedNodeField(serializedNode, currentPath + field.Name, propertyType, target, field); propertyData.Add(currentSerializedField); // Variable? if (propertyType == NodePropertyType.Variable) { // Get the field value object fieldValue = target != null ? field.GetValue(target) : null; // Get the children fields SerializedNodeProperty[] children = SerializedNode.GetPropertiesData(serializedNode, fieldValue, fieldValue != null ? fieldValue.GetType() : fieldType, currentPath + field.Name + "."); // Create the property drawer for the "Value" child property if (propertyAttr != null && currentSerializedField.isConcreteVariable) { foreach (var child in children) { // It is the "Value" property? if (child.label == "Value") child.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr); } } // Set children currentSerializedField.SetChildren(children); } // Array? else if (propertyType == NodePropertyType.Array) { // Get the array value Array array = target != null ? field.GetValue(target) as Array : null; // Get array element type var elementType = fieldType.GetElementType(); // Create the array children list var childrenList = new List<SerializedNodeProperty>(); // Create the array size childrenList.Add(new SerializedArraySize(target, serializedNode, currentSerializedField.path + ".size", currentSerializedField, array, elementType)); // Create children var variableInfo = AttributeUtility.GetAttribute<VariableInfoAttribute>(field, true) ?? new VariableInfoAttribute(); childrenList.AddRange(SerializedNode.GetPropertiesData(serializedNode, target, array, elementType, currentSerializedField.path + ".", variableInfo, propertyAttr)); // Set array data children currentSerializedField.SetChildren(childrenList.ToArray()); } // Get the property drawer else if (propertyAttr != null) currentSerializedField.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr); } return propertyData.ToArray(); }