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

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

            for (int i = 0; i < fromArr.Length; ++i)
            {
                copy.Copy(fromArr.arr[i], ref arr.arr.GetRef(i));
            }
        }
Пример #2
0
        public static void Copy <T, TCopy>(NativeArrayBurst <T> fromArr, ref NativeArrayBurst <T> arr, TCopy copy)
            where TCopy : IArrayElementCopy <T> where T : struct
        {
            if (fromArr.IsCreated == false)
            {
                if (arr.IsCreated == true)
                {
                    NativeArrayUtils.Recycle(ref arr, copy);
                }
                arr = default;
                return;
            }

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

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