示例#1
0
    private BTNode LoadBTNode(XmlNode currentNode, AI owner, MacroAIParty party)
    {
        XmlNodeList nodeContent = currentNode.ChildNodes;

        XmlAttributeCollection nodeAttributes = currentNode.Attributes;
        BTNode node = null;

        if (currentNode.Name == "behavior")
        {
            node = LoadBTNode(nodeContent[0], owner, party);
        }
        else if (currentNode.Name == "composite")
        {
            BTComposite compNode = null;
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "Sequence")
            {
                BTSequence seqNode = new BTSequence();
                seqNode.CompNodeType = BTCompType.Sequence;
                compNode             = seqNode;
            }
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "Selector")
            {
                BTSelector selNode = new BTSelector();
                selNode.CompNodeType = BTCompType.Selector;
                compNode             = selNode;
            }
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "ParallelAnd")
            {
                BTParallelAnd parNode = new BTParallelAnd();
                parNode.CompNodeType = BTCompType.ParallelAnd;
                compNode             = parNode;
            }
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "ParallelMain")
            {
                BTParallelMain parNode = new BTParallelMain();
                parNode.CompNodeType = BTCompType.ParallelMain;
                compNode             = parNode;
            }
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "Random")
            {
                BTRandom randNode = new BTRandom();
                randNode.CompNodeType = BTCompType.Random;
                compNode = randNode;
            }
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "Switch")
            {
                BTSwitch swNode = new BTSwitch();
                swNode.CompNodeType = BTCompType.Switch;
                compNode            = swNode;
            }

            compNode.Children = new List <BTNode>();

            foreach (XmlNode nodeItem in nodeContent)
            {
                compNode.Children.Add(LoadBTNode(nodeItem, owner, party));
            }

            node = compNode;
        }
        else if (currentNode.Name == "decorator")
        {
            BTDecorator decNode = null;
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "Repeat")
            {
                BTRepeat repNode = new BTRepeat();
                decNode = repNode;
            }
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "Invert")
            {
                BTInvert invNode = new BTInvert();
                decNode = invNode;
            }
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "UntilFail")
            {
                BTUntilFail repNode = new BTUntilFail();
                decNode = repNode;
            }
            foreach (XmlNode nodeItem in nodeContent)
            {
                decNode.Child = LoadBTNode(nodeItem, owner, party);
            }

            node = decNode;
        }
        else if (currentNode.Name == "leaf")
        {
            XmlNodeList   parameterList = currentNode.ChildNodes;
            List <string> parameters    = new List <string>();
            foreach (XmlNode paramNode in parameterList)
            {
                parameters.Add(paramNode.InnerText);
            }

            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "Check")
            {
                if (nodeAttributes["name"] != null)
                {
                    string  actionName = nodeAttributes["name"].Value;
                    BTCheck checkNode  = new BTCheck();
                    checkNode.Action     = actionName;
                    checkNode.Parameters = parameters;
                    checkNode.MyAI       = owner;
                    checkNode.MyParty    = party;
                    node = checkNode;
                }
            }
            if (nodeAttributes["type"] != null && nodeAttributes["type"].Value == "Action")
            {
                if (nodeAttributes["name"] != null)
                {
                    BTLeaf leafNode = (BTLeaf)System.Activator.CreateInstance(System.Type.GetType("BT" + nodeAttributes["name"].Value));
                    leafNode.Parameters = parameters;
                    leafNode.MyAI       = owner;
                    leafNode.MyParty    = party;
                    node = leafNode;
                }
            }
        }

        return(node);
    }
示例#2
0
        void DrawLeaf(BTLeaf leaf)
        {
            EditorData nodeData = _editorData[leaf.id];

            CreateNodeWindow(nodeData, _nodeWidth, _leafHeight);
        }
示例#3
0
		void DrawLeaf( BTLeaf leaf )
		{
			EditorData nodeData = _editorData[leaf.id];
			CreateNodeWindow( nodeData, _nodeWidth, _leafHeight );
		}