Exemplo n.º 1
0
        private static void GetTreeNodeConfigFromBTreeRoot(BTNode _root, ref TreeNodeConfig[] _treeNodeList, ref int _index, int _parentIndex)
        {
            _treeNodeList[_index]              = new TreeNodeConfig();
            _treeNodeList[_index].mNodeName    = _root.name;
            _treeNodeList[_index].mParentIndex = _parentIndex;
            bool _isAction = _root.GetType().IsSubclassOf(typeof(BTAction));

            if (_isAction)
            {
                _treeNodeList[_index].mNodeType = (int)NodeType.ActionNode;
            }
            else
            {
                _treeNodeList[_index].mNodeType = (int)NodeType.SelectorNode;
            }
            _treeNodeList[_index].mActionNodeName = _isAction ? _root.GetType().Name : null;
            _treeNodeList[_index].mNodeSubType    = !_isAction ? (int)(Enum.Parse(typeof(SelectorNodeType), _root.GetType().Name)) : 0;
            _treeNodeList[_index].mOtherParams    = GetOtherParamsFromBTreeNode(_root, (NodeType)_treeNodeList[_index].mNodeType, (SelectorNodeType)_treeNodeList[_index].mNodeSubType);
            if (_root.precondition != null)
            {
                int _preconditionCount = GetBTreeChildPreconditionNum(_root.precondition) + 1;
                _treeNodeList[_index].mPreconditions = new PreconditionConfig[_preconditionCount];
                int index = 0;
                GetPreconditionConfigFromBtreeNode(_root.precondition, ref _treeNodeList[_index].mPreconditions, ref index, -1);
            }
            int parentIndex = _index;

            for (int i = 0; i < _root.childCount; i++)
            {
                _index = _index + 1;
                GetTreeNodeConfigFromBTreeRoot(_root.children[i], ref _treeNodeList, ref _index, parentIndex);
            }
        }
Exemplo n.º 2
0
        private static BTNode CreateTreeNode(ref BTNode[] _nodes, TreeNodeConfig[] _nodeConfigs, int index)
        {
            TreeNodeConfig _nodeConfig = _nodeConfigs[index];

            if (_nodeConfig.mParentIndex >= 0 && _nodes[_nodeConfig.mParentIndex] == null)
            {
                _nodes[_nodeConfig.mParentIndex] = CreateTreeNode(ref _nodes, _nodeConfigs, _nodeConfig.mParentIndex);
            }
            BTNode parent = null;

            if (_nodeConfig.mParentIndex >= 0)
            {
                parent = _nodes[_nodeConfig.mParentIndex];
            }
            NodeType type  = (NodeType)_nodeConfig.mNodeType;
            BTNode   _node = null;

            switch (type)
            {
            case NodeType.SelectorNode:
                SelectorNodeType subType = (SelectorNodeType)_nodeConfig.mNodeSubType;
                _node = CreateSelectorNode(subType, parent, _nodeConfig.mNodeName, _nodeConfig.mOtherParams);
                break;

            case NodeType.ActionNode:
                _node = CreateActionNode(parent, _nodeConfig.mNodeName, ActionTypeDic[_nodeConfig.mActionNodeName]);
                break;

            default:
                break;
            }
            _node.index = index;
            return(_node);
        }
Exemplo n.º 3
0
 private static BTPrecondition CreatePreconditionFromConfig(TreeNodeConfig _nodeConfig)
 {
     PreconditionConfig[] _condConfigs       = _nodeConfig.mPreconditions;
     BTPrecondition[]     _nodePreconditions = new BTPrecondition[_condConfigs.Length];
     for (int i = 0; i < _nodePreconditions.Length; i++)
     {
         _nodePreconditions[i] = null;
     }
     for (int i = 0; i < _nodePreconditions.Length; i++)
     {
         if (_nodePreconditions[i] == null)
         {
             _nodePreconditions[i] = CreatePrecondition(ref _nodePreconditions, _condConfigs, i);
         }
     }
     return(_nodePreconditions[0]);
 }