using System; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; namespace GameCore.LowLevel { public static class NativeArrayExtensions { public static ref T GetRef(this NativeArray array, int index) where T : struct { if (index < 0 || index >= array.Length) throw new ArgumentOutOfRangeException(nameof(index)); unsafe { return ref UnsafeUtility.ArrayElementAsRef(array.GetUnsafePtr(), index); } } public static ref readonly T GetReadOnlyRef(this NativeArray array, int index) where T : struct { if (index < 0 || index >= array.Length) throw new ArgumentOutOfRangeException(nameof(index)); unsafe { return ref UnsafeUtility.ArrayElementAsRef(array.GetUnsafeReadOnlyPtr(), index); } } } }