Created
September 15, 2019 11:42
-
-
Save mao-test-h/51b4e3f143b10d0dd12a8b1c81721133 to your computer and use it in GitHub Desktop.
ポインタをNativeArrayに変換
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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