Exemple #1
0
        /// <summary>
        /// Add the source <c>collection</c> to the array property.
        /// </summary>
        /// <param name="property">Property.</param>
        /// <param name="collection">Collection.</param>
        public static void AddRange(this SerializedProperty property, IEnumerable <Object> collection)
        {
            property.CheckArray();

            foreach (var _element in collection)
            {
                property.arraySize++;
                property.GetArrayElementAtIndex(property.arraySize - 1).objectReferenceValue = _element;
            }

            property.serializedObject.ApplyModifiedProperties();
        }
Exemple #2
0
        /// <summary>
        /// Insert an array element at the specified index and return it.
        /// </summary>
        ///
        /// <remarks>
        /// Optional to copy values from the original element at the index, like the Unity's default behavior.
        /// Otherwise Leave all the values empty.
        /// </remarks>
        ///
        /// <returns>Element property.</returns>
        /// <param name="property">Property.</param>
        /// <param name="index">Index.</param>
        /// <param name="copy">If set to <c>true</c> copy.</param>
        ///
        public static SerializedProperty Insert(this SerializedProperty property, int index = -1, bool copy = false)
        {
            property.CheckArray();
            if (0 > index || index > property.arraySize)
            {
                index = property.arraySize;
            }

            property.InsertArrayElementAtIndex(copy ? index : 0);
            if (!copy)
            {
                property.MoveArrayElement(0, index);
            }

            property.serializedObject.ApplyModifiedProperties();
            return(property.GetArrayElementAtIndex(index));
        }