public static ref T GetRef <T>(this Unity.Collections.NativeList <T> array, int index) where T : unmanaged { CheckArray(index, array.Length); unsafe { var ptr = array.GetUnsafePtr(); #if UNITY_2020_1_OR_NEWER return(ref UnsafeUtility.ArrayElementAsRef <T>(ptr, index)); #else throw new Exception("UnsafeUtility.ArrayElementAsRef"); #endif } }
public static ref T GetRef <T>(this Unity.Collections.NativeList <T> array, int index) where T : struct { if (index < 0 || index >= array.Length) { throw new ArgumentOutOfRangeException(nameof(index)); } unsafe { var ptr = array.GetUnsafePtr(); #if UNITY_2020_1_OR_NEWER return(ref UnsafeUtility.ArrayElementAsRef <T>(ptr, index)); #else throw new Exception("UnsafeUtility.ArrayElementAsRef"); #endif } }