Beispiel #1
0
        public static bool RemoveFirst <T>(this DynamicBuffer <T> buffer, Predicate <T> predicate) where T : struct, IBufferElementData
        {
            var indexOfExistingElement = buffer.IndexOf(predicate);

            if (indexOfExistingElement >= 0)
            {
                buffer.RemoveAt(indexOfExistingElement);
            }

            return(indexOfExistingElement >= 0);
        }
        public static bool ReplaceFirst <T>(this DynamicBuffer <T> buffer, Predicate <T> predicate, T replaceWith) where T : struct, IBufferElementData
        {
            var indexOfExistingElement = buffer.IndexOf(predicate);

            if (indexOfExistingElement >= 0)
            {
                buffer[indexOfExistingElement] = replaceWith;
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public static void AddOrReplace <T>(this DynamicBuffer <T> buffer, T element, Predicate <T> predicate) where T : struct, IBufferElementData
        {
            var indexOfExistingElement = buffer.IndexOf(predicate);

            if (indexOfExistingElement >= 0)
            {
                buffer[indexOfExistingElement] = element;
            }
            else
            {
                buffer.Add(element);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Remove an element from a <see cref="DynamicBuffer{T}"/>.
        /// </summary>
        /// <typeparam name="T">The type of NativeList</typeparam>
        /// <typeparam name="TI">The type of element.</typeparam>
        /// <param name="buffer">The DynamicBuffer.</param>
        /// <param name="element">The element.</param>
        /// <returns>True if removed, else false.</returns>
        public static bool Remove <T, TI>(this DynamicBuffer <T> buffer, TI element)
            where T : struct, IEquatable <TI>
            where TI : struct
        {
            var index = buffer.IndexOf(element);

            if (index < 0)
            {
                return(false);
            }

            buffer.RemoveAt(index);
            return(true);
        }
Beispiel #5
0
 public static bool Contains <T, TI>(this DynamicBuffer <T> buffer, TI item)
     where T : struct, IEquatable <TI>
     where TI : struct
 {
     return(buffer.IndexOf(item) >= 0);
 }
 public static bool Contains <T>(this DynamicBuffer <T> buffer, Predicate <T> predicate) where T : struct, IBufferElementData
 {
     return(buffer.IndexOf(predicate) != -1);
 }