示例#1
0
        bool IsSubGraphRunning(FiniteStateMachineSubGraphNode subGraphNode, FiniteStateMachineGraph behaviourGraph, FiniteStateMachineRuntimeState state, List <int> checkedSubgraphs)
        {
            checkedSubgraphs.Add(subGraphNode.GetInstanceID());
            var subGraph = subGraphNode.SubGraph;

            foreach (var node in subGraph.nodes)
            {
                var running = false;
                // If node is another subgraph execute recursively but prevent infinite cycles.
                if (node is FiniteStateMachineSubGraphNode && checkedSubgraphs.Contains(node.GetInstanceID()) == false)
                {
                    running = IsSubGraphRunning(node as FiniteStateMachineSubGraphNode, behaviourGraph, state, checkedSubgraphs);
                }
                else if (node is FiniteStateMachineStateGraphNode)
                {
                    running = IsStateRunning(node as FiniteStateMachineStateGraphNode, behaviourGraph, state);
                }

                if (running)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        bool IsStateRunning(FiniteStateMachineStateGraphNode stateNode, FiniteStateMachineGraph behaviourGraph, FiniteStateMachineRuntimeState state)
        {
            if (behaviourGraph.TryGetNodeIndex(stateNode.GetInstanceID(), out var nodeIndex))
            {
                if (state.CurrentState == nodeIndex)
                {
                    return(true);
                }
            }

            return(false);
        }