public static void CopyWithIndex <T, TCopy>(NativeBufferArray <T> fromArr, ref NativeBufferArray <T> arr, TCopy copy) where TCopy : IArrayElementCopyWithIndex <T> where T : struct
        {
            if (fromArr.isCreated == false)
            {
                if (arr.isCreated == true)
                {
                    NativeArrayUtils.RecycleWithIndex(ref arr, copy);
                }
                arr = NativeBufferArray <T> .Empty;
                return;
            }

            if (arr.isCreated == false || fromArr.Length != arr.Length)
            {
                if (arr.isCreated == true)
                {
                    NativeArrayUtils.RecycleWithIndex(ref arr, copy);
                }
                arr = PoolArrayNative <T> .Spawn(fromArr.Length);
            }

            for (int i = 0; i < fromArr.Length; ++i)
            {
                copy.Copy(i, fromArr.arr[i], ref arr.arr.GetRef(i));
            }
        }
Esempio n. 2
0
        public static void CopyWithIndex <T, TCopy>(Unity.Collections.NativeArray <T> fromArr, ref Unity.Collections.NativeArray <T> arr, TCopy copy)
            where TCopy : IArrayElementCopyWithIndex <T> where T : struct
        {
            if (fromArr.IsCreated == false)
            {
                if (arr.IsCreated == true)
                {
                    NativeArrayUtils.RecycleWithIndex(ref arr, copy);
                }
                arr = default;
                return;
            }

            if (arr.IsCreated == false || fromArr.Length != arr.Length)
            {
                if (arr.IsCreated == true)
                {
                    NativeArrayUtils.RecycleWithIndex(ref arr, copy);
                }
                arr = new Unity.Collections.NativeArray <T>(fromArr.Length, Unity.Collections.Allocator.Persistent);
            }

            for (int i = 0; i < fromArr.Length; ++i)
            {
                copy.Copy(i, fromArr[i], ref arr.GetRef(i));
            }
        }