コード例 #1
0
    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;
        }
    }
コード例 #2
0
    /// <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);
    }