Пример #1
0
        /// <summary>
        /// Class constructor.
        /// <param name="target">The target object (node, variable or generic object).</param>
        /// <param name="serializedNode">The target serialized node.</param>
        /// <param name="path">The property path.</param>
        /// <param name="type">The type of the property.</param>
        /// <param name="propertyType">The property type.</param>
        /// <param name="array">The array that the element belongs to.</param>
        /// <param name="index">The element index.</param>
        /// <param name="variableInfo">A variable info if the serialized property is a variable; null otherwise.</param>
        /// </summary>
        public SerializedArrayElement (object target, SerializedNode serializedNode, string path, System.Type type, NodePropertyType propertyType, Array array, int index, VariableInfoAttribute variableInfo) : base (target, serializedNode, path, type, propertyType) {
            m_Array = array;
            m_Index = index;
            m_VariableInfo = variableInfo;
            this.label = "Element " + index.ToString();

            // Its a variable type?
            if (propertyType == NodePropertyType.Variable) {
                // Update label
                this.tooltip = (type.Name + ": " + this.tooltip).Replace("Var", string.Empty);

                // Set concreteVariable
                var variable = m_Array.GetValue(m_Index) as BehaviourMachine.Variable;
                System.Type variableType = variable != null ? variable.GetType() : null;
                m_IsConcreteVariable = variableType != null && TypeUtility.GetConcreteType(variableType) == variableType;
            }
        }
Пример #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();
        }