Пример #1
0
        private void ShowAdd()
        {
            DynamicBuffer <int> buffer       = new DynamicBuffer <int>();
            DynamicBuffer <int> secondBuffer = new DynamicBuffer <int>();

            #region dynamicbuffer.add

            buffer.Add(5);

            #endregion

            #region dynamicbuffer.addrange

            int[]             source      = { 1, 2, 3, 4, 5 };
            NativeArray <int> newElements = new NativeArray <int>(source, Allocator.Persistent);
            buffer.AddRange(newElements);

            #endregion

            #region dynamicbuffer.asnativearray

            int[] intArray = { 1, 2, 3, 4, 5 };
            NativeArray <int> .Copy(intArray, buffer.AsNativeArray());

            #endregion

            #region dynamicbuffer.capacity

            #endregion

            #region dynamicbuffer.clear

            buffer.Clear();

            #endregion

            #region dynamicbuffer.copyfrom.dynamicbuffer

            buffer.CopyFrom(secondBuffer);

            #endregion

            #region dynamicbuffer.copyfrom.nativearray

            int[]             sourceArray = { 1, 2, 3, 4, 5 };
            NativeArray <int> nativeArray = new NativeArray <int>(source, Allocator.Persistent);
            buffer.CopyFrom(nativeArray);

            #endregion

            #region dynamicbuffer.copyfrom.array

            int[] integerArray = { 1, 2, 3, 4, 5 };
            buffer.CopyFrom(integerArray);

            #endregion

            #region dynamicbuffer.getenumerator

            foreach (var element in buffer)
            {
                //Use element...
            }

            #endregion

            #region dynamicbuffer.getunsafeptr

            #endregion

            int insertionIndex = 2;

            #region dynamicbuffer.insert

            if (insertionIndex < buffer.Length)
            {
                buffer.Insert(insertionIndex, 6);
            }

            #endregion

            #region dynamicbuffer.iscreated

            #endregion

            #region dynamicbuffer.length

            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = i * i;
            }

            #endregion

            #region dynamicbuffer.removeat

            if (insertionIndex < buffer.Length)
            {
                buffer.RemoveAt(insertionIndex);
            }

            #endregion

            int start = 1;

            #region dynamicbuffer.removerange

            buffer.RemoveRange(start, 5);

            #endregion

            #region dynamicbuffer.reserve

            buffer.Reserve(buffer.Capacity + 10);

            #endregion

            #region dynamicbuffer.resizeuninitialized

            buffer.ResizeUninitialized(buffer.Length + 10);

            #endregion

            #region dynamicbuffer.indexoperator

            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = i * i;
            }

            #endregion

            #region dynamicbuffer.tonativearray

            NativeArray <int> copy = buffer.ToNativeArray(Allocator.Persistent);

            #endregion

            #region dynamicbuffer.trimexcess

            if (buffer.Capacity > buffer.Length)
            {
                buffer.TrimExcess();
            }

            #endregion
        }