/// <summary>
        /// Copies an array of structs to an array in a blob asset after allocating the necessary memory.
        /// </summary>
        /// <param name="blobArray">A reference to a BlobArray field in a blob asset.</param>
        /// <param name="data">An array  containing structs of type <typeparamref name="T"/>.</param>
        /// <typeparam name="T">The struct data type.</typeparam>
        /// <returns>A reference to the newly constructed array as a mutable BlobBuilderArray instance.</returns>
        public BlobBuilderArray <T> Construct <T>(ref BlobArray <T> blobArray, params T[] data) where T : struct
        {
            var constructBlobArray = Allocate(ref blobArray, data.Length);

            for (int i = 0; i != data.Length; i++)
            {
                constructBlobArray[i] = data[i];
            }
            return(constructBlobArray);
        }
        /// <summary>
        /// Allocates enough memory to store <paramref name="length"/> elements of struct <typeparamref name="T"/>.
        /// </summary>
        /// <param name="ptr">A reference to a BlobArray field in a blob asset.</param>
        /// <param name="length">The number of elements to allocate.</param>
        /// <typeparam name="T">The struct data type.</typeparam>
        /// <returns>A reference to the newly allocated array as a mutable BlobBuilderArray instance.</returns>
        public BlobBuilderArray <T> Allocate <T>(ref BlobArray <T> ptr, int length) where T : struct
        {
            if (length <= 0)
            {
                return(new BlobBuilderArray <T>(null, 0));
            }

            var offsetPtr = (int *)UnsafeUtility.AddressOf(ref ptr.m_OffsetPtr);

            ValidateAllocation(offsetPtr);

            var allocation = Allocate(UnsafeUtility.SizeOf <T>() * length, UnsafeUtility.AlignOf <T>());

            var patch = new OffsetPtrPatch
            {
                offsetPtr = offsetPtr,
                target    = allocation,
                length    = length
            };

            m_patches.Add(patch);
            return(new BlobBuilderArray <T>(AllocationToPointer(allocation), length));
        }
示例#3
0
        public BlobBuilderArray <T> Allocate <T>(int length, ref BlobArray <T> ptr) where T : struct
        {
            if (length <= 0)
            {
                throw new ArgumentException("BlobArray length must be greater than 0");
            }

            var offsetPtr = (int *)UnsafeUtility.AddressOf(ref ptr.m_OffsetPtr);

            ValidateAllocation(offsetPtr, "The BlobArray passed to Allocate was not allocated by this BlobBuilder");

            var allocation = Allocate(UnsafeUtility.SizeOf <T>() * length, UnsafeUtility.AlignOf <T>());

            var patch = new OffsetPtrPatch
            {
                offsetPtr = offsetPtr,
                target    = allocation,
                length    = length
            };

            m_patches.Add(patch);
            return(new BlobBuilderArray <T>(AllocationToPointer(allocation), length));
        }
示例#4
0
 public void Allocate <T>(int length, ref BlobArray <T> ptr) where T : struct
 {
     ptr.m_OffsetPtr = Allocate(UnsafeUtility.SizeOf <T>() * length, UnsafeUtility.AddressOf(ref ptr));
     ptr.m_Length    = length;
 }
示例#5
0
 public BlobBuilderArray <T> Allocate <T>(int length, ref BlobArray <T> ptr) where T : struct
 {
     return(Allocate <T>(ref ptr, length));
 }
示例#6
0
 public BlobBuilderArray <T> Allocate <T>(int length, ref BlobArray <T> ptr) where T : struct => Allocate(ref ptr, length);