Esempio n. 1
0
        private static void GetTreeNodeConfigFromBTreeRoot(BTreeNode _root, ref TreeNodeConfig[] _treeNodeList, ref int _index, int _parentIndex)
        {
            _treeNodeList[_index]               = new TreeNodeConfig();
            _treeNodeList[_index].m_NodeName    = _root.m_Name;
            _treeNodeList[_index].m_ParentIndex = _parentIndex;
            bool _isAction = _root.m_IsAcitonNode;

            if (_isAction)
            {
                _treeNodeList[_index].m_NodeType = (int)NodeType.ActionNode;
            }
            else
            {
                _treeNodeList[_index].m_NodeType = (int)NodeType.SelectorNode;
            }
            _treeNodeList[_index].m_ActionNodeName = _isAction ? _root.GetType().Name : null;
            _treeNodeList[_index].m_NodeSubType    = !_isAction ? (int)(Enum.Parse(typeof(SelectorNodeType), _root.GetType().Name)) : 0;
            _treeNodeList[_index].m_OtherParams    = GetOtherParamsFromBTreeNode(_root, (NodeType)_treeNodeList[_index].m_NodeType, (SelectorNodeType)_treeNodeList[_index].m_NodeSubType);
            if (_root.GetNodePrecondition() != null)
            {
                int _preconditionCount = GetBTreeChildPreconditionNum(_root.GetNodePrecondition()) + 1;
                _treeNodeList[_index].m_Preconditions = new PreconditionConfig[_preconditionCount];
                int index = 0;
                GetPreconditionConfigFromBtreeNode(_root.GetNodePrecondition(), ref _treeNodeList[_index].m_Preconditions, ref index, -1);
            }
            int parentIndex = _index;

            for (int i = 0; i < _root.m_ChildCount; i++)
            {
                _index = _index + 1;
                GetTreeNodeConfigFromBTreeRoot(_root.m_ChildNodeList[i], ref _treeNodeList, ref _index, parentIndex);
            }
        }
Esempio n. 2
0
        private static BTreeNode CreateTreeNode(ref BTreeNode[] _nodes, TreeNodeConfig[] _nodeConfigs, int index)
        {
            TreeNodeConfig _nodeConfig = _nodeConfigs[index];

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

            if (_nodeConfig.m_ParentIndex >= 0)
            {
                parent = _nodes[_nodeConfig.m_ParentIndex];
            }
            NodeType  type  = (NodeType)_nodeConfig.m_NodeType;
            BTreeNode _node = null;

            switch (type)
            {
            case NodeType.SelectorNode:
                SelectorNodeType subType = (SelectorNodeType)_nodeConfig.m_NodeSubType;
                _node = CreateSelectorNode(subType, parent, _nodeConfig.m_NodeName, _nodeConfig.m_OtherParams);
                break;

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

            default:
                break;
            }
            _node.m_Index = index;
            return(_node);
        }
Esempio n. 3
0
 private static BTreeNodePrecondition CreatePreconditionFromConfig(TreeNodeConfig _nodeConfig)
 {
     PreconditionConfig[]    _condConfigs       = _nodeConfig.m_Preconditions;
     BTreeNodePrecondition[] _nodePreconditions = new BTreeNodePrecondition[_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]);
 }