Пример #1
0
        /// <summary>
        /// Add a slice of elements taken from the given list.
        /// </summary>
        /// <param name="list"></param>
        /// <param name="count"></param>
        /// <param name="destinationIndex"></param>
        /// <param name="sourceIndex"></param>
        /// <typeparam name="TList"></typeparam>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public void AddSlice <TList>(TList list, int count = -1, int destinationIndex = -1, int sourceIndex = 0)
            where TList : IReadOnlyList <TControl>
        {
            if (count < 0)
            {
                count = list.Count;
            }
            if (destinationIndex < 0)
            {
                destinationIndex = Count;
            }

            if (count == 0)
            {
                return;
            }
            if (sourceIndex + count > list.Count)
            {
                throw new ArgumentOutOfRangeException(string.Format(
                                                          "Count of {0} elements starting at index {1} exceeds length of list of {2}", count, sourceIndex,
                                                          list.Count), "count");
            }

            // Make space in the list.
            if (Capacity < count)
            {
                Capacity = Math.Max(count, 10);
            }
            if (destinationIndex < Count)
                #if UNITY_2018_3_OR_NEWER
            { NativeArray <ulong> .Copy(m_Indices, destinationIndex, m_Indices, destinationIndex + count,
                                        Count - destinationIndex); }
                #else
            { Unity2018_2_Compatibility.Copy <ulong>(m_Indices, destinationIndex, m_Indices, destinationIndex + count,
                                                     Count - destinationIndex); }
                #endif

            // Add elements.
            for (var i = 0; i < count; ++i)
            {
                m_Indices[destinationIndex + i] = ToIndex(list[sourceIndex + i]);
            }
            m_Count += count;
        }
Пример #2
0
        public void AddRange(IEnumerable <TControl> list, int count = -1, int destinationIndex = -1)
        {
            if (count < 0)
            {
                count = list.Count();
            }
            if (destinationIndex < 0)
            {
                destinationIndex = Count;
            }

            if (count == 0)
            {
                return;
            }

            // Make space in the list.
            if (Capacity < count)
            {
                Capacity = Math.Max(count, 10);
            }
            if (destinationIndex < Count)
                #if UNITY_2018_3_OR_NEWER
            { NativeArray <ulong> .Copy(m_Indices, destinationIndex, m_Indices, destinationIndex + count,
                                        Count - destinationIndex); }
                #else
            { Unity2018_2_Compatibility.Copy <ulong>(m_Indices, destinationIndex, m_Indices, destinationIndex + count,
                                                     Count - destinationIndex); }
                #endif

            // Add elements.
            foreach (var element in list)
            {
                m_Indices[destinationIndex++] = ToIndex(element);
                ++m_Count;
                --count;
                if (count == 0)
                {
                    break;
                }
            }
        }