Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

NativeNotBurstCompatible.cs 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //#define USE_NOT_BURST_COMPATIBLE_EXTENSIONS
  2. using System;
  3. using Unity.Collections.LowLevel.Unsafe;
  4. namespace Unity.Collections.NotBurstCompatible
  5. {
  6. /// <summary>
  7. /// Provides some extension methods for various collections.
  8. /// </summary>
  9. public static class Extensions
  10. {
  11. /// <summary>
  12. /// Returns a new managed array with all the elements copied from a set.
  13. /// </summary>
  14. /// <typeparam name="T">The type of elements.</typeparam>
  15. /// <param name="set">The set whose elements are copied to the array.</param>
  16. /// <returns>A new managed array with all the elements copied from a set.</returns>
  17. [ExcludeFromBurstCompatTesting("Returns managed array")]
  18. public static T[] ToArray<T>(this NativeHashSet<T> set)
  19. where T : unmanaged, IEquatable<T>
  20. {
  21. var array = set.ToNativeArray(Allocator.TempJob);
  22. var managed = array.ToArray();
  23. array.Dispose();
  24. return managed;
  25. }
  26. /// <summary>
  27. /// Returns a new managed array with all the elements copied from a set.
  28. /// </summary>
  29. /// <typeparam name="T">The type of elements.</typeparam>
  30. /// <param name="set">The set whose elements are copied to the array.</param>
  31. /// <returns>A new managed array with all the elements copied from a set.</returns>
  32. [ExcludeFromBurstCompatTesting("Returns managed array")]
  33. public static T[] ToArray<T>(this NativeParallelHashSet<T> set)
  34. where T : unmanaged, IEquatable<T>
  35. {
  36. var array = set.ToNativeArray(Allocator.TempJob);
  37. var managed = array.ToArray();
  38. array.Dispose();
  39. return managed;
  40. }
  41. /// <summary>
  42. /// Returns a new managed array which is a copy of this list.
  43. /// </summary>
  44. /// <typeparam name="T">The type of elements.</typeparam>
  45. /// <param name="list">The list to copy.</param>
  46. /// <returns>A new managed array which is a copy of this list.</returns>
  47. [ExcludeFromBurstCompatTesting("Returns managed array")]
  48. public static T[] ToArrayNBC<T>(this NativeList<T> list)
  49. where T : unmanaged
  50. {
  51. return list.AsArray().ToArray();
  52. }
  53. /// <summary>
  54. /// Clears this list and then copies all the elements of an array to this list.
  55. /// </summary>
  56. /// <typeparam name="T">The type of elements.</typeparam>
  57. /// <param name="list">This list.</param>
  58. /// <param name="array">The managed array to copy from.</param>
  59. [ExcludeFromBurstCompatTesting("Takes managed array")]
  60. public static void CopyFromNBC<T>(this NativeList<T> list, T[] array)
  61. where T : unmanaged
  62. {
  63. list.Clear();
  64. list.Resize(array.Length, NativeArrayOptions.UninitializedMemory);
  65. NativeArray<T> na = list.AsArray();
  66. na.CopyFrom(array);
  67. }
  68. }
  69. }