public static void DoTimes(System.Func <int> times, System.Func <int, int> action, bool forwardOrder = true)
 {
     if (!times.IsNull() && !action.IsNull())
     {
         var start  = forwardOrder ? 0 : (times.Invoke() - 1);
         var offset = forwardOrder ? 1 : -1;
         for (var i = start; (i >= 0) && (i < times.Invoke()); i += offset)
         {
             i = action.Invoke(i);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Perform an action on all the aliases that were found for a keycode
        /// </summary>
        /// <param name="keyCode">The KeyCode to look for aliases of</param>
        /// <param name="loopFunction">The Func that will be run on all aliases</param>
        /// <param name="performOnOriginal">Whether the loopFunction will be invoked on the original KeyCode</param>
        public static void PerformOnAliases(KeyCode keyCode, System.Func <KeyCode, bool> loopFunction, bool performOnOriginal = true)
        {
            bool _validAliasFound = false;

            if (loopFunction.IsNull())
            {
                return;
            }
            if (performOnOriginal)
            {
                _validAliasFound = loopFunction.Invoke(keyCode);
            }

            if (s_instance.IsNull())
            {
                if (s_warningMessageSent == false)
                {
                    Debug.LogWarning("No KeyCodeAliasManager is currently set up!");
                    s_warningMessageSent = true;
                }
                return;
            }

            if (s_instance.m_aliases.DoesNotContainKey(keyCode))
            {
                return;
            }

            foreach (KeyCode _alias in s_instance.m_aliases[keyCode])
            {
                if (_validAliasFound)
                {
                    return;
                }

                _validAliasFound = loopFunction.Invoke(_alias);
            }
        }
 public static TResult SafeInvoke <T1, T2, T3, T4, TResult>(this System.Func <T1, T2, T3, T4, TResult> h, T1 arg1, T2 arg2, T3 arg3, T4 arg4, TResult defaultValue)
 {
     return(!h.IsNull() ? h.Invoke(arg1, arg2, arg3, arg4) : defaultValue);
 }
 public static TResult SafeInvoke <T, TResult>(this System.Func <T, TResult> h, T arg, TResult defaultValue)
 {
     return(!h.IsNull() ? h.Invoke(arg) : defaultValue);
 }