Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
748B

  1. #if UNITY_COLLECTIONS
  2. using Unity.Collections;
  3. using Unity.Collections.LowLevel.Unsafe;
  4. namespace Svelto.ECS.DataStructures
  5. {
  6. public static class NativeDynamicArrayUnityExtension
  7. {
  8. public static NativeArray<T> ToNativeArray<T>(this NativeDynamicArray array) where T : struct
  9. {
  10. unsafe
  11. {
  12. var nativeArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<T>(
  13. (void*) array.ToIntPTR<T>(), (int) array.Count<T>(), Allocator.None);
  14. #if ENABLE_UNITY_COLLECTIONS_CHECKS
  15. NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref nativeArray, AtomicSafetyHandle.Create());
  16. #endif
  17. return nativeArray;
  18. }
  19. }
  20. }
  21. }
  22. #endif