OldBlueWater/BlueWater/Assets/NWH/Common/Scripts/Utility/ArrayExtensions.cs

33 lines
977 B
C#
Raw Normal View History

2023-08-01 04:03:57 +00:00
using System;
using Unity.Collections;
namespace NWH.Common.Utility
{
public static class ArrayExtensions
{
public static void Fill<T>(this T[] destinationArray, params T[] value)
{
int destinationLength = destinationArray.Length;
if (destinationLength == 0)
{
return;
}
int valueLength = value.Length;
// set the initial array value
Array.Copy(value, destinationArray, valueLength);
int arrayToFillHalfLength = destinationLength / 2;
int copyLength;
for (copyLength = valueLength; copyLength < arrayToFillHalfLength; copyLength <<= 1)
{
Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength);
}
Array.Copy(destinationArray, 0, destinationArray, copyLength,
destinationLength - copyLength);
}
}
}