using System; using System.Collections; using System.Collections.Generic; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using UnityEngine; namespace SLZ.CustomStaticBatching { public static class CSBNativeArraySpanExt { public unsafe static void Copy(Span src, int srcIndex, NativeArray dst, int dstIndex, int length) where T : unmanaged { fixed (T* pData = &src.GetPinnableReference()) { //AtomicSafetyHandle.CheckWriteAndThrow(dst.m_Safety); UnsafeUtility.MemCpy((byte*)dst.GetUnsafePtr() + dstIndex * UnsafeUtility.SizeOf(), (byte*)(void*)pData + srcIndex * UnsafeUtility.SizeOf(), length * UnsafeUtility.SizeOf()); } } public unsafe static void Copy(ReadOnlySpan src, int srcIndex, NativeArray dst, int dstIndex, int length) where T : unmanaged { fixed (T* pData = &src.GetPinnableReference()) { //AtomicSafetyHandle.CheckWriteAndThrow(dst.m_Safety); UnsafeUtility.MemCpy((byte*)dst.GetUnsafePtr() + dstIndex * UnsafeUtility.SizeOf(), (byte*)(void*)pData + srcIndex * UnsafeUtility.SizeOf(), length * UnsafeUtility.SizeOf()); } } public unsafe static void Copy(NativeArray src, int srcIndex, Span dst, int dstIndex, int length) where T : unmanaged { fixed (T* pData = &dst.GetPinnableReference()) { //AtomicSafetyHandle.CheckWriteAndThrow(dst.m_Safety); UnsafeUtility.MemCpy((byte*)(void*)pData + dstIndex * UnsafeUtility.SizeOf(), (byte*)src.GetUnsafePtr() + srcIndex * UnsafeUtility.SizeOf(), length * UnsafeUtility.SizeOf()); } } } }