init free 2.1.3

This commit is contained in:
2025-08-02 20:11:41 +08:00
commit 24bc0ab149
871 changed files with 312178 additions and 0 deletions
@@ -0,0 +1,37 @@
// Copyright (c) Supernova Technologies LLC
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
namespace Nova.Compat
{
internal unsafe struct RawPtrArrayWrapper<T> : IDisposable where T : unmanaged
{
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
public NativeArray<T> Array;
#if ENABLE_UNITY_COLLECTIONS_CHECKS
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private AtomicSafetyHandle safetyHandle;
#endif
public RawPtrArrayWrapper(T* ptr, int length)
{
Array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>(ptr, length, Allocator.None);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
safetyHandle = AtomicSafetyHandle.Create();
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref Array, safetyHandle);
#endif
}
public void Dispose()
{
#if ENABLE_UNITY_COLLECTIONS_CHECKS
AtomicSafetyHandle.Release(safetyHandle);
#endif
}
public static implicit operator NativeArray<T>(RawPtrArrayWrapper<T> handle) => handle.Array;
}
}