public static unsafe void SetManagedObjectType <T>(object source) { void *ptr = UnsafeUtility.PinGCObjectAndGetAddress(source, out ulong gcHandle); MedicineUnsafeUtility.AsRef <ObjectHeader>(ptr) = TypeHeaders <T> .Header; UnsafeUtility.ReleaseGCObject(gcHandle); }
public static unsafe void SetListBackingArray(object InternalList, Array array) { void *ptr = UnsafeUtility.PinGCObjectAndGetAddress(InternalList, out ulong gcHandle); MedicineUnsafeUtility.AsRef <ListHeader>(ptr).Array = array; UnsafeUtility.ReleaseGCObject(gcHandle); }
public static unsafe T[] GetInternalArray <T>(List <T> list) { void *ptr = UnsafeUtility.PinGCObjectAndGetAddress(list, out ulong gcHandle); var array = MedicineUnsafeUtility.AsRef <ListHeader>(ptr).Array; UnsafeUtility.ReleaseGCObject(gcHandle); return(array as T[]); }
public static unsafe void OverwriteArrayLength(Array array, int length) { if (array.Length == length) { return; } void *ptr = UnsafeUtility.PinGCObjectAndGetAddress(array, out ulong gcHandle); MedicineUnsafeUtility.AsRef <ArrayHeader>(ptr).ManagedArrayLength = length; UnsafeUtility.ReleaseGCObject(gcHandle); }
public unsafe void SetType <T>() { var type = typeof(T); if (currentType == typeof(T)) { return; } currentType = type; void *arrayPtr = UnsafeUtility.PinGCObjectAndGetAddress(InternalBackingArray, out ulong arrayGcHandle); void *listPtr = UnsafeUtility.PinGCObjectAndGetAddress(InternalList, out ulong listGcHandle); MedicineUnsafeUtility.AsRef <ObjectHeader>(arrayPtr) = TypeHeaders <T[]> .Header; MedicineUnsafeUtility.AsRef <ObjectHeader>(listPtr) = TypeHeaders <List <T> > .Header; UnsafeUtility.ReleaseGCObject(arrayGcHandle); UnsafeUtility.ReleaseGCObject(listGcHandle); }
public unsafe void EnsureListSyncedWithArray() { var capacity = InternalList.Capacity; // detect if the list's capacity has changed // this indicates that the internal array has been replaced with a new one // (in that case, we want to start using its internal array as the new staticArray) if (capacity == InternalBackingArray.Length) { return; } void *ptr = UnsafeUtility.PinGCObjectAndGetAddress(InternalList, out ulong gcHandle); var array = MedicineUnsafeUtility.AsRef <ListHeader>(ptr).Array; UnsafeUtility.ReleaseGCObject(gcHandle); InternalBackingArray = array; actualCapacity = capacity; }