Esempio n. 1
0
        /// <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());
        }
Esempio n. 2
0
        /// <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();
        }