Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mao-test-h
Created September 15, 2019 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mao-test-h/51b4e3f143b10d0dd12a8b1c81721133 to your computer and use it in GitHub Desktop.
Save mao-test-h/51b4e3f143b10d0dd12a8b1c81721133 to your computer and use it in GitHub Desktop.
ポインタをNativeArrayに変換
namespace Unity.Collections.LowLevel.Unsafe
{
public static unsafe class NativeUtility
{
public static NativeArray<T> PtrToNativeArray<T>(T* ptr, int length)
where T : unmanaged
{
var arr = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>(ptr, length, Allocator.Invalid);
// これをやらないとNativeArrayのインデクサアクセス時に死ぬ
#if ENABLE_UNITY_COLLECTIONS_CHECKS
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref arr, AtomicSafetyHandle.Create());
#endif
return arr;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment