예제 #1
0
 public static ref T GetRefRead <T>(this Unity.Collections.NativeList <T> array, int index) where T : unmanaged
 {
     CheckArray(index, array.Length);
     unsafe {
         var ptr = array.GetUnsafeReadOnlyPtr();
         #if UNITY_2020_1_OR_NEWER
         return(ref UnsafeUtility.ArrayElementAsRef <T>(ptr, index));
         #else
         throw new Exception("UnsafeUtility.ArrayElementAsRef");
         #endif
     }
 }
예제 #2
0
 public static ref T GetRefRead <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.GetUnsafeReadOnlyPtr();
         #if UNITY_2020_1_OR_NEWER
         return(ref UnsafeUtility.ArrayElementAsRef <T>(ptr, index));
         #else
         throw new Exception("UnsafeUtility.ArrayElementAsRef");
         #endif
     }
 }