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));
            }
        }
Esempio n. 3
0
        public static NativeBufferArray <T> Spawn(int length, bool realSize = false, Unity.Collections.Allocator allocator = Unity.Collections.Allocator.Persistent)
        {
            var arrSize = PoolArray <T> .GetSize(length);

            var arr    = new Unity.Collections.NativeArray <T>(arrSize, allocator);
            var size   = (realSize == true ? arr.Length : length);
            var buffer = new NativeBufferArray <T>(arr, length, realSize == true ? arr.Length : -1);

            NativeArrayUtils.Clear(buffer, 0, size);

            return(buffer);
        }
Esempio n. 4
0
        public UnsafeData Set <T>(T data) where T : struct
        {
            this.typeId = AllComponentTypes <T> .typeId;

            if (this.data != System.IntPtr.Zero)
            {
                NativeArrayUtils.Dispose(ref this.data);
            }

            this.sizeOf  = UnsafeUtility.SizeOf <T>();
            this.alignOf = UnsafeUtility.AlignOf <T>();
            this.data    = (System.IntPtr)UnsafeUtility.Malloc(this.sizeOf, this.alignOf, Unity.Collections.Allocator.Persistent);
            Unity.Collections.LowLevel.Unsafe.UnsafeUtility.WriteArrayElement((void *)this.data, 0, data);

            return(this);
        }
Esempio n. 5
0
 public void Validate(int capacity)
 {
     NativeArrayUtils.Resize(capacity, ref this.types);
     NativeArrayUtils.Resize(capacity, ref this.prevTypes);
 }