using System;
using Unity.Collections;
using UnityEngine.Jobs;
namespace UnityEngine.Rendering
{
///
/// Array utilities functions
///
public static class ArrayExtensions
{
///
/// Resizes a native array. If an empty native array is passed, it will create a new one.
///
/// The type of the array
/// Target array to resize
/// New size of native array to resize
public static void ResizeArray(this ref NativeArray array, int capacity) where T : struct
{
var newArray = new NativeArray(capacity, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
if (array.IsCreated)
{
NativeArray.Copy(array, newArray, array.Length);
array.Dispose();
}
array = newArray;
}
///
/// Resizes a transform access array.
///
/// Target array to resize
/// New size of transform access array to resize
public static void ResizeArray(this ref TransformAccessArray array, int capacity)
{
var newArray = new TransformAccessArray(capacity);
if (array.isCreated)
{
for (int i = 0; i < array.length; ++i)
newArray.Add(array[i]);
array.Dispose();
}
array = newArray;
}
///
/// Resizes an array. If a null reference is passed, it will allocate the desired array.
///
/// The type of the array
/// Target array to resize
/// New size of array to resize
public static void ResizeArray(ref T[] array, int capacity)
{
if (array == null)
{
array = new T[capacity];
return;
}
Array.Resize(ref array, capacity);
}
}
}