/// <summary> /// Executes the specified action once. /// </summary> /// <param name="lb">The load balancer.</param> /// <param name="action">The action.</param> /// <param name="delay">The delay until the action is executed.</param> public static void ExecuteOnce(this ILoadBalancer lb, Action action, float delay = 0f) { Ensure.ArgumentNotNull(action, "action"); if (_oneTimeActions == null) { _oneTimeActions = new Queue <RecycledOneTimeAction>(1); } RecycledOneTimeAction ota; if (_oneTimeActions.Count > 0) { ota = _oneTimeActions.Dequeue(); ota.action = action; } else { ota = new RecycledOneTimeAction { action = action }; } if (delay > 0f) { lb.Add(ota, delay, true); } else { lb.Add(ota); } }
public static void ExecuteOnce(this ILoadBalancer lb, Action action, float delay = 0f) { LoadBalancedActionPool.RecycledOneTimeAction recycledOneTimeAction; Ensure.ArgumentNotNull(action, "action"); if (LoadBalancedActionPool._oneTimeActions == null) { LoadBalancedActionPool._oneTimeActions = new Queue <LoadBalancedActionPool.RecycledOneTimeAction>(1); } if (LoadBalancedActionPool._oneTimeActions.Count <= 0) { recycledOneTimeAction = new LoadBalancedActionPool.RecycledOneTimeAction() { action = action }; } else { recycledOneTimeAction = LoadBalancedActionPool._oneTimeActions.Dequeue(); recycledOneTimeAction.action = action; } if (delay <= 0f) { lb.Add(recycledOneTimeAction); return; } lb.Add(recycledOneTimeAction, delay, true); }
/// <summary> /// Executes the specified long running action. /// </summary> /// <param name="lb">The load balancer.</param> /// <param name="longRunningAction">The long running action, i.e. an action that will execute in steps by means of an enumerator.</param> /// <param name="maxMillisecondsUsedPerFrame">The maximum milliseconds to use per frame.</param> /// <returns>>A handle that can be used to Stop, pause and resume the action.</returns> public static ILoadBalancedHandle Execute(this ILoadBalancer lb, IEnumerator longRunningAction, int maxMillisecondsUsedPerFrame) { Ensure.ArgumentNotNull(longRunningAction, "longRunningAction"); if (_longActions == null) { _longActions = new Queue <RecycledLongRunningAction>(1); } RecycledLongRunningAction lra; if (_longActions.Count > 0) { lra = _longActions.Dequeue(); lra.iter = longRunningAction; lra.maxMillisecondsUsedPerFrame = maxMillisecondsUsedPerFrame; } else { lra = new RecycledLongRunningAction { iter = longRunningAction, maxMillisecondsUsedPerFrame = maxMillisecondsUsedPerFrame }; } return(lb.Add(lra)); }
public static ILoadBalancedHandle Execute(this ILoadBalancer lb, IEnumerator longRunningAction, int maxMillisecondsUsedPerFrame) { LoadBalancedActionPool.RecycledLongRunningAction recycledLongRunningAction; Ensure.ArgumentNotNull(longRunningAction, "longRunningAction"); if (LoadBalancedActionPool._longActions == null) { LoadBalancedActionPool._longActions = new Queue <LoadBalancedActionPool.RecycledLongRunningAction>(1); } if (LoadBalancedActionPool._longActions.Count <= 0) { recycledLongRunningAction = new LoadBalancedActionPool.RecycledLongRunningAction() { iter = longRunningAction, maxMillisecondsUsedPerFrame = maxMillisecondsUsedPerFrame }; } else { recycledLongRunningAction = LoadBalancedActionPool._longActions.Dequeue(); recycledLongRunningAction.iter = longRunningAction; recycledLongRunningAction.maxMillisecondsUsedPerFrame = maxMillisecondsUsedPerFrame; } return(lb.Add(recycledLongRunningAction)); }
public static ILoadBalancedHandle Execute(this ILoadBalancer lb, Func <float, bool> action, float interval, float delayFirstUpdateBy) { return(lb.Add(LoadBalancedActionPool.GetAction(action), interval, delayFirstUpdateBy)); }
public static ILoadBalancedHandle Execute(this ILoadBalancer lb, Func <float, bool> action, bool delayFirstUpdate = false) { return(lb.Add(LoadBalancedActionPool.GetAction(action), delayFirstUpdate)); }
/// <summary> /// Executes the specified action as long as it returns <c>true</c>. /// </summary> /// <param name="lb">The load balancer.</param> /// <param name="action">The action.</param> /// <param name="interval">The interval between the action being executed.</param> /// <param name="delayFirstUpdate">if set to <c>true</c> the first execution of the action will be delayed by <paramref name="interval"/>, otherwise it will run on the next frame.</param> /// <returns>A handle that can be used to Stop, pause and resume the action.</returns> public static ILoadBalancedHandle Execute(this ILoadBalancer lb, Func <float, bool> action, float interval, bool delayFirstUpdate = false) { var ota = GetAction(action); return(lb.Add(ota, interval, delayFirstUpdate)); }