Esempio n. 1
0
        public static void InvokeCallbacksSafe <TValue1, TValue2>(ref InlinedArray <Action <TValue1, TValue2> > callbacks, TValue1 argument1, TValue2 argument2, string callbackName)
        {
            Profiler.BeginSample(callbackName);
            for (var i = 0; i < callbacks.length; ++i)
            {
                var lengthBefore = callbacks.length;

                try
                {
                    callbacks[i](argument1, argument2);
                }
                catch (Exception exception)
                {
                    Debug.LogError($"{exception.GetType().Name} while executing '{callbackName}' callbacks");
                    Debug.LogException(exception);
                }

                ////REVIEW: is this enough?
                if (callbacks.length == lengthBefore - 1)
                {
                    --i;
                }
            }
            Profiler.EndSample();
        }
Esempio n. 2
0
        public static void InvokeCallbacksSafe <TValue>(ref InlinedArray <Action <TValue> > callbacks, TValue argument, string callbackName, object context = null)
        {
            Profiler.BeginSample(callbackName);
            for (var i = 0; i < callbacks.length; ++i)
            {
                var lengthBefore = callbacks.length;

                try
                {
                    callbacks[i](argument);
                }
                catch (Exception exception)
                {
                    if (context != null)
                    {
                        Debug.LogError($"{exception.GetType().Name} while executing '{callbackName}' callbacks of '{context}'");
                    }
                    else
                    {
                        Debug.LogError($"{exception.GetType().Name} while executing '{callbackName}' callbacks");
                    }
                    Debug.LogException(exception);
                }

                ////REVIEW: is this enough?
                if (callbacks.length == lengthBefore - 1)
                {
                    --i;
                }
            }
            Profiler.EndSample();
        }
Esempio n. 3
0
 public static bool Contains <TValue>(this InlinedArray <TValue> array, TValue value)
 {
     for (var i = 0; i < array.length; ++i)
     {
         if (array[i].Equals(value))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 4
0
        public static int IndexOfReference <TValue>(this InlinedArray <TValue> array, TValue value)
            where TValue : class
        {
            for (var i = 0; i < array.length; ++i)
            {
                if (ReferenceEquals(array[i], value))
                {
                    return(i);
                }
            }

            return(-1);
        }
Esempio n. 5
0
        public void Merge(InlinedArray <TValue> other)
        {
            var comparer = EqualityComparer <TValue> .Default;

            for (var i = 0; i < other.length; ++i)
            {
                var value = other[i];
                if (Contains(value, comparer))
                {
                    continue;
                }

                ////FIXME: this is ugly as it repeatedly copies
                Append(value);
            }
        }
Esempio n. 6
0
        public void AssignWithCapacity(InlinedArray <TValue> values)
        {
            if (Capacity < values.length && values.length > 1)
            {
                additionalValues = new TValue[values.length - 1];
            }

            length = values.length;
            if (length > 0)
            {
                firstValue = values.firstValue;
            }
            if (length > 1)
            {
                Array.Copy(values.additionalValues, additionalValues, length - 1);
            }
        }
        public static bool InvokeCallbacksSafe_AnyCallbackReturnsTrue <TValue1, TValue2>(ref InlinedArray <Func <TValue1, TValue2, bool> > callbacks,
                                                                                         TValue1 argument1, TValue2 argument2, string callbackName, object context = null)
        {
            if (callbacks.length == 0)
            {
                return(true);
            }
            Profiler.BeginSample(callbackName);
            for (var i = 0; i < callbacks.length; ++i)
            {
                var lengthBefore = callbacks.length;

                try
                {
                    if (callbacks[i](argument1, argument2))
                    {
                        return(true);
                    }
                }
                catch (Exception exception)
                {
                    if (context != null)
                    {
                        Debug.LogError($"{exception.GetType().Name} while executing '{callbackName}' callbacks of '{context}'");
                    }
                    else
                    {
                        Debug.LogError($"{exception.GetType().Name} while executing '{callbackName}' callbacks");
                    }
                    Debug.LogException(exception);
                }

                ////REVIEW: is this enough?
                if (callbacks.length == lengthBefore - 1)
                {
                    --i;
                }
            }
            Profiler.EndSample();
            return(false);
        }
Esempio n. 8
0
 public static bool ContainsReference <TValue>(this InlinedArray <TValue> array, TValue value)
     where TValue : class
 {
     return(IndexOfReference(array, value) != -1);
 }