/// <summary> /// Executes the task using the specified context. /// </summary> /// <param name="context">The context.</param> public override void Execute(ICakeContext context) { while (DelayedActions.Count > 0) { var delayedDelegate = DelayedActions.Dequeue(); delayedDelegate(); } var exceptions = new List <Exception>(); foreach (var action in Actions) { try { action(context); } catch (Exception e) when(DeferExceptions) { exceptions.Add(e); } } if (exceptions.Any()) { if (exceptions.Count == 1) { throw exceptions.Single(); } throw new AggregateException("Task failed with following exceptions", exceptions); } }
public async Task InitializeAndPost() { GameCenter.StartTracking(this); driverTimer.Start(); // Make sure to post this status before we handle any cancellations. await PostStatus(driverTimer.Interval); // Delay running the OnRide___Canceled() methods until this method finishes. using (var delay = new DelayedActions()) { // TODO handle request changes properly offer.Changed += OnRideOfferCanceled; delay.Run(() => offer.Canceled.RunWhenFired(OnRideOfferCanceled)); offer.PendingRideMade(this); foreach (UserRideRequest rr in requests) { // TODO handle request changes properly rr.Changed += OnRideRequestCanceled; delay.Run(() => rr.Canceled.RunWhenFired(OnRideRequestCanceled)); rr.PendingRideMade(this); } } }
/// <summary> /// Adds a delayed action to the task. /// This method will be executed the first time the task is executed. /// </summary> /// <param name="action">The action.</param> public void AddDelayedAction(Action action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } DelayedActions.Enqueue(action); }
public void Update(float deltaTime) { if (DelayedActions.Count > 0) { var pairs = DelayedActions.FindAll(x => x.Value <= Game.GameTimeSeconds); foreach (var pair in pairs) { pair.Key(); DelayedActions.Remove(pair); } } }
/// <summary> /// Delay = seconds /// </summary> /// <param name="action"></param> /// <param name="delay"></param> protected void Action(Action action, float delay) { DelayedActions.Add(new KeyValuePair <Action, float>(action, delay)); }
public GameState ExtendDelayedAction(DelayedAction action, int amount) { return(UpdateDelayedAction(DelayedActions.WithID(action.ID).ExtendDuration(amount))); }
public GameState AddDelayedAction(DelayedAction action) { return(WithDelayedActions(DelayedActions.Add(action))); }
public GameState UpdateDelayedAction(DelayedAction delayedEffect) { return(WithDelayedActions(DelayedActions.ReplaceWithID(delayedEffect))); }
private void Start() { Profiler.BeginSample("Array for each"); numbers.ForEach(x => { // x is the array item. }); Profiler.EndSample(); Profiler.BeginSample("List for each"); numberList.ForEach(x => { }); Profiler.EndSample(); Vector2 mousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); Vector2Int tilePosition = mousePosition.ToInt(); string decmialNumbersString = "1234.45"; float result = decmialNumbersString.ParseFloatInvariant(); Vector3 position = transform.position; if (position.IsNaN()) { return; } if (randomFloat == 1f) { } if (randomInt == 3) { } if (randomFloat == testFloat) { } if (randomInt == testInt) { } if (gameObject.layer == layerSelection) { } layerSelection = gameObject.layer; testInt = randomInt; testFloat = randomFloat; Vector3 normalFloatMultiply = Vector3.one * testFloat; Vector3 normalFloatMultiplyInverse = testFloat * Vector3.one; Vector3 randomFloatMultiply = Vector3.one * randomFloat; Vector3 randomFloatMultiplyInverse = randomFloat * Vector3.one; Vector3Int normalIntMultiply = Vector3Int.one * testInt; Vector3Int randomIntMultiply = Vector3Int.one * testInt; if (Input.GetKeyDown(KeyCode.Space)) { SceneManager.LoadScene(gameScene); } Time.timeScale = 0; DelayedActions.ScheduleAction(() => { Debug.Log("No timescale action!"); Time.timeScale = 1; }, 5f, true); DelayedActions.ScheduleAction(() => { Debug.Log("Delayed action after two seconds!"); }, 2); DelayedActions.ScheduleAction(DelayedFunction, 5); }