public void Update() { var currentAction = GetCurrentOrNextAction(); ActionCurrentlyBeingPerformed = currentAction; if (!ActionCurrentlyBeingPerformed.IsStarted) { ActionCurrentlyBeingPerformed.IsStarted = true; try { currentActionStartedAtThisTime = DateTime.Now; ActionCurrentlyBeingPerformed.onStart(); } catch (Exception e) { Debug.LogError(e.Message + " [stack trace] " + ActionCurrentlyBeingPerformed?.stackTrace?.ToString()); IsCurrentActionFinished = true; } } if (ActionCurrentlyBeingPerformed.IsFinished()) { if (!ActionCurrentlyBeingPerformed.Parent.ChildActionsQueue.IsEmpty()) // check performed solely for sake of Master Action { ActionCurrentlyBeingPerformed.Parent.ChildActionsQueue.PopFirstElement(); // remove the action to get a new current action. Console.Out.Write("Finished action on queue!"); } IsCurrentActionFinished = false; // the current action isn't started yet; resetting this flag so that we can use it in the next action. } else if (currentActionStartedAtThisTime + ActionCurrentlyBeingPerformed.Timeout > DateTime.Now && ActionCurrentlyBeingPerformed.IsTimeoutRelevant) { Log.Error("Action timed out!: " + ActionCurrentlyBeingPerformed.ActionId); IsCurrentActionFinished = true; } }
private static void PushActionOntoRelevantQueue(BasicDelayedAction action, QueueingType queueingType) { var parentAction = ActionManager.Instance.ActionCurrentlyBeingPerformed; if (queueingType == QueueingType.TO_BACK) { parentAction.ChildActionsQueue.Add(action); } else { parentAction.ChildActionsQueue.AddToFront(action); } }
public BasicDelayedAction(Action onStart, BasicDelayedAction parent, string name = "") { stackTrace = new StackTrace(); ActionId = name; this.onStart = onStart; if (parent != null) { Parent = parent; if (!parent.ChildActionsQueue.Contains(this)) { parent.ChildActionsQueue.Add(this); } } }
/// <summary> /// depth-first search on action manager /// </summary> private BasicDelayedAction GetNextActionToMonitorOrPerform(BasicDelayedAction parent) { if (parent.ChildActionsQueue.IsEmpty()) { return(parent); } if (!parent.IsFinished()) // we want to finish with the parent BEFORE we finish with the child { return(parent); } var nextActionInFirstChild = GetNextActionToMonitorOrPerform(parent.ChildActionsQueue.First()); return(nextActionInFirstChild); }
public void AddToBack(BasicDelayedAction action) { QueuedActions.DelayedActionWithCustomTrigger(action.ActionId, action.onStart, queueingType: QueueingType.TO_BACK); }
public void AddToFront(BasicDelayedAction action) { QueuedActions.DelayedActionWithCustomTrigger(action.ActionId, action.onStart, queueingType: QueueingType.TO_FRONT); }
public DelayedActionWithFinishTrigger(string name, Action toPerform, BasicDelayedAction parent, Func <bool> isFinished) : base(toPerform, parent) { onStart = toPerform; ActionId = name; IsFinishedFunction = isFinished; }
public ImmediateAction(Action onStart, BasicDelayedAction parent, string name = "") : base(onStart, parent, name) { }