public LongRunningAction ChangeLevelToVolume(string levelName, int toVolume, bool asDoor, bool spin, bool trialEnding) { this.LevelManager.DestinationVolumeId = new int?(toVolume); LongRunningAction lra = this.ChangeLevel(levelName, asDoor, spin, trialEnding); return(new LongRunningAction((Action)(() => { if (lra.OnDispose != null) { lra.OnDispose(); } if (ActionTypeExtensions.IsEnteringDoor(this.PlayerManager.Action)) { return; } this.LevelManager.DestinationVolumeId = new int?(); }))); }
private void Update() { if (Input.GetKeyUp(KeyCode.Alpha1)) { //So here we create a long running action which will complete the DoWork call but only use 3 ms per frame, hence spreading it out across numerous frames. var action = new LongRunningAction(DoWork, 3); //We schedule it to run each frame if possible _handle = ExamplesLoadBalancer.extraBalancer.Add(action, 0f); } else if (Input.GetKeyUp(KeyCode.Alpha2)) { //Here we stop the action initiated in 3 above if (_handle != null) { _handle.Stop(); } } }
private void StartAction(RunnableAction runnableAction) { LongRunningAction runningAction = runnableAction.Invocation() as LongRunningAction; runnableAction.Invocation = (Func <object>)null; if (runningAction == null) { return; } runningAction.Ended += (Action)(() => { this.runningActions.Remove(runningAction); if (!runnableAction.Action.Killswitch) { return; } this.Dispose(); }); this.runningActions.Add(runningAction); }
public LongRunningAction ChangeToFarAwayLevel(string levelName, int toVolume, bool trialEnding) { this.LevelManager.DestinationIsFarAway = true; this.LevelManager.DestinationVolumeId = new int?(toVolume); LongRunningAction lra = this.ChangeLevel(levelName, true, false, trialEnding); return(new LongRunningAction((Action)(() => { if (lra.OnDispose != null) { lra.OnDispose(); } this.LevelManager.DestinationIsFarAway = false; if (ActionTypeExtensions.IsEnteringDoor(this.PlayerManager.Action)) { return; } this.LevelManager.DestinationVolumeId = new int?(); }))); }
/// <summary> /// Posts the message as a <see cref="Apex.LoadBalancing.LongRunningAction" />. Use this if you experience message processing to affect the frame rate. /// </summary> /// <typeparam name="T">The type of message</typeparam> /// <param name="message">The message.</param> /// <param name="maxMillisecondUsedPerFrame">The maximum milliseconds used per frame for subscribers processing the message.</param> /// <param name="callback">A callback which will be invoked once the message has been sent and processed by all subscribers.</param> public void PostBalanced <T>(T message, int maxMillisecondUsedPerFrame, Action callback) { IList <object> subscribers; if (!_subscriptions.TryGetValue(typeof(T), out subscribers)) { if (callback != null) { callback(); } return; } var task = new LongRunningAction( () => BalancedPoster(subscribers, message), maxMillisecondUsedPerFrame, callback); LoadBalancer.defaultBalancer.Add(task, 0f); }