Files
Dec2017-Script-Dump/UnityEngine/Collections/NativeArray.cs
T
2026-06-04 11:42:34 +02:00

244 lines
6.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace UnityEngine.Collections
{
// Token: 0x020004C7 RID: 1223
[NativeContainer]
[NativeContainerSupportsMinMaxWriteRestriction]
[DebuggerDisplay("Length = {Length}")]
[DebuggerTypeProxy(typeof(NativeArrayDebugView<>))]
public struct NativeArray<T> : IDisposable, IEnumerable<T>, IEnumerable where T : struct
{
// Token: 0x06003BB5 RID: 15285 RVA: 0x00068D54 File Offset: 0x00066F54
public NativeArray(int length, Allocator allocMode)
{
NativeArray<T>.Allocate(length, allocMode, out this);
}
// Token: 0x06003BB6 RID: 15286 RVA: 0x00068D60 File Offset: 0x00066F60
public NativeArray(T[] array, Allocator allocMode)
{
if (array == null)
{
throw new ArgumentNullException("array");
}
NativeArray<T>.Allocate(array.Length, allocMode, out this);
this.FromArray(array);
}
// Token: 0x06003BB7 RID: 15287 RVA: 0x00068D88 File Offset: 0x00066F88
internal NativeArray(IntPtr dataPointer, int length)
{
this = new NativeArray<T>(dataPointer, length, Allocator.None);
}
// Token: 0x06003BB8 RID: 15288 RVA: 0x00068D94 File Offset: 0x00066F94
internal NativeArray(IntPtr dataPointer, int length, int stride, AtomicSafetyHandle safety, Allocator allocMode)
{
this.m_Buffer = dataPointer;
this.m_Length = length;
this.m_Stride = stride;
this.m_AllocatorLabel = allocMode;
}
// Token: 0x06003BB9 RID: 15289 RVA: 0x00068DB4 File Offset: 0x00066FB4
private NativeArray(IntPtr dataPointer, int length, Allocator allocMode)
{
if (dataPointer == IntPtr.Zero)
{
throw new ArgumentOutOfRangeException("dataPointer", "Pointer must not be zero");
}
if (length < 0)
{
throw new ArgumentOutOfRangeException("length", "Length must be >= 0");
}
this.m_Buffer = dataPointer;
this.m_Length = length;
this.m_Stride = UnsafeUtility.SizeOf<T>();
this.m_AllocatorLabel = allocMode;
}
// Token: 0x17000D85 RID: 3461
// (get) Token: 0x06003BBA RID: 15290 RVA: 0x00068E1C File Offset: 0x0006701C
public int Length
{
get
{
return this.m_Length;
}
}
// Token: 0x17000D86 RID: 3462
public T this[int index]
{
get
{
if (index >= this.m_Length)
{
this.FailOutOfRangeError(index);
}
return UnsafeUtility.ReadArrayElement<T>(this.m_Buffer, index * this.m_Stride);
}
set
{
if (index >= this.m_Length)
{
this.FailOutOfRangeError(index);
}
UnsafeUtility.WriteArrayElement<T>(this.m_Buffer, index * this.m_Stride, value);
}
}
// Token: 0x06003BBD RID: 15293 RVA: 0x00068EA0 File Offset: 0x000670A0
public void Dispose()
{
UnsafeUtility.Free(this.m_Buffer, this.m_AllocatorLabel);
this.m_Buffer = IntPtr.Zero;
this.m_Length = 0;
}
// Token: 0x06003BBE RID: 15294 RVA: 0x00068EC8 File Offset: 0x000670C8
public IntPtr GetUnsafeReadBufferPtr()
{
return this.m_Buffer;
}
// Token: 0x06003BBF RID: 15295 RVA: 0x00068EE4 File Offset: 0x000670E4
public IntPtr GetUnsafeWriteBufferPtr()
{
return this.m_Buffer;
}
// Token: 0x06003BC0 RID: 15296 RVA: 0x00068F00 File Offset: 0x00067100
public void FromArray(T[] array)
{
if (this.Length != array.Length)
{
throw new ArgumentException("Array length does not match the length of this instance");
}
for (int i = 0; i < this.Length; i++)
{
UnsafeUtility.WriteArrayElement<T>(this.m_Buffer, i * this.m_Stride, array[i]);
}
}
// Token: 0x06003BC1 RID: 15297 RVA: 0x00068F58 File Offset: 0x00067158
public T[] ToArray()
{
T[] array = new T[this.Length];
for (int i = 0; i < this.Length; i++)
{
array[i] = UnsafeUtility.ReadArrayElement<T>(this.m_Buffer, i * this.m_Stride);
}
return array;
}
// Token: 0x06003BC2 RID: 15298 RVA: 0x00068FAC File Offset: 0x000671AC
private void FailOutOfRangeError(int index)
{
throw new IndexOutOfRangeException(string.Format("Index {0} is out of range of '{1}' Length.", index, this.Length));
}
// Token: 0x06003BC3 RID: 15299 RVA: 0x00068FD0 File Offset: 0x000671D0
private static void Allocate(int length, Allocator allocMode, out NativeArray<T> outArray)
{
if (allocMode <= Allocator.None)
{
throw new ArgumentOutOfRangeException("allocMode", "Allocator must be Temp, Job or Persistent");
}
if (length < 0)
{
throw new ArgumentOutOfRangeException("length", "Length must be >= 0");
}
long num = (long)UnsafeUtility.SizeOf<T>() * (long)length;
if (num > 2147483647L)
{
throw new ArgumentOutOfRangeException("length", "Length * sizeof(T) cannot exceed " + int.MaxValue + "bytes");
}
outArray = new NativeArray<T>(UnsafeUtility.Malloc((int)num, UnsafeUtility.AlignOf<T>(), allocMode), length, allocMode);
}
// Token: 0x06003BC4 RID: 15300 RVA: 0x0006905C File Offset: 0x0006725C
public IEnumerator<T> GetEnumerator()
{
return new NativeArray<T>.Enumerator(ref this);
}
// Token: 0x06003BC5 RID: 15301 RVA: 0x0006907C File Offset: 0x0006727C
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
// Token: 0x040011EF RID: 4591
private IntPtr m_Buffer;
// Token: 0x040011F0 RID: 4592
private int m_Length;
// Token: 0x040011F1 RID: 4593
private int m_Stride;
// Token: 0x040011F2 RID: 4594
private readonly Allocator m_AllocatorLabel;
// Token: 0x020004C8 RID: 1224
public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
{
// Token: 0x06003BC6 RID: 15302 RVA: 0x00069098 File Offset: 0x00067298
public Enumerator(ref NativeArray<T> array)
{
this.array = array;
this.index = -1;
}
// Token: 0x06003BC7 RID: 15303 RVA: 0x000690B0 File Offset: 0x000672B0
public void Dispose()
{
}
// Token: 0x06003BC8 RID: 15304 RVA: 0x000690B4 File Offset: 0x000672B4
public bool MoveNext()
{
this.index++;
return this.index < this.array.Length;
}
// Token: 0x06003BC9 RID: 15305 RVA: 0x000690EC File Offset: 0x000672EC
public void Reset()
{
this.index = -1;
}
// Token: 0x17000D88 RID: 3464
// (get) Token: 0x06003BCA RID: 15306 RVA: 0x000690F8 File Offset: 0x000672F8
public T Current
{
get
{
return this.array[this.index];
}
}
// Token: 0x17000D87 RID: 3463
// (get) Token: 0x06003BCB RID: 15307 RVA: 0x00069120 File Offset: 0x00067320
object IEnumerator.Current
{
get
{
return this.Current;
}
}
// Token: 0x040011F3 RID: 4595
private NativeArray<T> array;
// Token: 0x040011F4 RID: 4596
private int index;
}
}
}