/// <summary> /// Retrieve a member of the contaner by index. /// </summary> /// <param name="index">The zero-based index into the list.</param> /// <value>The list item at the specified index.</value> /// <exception cref="IndexOutOfRangeException">Thrown if index is negative or >= to <see cref="Length"/>.</exception> public T this[int index] { get { #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.CheckReadAndThrow(m_Safety); #endif CheckIndexInRange(index, m_ListData->Length); return UnsafeUtility.ReadArrayElement<T>(m_ListData->Ptr, CollectionHelper.AssumePositive(index)); } set { #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.CheckWriteAndThrow(m_Safety); #endif CheckIndexInRange(index, m_ListData->Length); UnsafeUtility.WriteArrayElement(m_ListData->Ptr, CollectionHelper.AssumePositive(index), value); } }
/// <summary> /// Adds elements from a buffer to this list. /// </summary> /// <typeparam name="T">Source type of elements</typeparam> /// <param name="ptr">A pointer to the buffer.</param> /// <param name="length">The number of elements to add to the list.</param> /// <remarks> /// If the list has reached its current capacity, internal array won't be resized, and exception will be thrown. /// </remarks> /// <exception cref="ArgumentOutOfRangeException">Thrown if length is negative.</exception> public void AddRangeNoResize(void *ptr, int length) { CheckArgPositive(length); AddRangeNoResize(UnsafeUtility.SizeOf <T>(), UnsafeUtility.AlignOf <T>(), ptr, CollectionHelper.AssumePositive(length)); }
/// <summary> /// Truncates the list by replacing the item at the specified index range with the items from the end the list. The list /// is shortened by number of elements in range. /// </summary> /// <typeparam name="T">Source type of elements</typeparam> /// <param name="begin">The first index of the item to remove.</param> /// <param name="end">The index past-the-last item to remove.</param> public void RemoveRangeSwapBack(int begin, int end) { #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.CheckWriteAndBumpSecondaryVersion(m_Safety); #endif m_ListData->RemoveRangeSwapBack <T>(CollectionHelper.AssumePositive(begin), CollectionHelper.AssumePositive(end)); }