using UnityEngine; using Unity.Entities; using Unity.Collections; using System.Linq; using System; public static class AhoyEntitiesExtensionMethods { public static void ForEach(this NativeArray arr, System.Action action) where T : struct { for (int i = 0; i < arr.Length; i++) { action(arr[i]); } } public static void ForEach(this NativeArray arr, System.Action action) where T : struct { for (int i = 0; i < arr.Length; i++) { action(arr[i], i); } } public static string ElementsToString(this NativeArray arr) where T : struct { return String.Join(",", arr.Select(p => p.ToString()).ToArray()); } public static void ForEach(this NativeList arr, System.Action action) where T : struct { for (int i = 0; i < arr.Length; i++) { action(arr[i], i); } } public static void ForEach(this NativeList arr, System.Action action) where T : struct { for (int i = 0; i < arr.Length; i++) { action(arr[i]); } } // public static string ElementsToString(this NativeList arr) where T : struct // { // // return String.Join(",", arr.Select(p => p.ToString()).ToArray()); // } public static void SafeDispose(this NativeQueue arr) where T : struct { if (arr.IsCreated) arr.Dispose(); } public static void SafeDispose(this NativeList arr) where T : struct { if (arr.IsCreated) arr.Dispose(); } public static NativeList ConvertToNativeList(this NativeQueue arr, Allocator allocator = Allocator.Persistent) where T : struct { NativeList list = new NativeList(allocator); T el; while (arr.TryDequeue(out el)) { list.Add(el); }; // arr.SafeDispose(); arr.Dispose(); return list; } }