示例#1
0
        private static void processTick(string msg)
        {
            // [tick]Ship::Ship_1 ships\basic.xml->BehaviorTree[0]:enter [all/success/failure] [1]
            // [tick]Ship::Ship_1 ships\basic.xml->BehaviorTree[0]:update [1]

            string[] tokens = msg.Substring(6).Split(' ');

            if (tokens.Length == 4)
            {
                string[] types = tokens[0].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                Debug.Check(types.Length == 2);
                string agentType     = types[0];
                string agentName     = types[1];
                string agentFullname = tokens[0];

                AgentInstancePool.AddInstance(agentType, agentName, true);

                string[] nodes = tokens[1].Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries);

                if (nodes.Length == 2)
                {
                    string behaviorFilename = nodes[0];

                    checkBehaviorFiles(behaviorFilename);
                    FrameStatePool.SetJumpInfo(agentFullname, behaviorFilename, true);

                    behaviorFilename = FrameStatePool.GetCurrentBehaviorTree(agentFullname, behaviorFilename);

                    string[] actions = nodes[1].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);

                    if (actions.Length == 3)
                    {
                        string[] actionResults = tokens[2].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] hitCounts     = tokens[3].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        int      hitCount      = int.Parse(hitCounts[0]);
                        string   nodeId        = actions[1];

                        if (actions[2] == ":enter")
                        {
                            FrameStatePool.EnterNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0], hitCount);
                        }
                        else if (actions[2] == ":exit")
                        {
                            FrameStatePool.ExitNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0], hitCount);
                        }
                        else if (actions[2] == ":update")
                        {
                            List <string> highlightNodeIds = FrameStatePool.GetHighlightNodeIds(agentFullname, AgentDataPool.TotalFrames, behaviorFilename);

                            if (highlightNodeIds != null && !highlightNodeIds.Contains(nodeId))
                            {
                                FrameStatePool.EnterNode(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0], hitCount);
                            }
                        }
                        else if (actions[2] == ":transition")
                        {
                            FrameStatePool.UpdateTransition(agentFullname, AgentDataPool.TotalFrames, behaviorFilename, nodeId, actionResults[0]);
                        }
                    }
                }
            }
        }