/// <summary> /// Update the values in the properties. /// </summary> public void Update() { if (m_RecreateData) { m_RecreateData = false; m_PropertiesData = SerializedNode.GetPropertiesData(this, m_Target, m_Type); } if (m_Target != null) { SerializedNode.UpdatePropertiesRecursively(m_PropertiesData); } }
/// <summary> /// Returns a set of serialized properties in an array. /// <param name="serializedNode">The target serialized node.</param> /// <param name="target">The target object (node, variable or generic object).</param> /// <param name="targetArray">The target array.</param> /// <param name="type">The elements type in the array.</param> /// <param name="currentPath">The property path of the target array.</param> /// <param name="variableInfo">The variable info in the array or null.</param> /// <param name="propertyAttr">The property attribute in the array.</param> /// <returns>The serialized properties in the array.</returns> /// </summary> static SerializedNodeProperty[] GetPropertiesData(SerializedNode serializedNode, object target, Array targetArray, Type type, string currentPath, VariableInfoAttribute variableInfo, PropertyAttribute propertyAttr) { // Create the property data list var propertyData = new List <SerializedNodeProperty>(); // Get the property type var propertyType = SerializedNode.GetPropertyType(type); if (targetArray != null) { // Variable? if (propertyType == NodePropertyType.Variable) { for (int i = 0; i < targetArray.Length; i++) { // Get the field value object elementValue = targetArray.GetValue(i); // Create the variable data var variableData = new SerializedArrayElement(target, serializedNode, currentPath + "data[" + i.ToString() + "]", type, propertyType, targetArray, i, variableInfo); // Create the variable children SerializedNodeProperty[] children = SerializedNode.GetPropertiesData(serializedNode, elementValue, elementValue != null ? elementValue.GetType() : type, variableData.path + "."); // Create the property drawer for the "Value" child property if (propertyAttr != null && variableData.isConcreteVariable) { foreach (var child in children) { // It is the "Value" property? if (child.label == "Value") { child.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr); } } } // Set children variableData.SetChildren(children); // Add the variable data to the list propertyData.Add(variableData); } } // Array? else if (propertyType == NodePropertyType.Array) { for (int i = 0; i < targetArray.Length; i++) { // Create the current property data var currentPropertyData = new SerializedArrayElement(target, serializedNode, currentPath + "data[" + i.ToString() + "]", type, propertyType, targetArray, i, variableInfo); // Get the array value var array = targetArray.GetValue(i) as Array; // Get array element type var elementType = type.GetElementType(); // Create the array children list var childrenList = new List <SerializedNodeProperty>(); // Create the array size childrenList.Add(new SerializedArraySize(target, serializedNode, currentPropertyData.path + ".size", currentPropertyData, array, elementType)); // Create array children childrenList.AddRange(SerializedNode.GetPropertiesData(serializedNode, target, array, elementType, currentPropertyData.path + ".", variableInfo, propertyAttr)); // Set array data children currentPropertyData.SetChildren(childrenList.ToArray()); // Add to list propertyData.Add(currentPropertyData); } } else { for (int i = 0; i < targetArray.Length; i++) { // Create the current property data var currentPropertyData = new SerializedArrayElement(target, serializedNode, currentPath + "data[" + i.ToString() + "]", type, propertyType, targetArray, i, variableInfo); // Try to get a property drawer if (propertyAttr != null) { currentPropertyData.customDrawer = NodePropertyDrawer.GetDrawer(propertyAttr); } // Add to list propertyData.Add(currentPropertyData); } } } 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()); }