You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
971 B
31 lines
971 B
using System; |
|
using Unity.Collections; |
|
using Unity.Collections.LowLevel.Unsafe; |
|
|
|
namespace GameCore.LowLevel |
|
{ |
|
public static class NativeArrayExtensions |
|
{ |
|
public static ref T GetRef<T>(this NativeArray<T> array, int index) |
|
where T : struct |
|
{ |
|
if (index < 0 || index >= array.Length) |
|
throw new ArgumentOutOfRangeException(nameof(index)); |
|
unsafe |
|
{ |
|
return ref UnsafeUtility.ArrayElementAsRef<T>(array.GetUnsafePtr(), index); |
|
} |
|
} |
|
|
|
public static ref readonly T GetReadOnlyRef<T>(this NativeArray<T> array, int index) |
|
where T : struct |
|
{ |
|
if (index < 0 || index >= array.Length) |
|
throw new ArgumentOutOfRangeException(nameof(index)); |
|
unsafe |
|
{ |
|
return ref UnsafeUtility.ArrayElementAsRef<T>(array.GetUnsafeReadOnlyPtr(), index); |
|
} |
|
} |
|
} |
|
} |