Exemplo n.º 1
0
        private static void GetPreconditionConfigFromBtreeNode(BTPrecondition _precondition, ref PreconditionConfig[] _preconditionList, ref int _index, int _parentIndex = -1)
        {
            _preconditionList[_index] = new PreconditionConfig();
            _preconditionList[_index].mParentIndex = _parentIndex;
            Type type = _precondition.GetType();

            _preconditionList[_index].mPreconditionName = type.Name.Split('`')[0];
            if (type.Equals(typeof(BTPreconditionAND)))
            {
                _preconditionList[_index].mType = (int)PreconditionType.And;
                BTPrecondition[] _childPreconditon = ((BTPreconditionAND)_precondition).GetChildPrecondition();
                _preconditionList[_index].mChildIndexs = new int[_childPreconditon.Length];
                int parentIndex = _index;
                for (int i = 0; i < _childPreconditon.Length; i++)
                {
                    _index = _index + 1;
                    _preconditionList[parentIndex].mChildIndexs[i] = _index;
                    GetPreconditionConfigFromBtreeNode(_childPreconditon[i], ref _preconditionList, ref _index, parentIndex);
                }
            }
            else if (type.Equals(typeof(BTPreconditionOR)))
            {
                _preconditionList[_index].mType = (int)PreconditionType.Or;
                BTPrecondition[] _childPreconditon = ((BTPreconditionOR)_precondition).GetChildPrecondition();
                _preconditionList[_index].mChildIndexs = new int[_childPreconditon.Length];
                int parentIndex = _index;
                for (int i = 0; i < _childPreconditon.Length; i++)
                {
                    _index = _index + 1;
                    _preconditionList[parentIndex].mChildIndexs[i] = _index;
                    GetPreconditionConfigFromBtreeNode(_childPreconditon[i], ref _preconditionList, ref _index, parentIndex);
                }
            }
            else if (type.Equals(typeof(BTPreconditionNOT)))
            {
                _preconditionList[_index].mType = (int)PreconditionType.Not;
                BTPrecondition _childPreconditon = ((BTPreconditionNOT)_precondition).GetChildPrecondition();
                _preconditionList[_index].mChildIndexs    = new int[1];
                _preconditionList[_index].mChildIndexs[0] = _index + 1;
                int parentIndex = _index;
                _index = _index + 1;
                GetPreconditionConfigFromBtreeNode(_childPreconditon, ref _preconditionList, ref _index, parentIndex);
            }
        }
Exemplo n.º 2
0
        private static int GetBTreeChildPreconditionNum(BTPrecondition _precondition)
        {
            if (_precondition == null)
            {
                return(0);
            }
            int  _count = 0;
            Type type   = _precondition.GetType();

            if (type.Equals(typeof(BTPreconditionAND)))
            {
                _count += ((BTPreconditionAND)_precondition).GetChildPreconditionCount();
                BTPrecondition[] _chlidList = ((BTPreconditionAND)_precondition).GetChildPrecondition();
                if (_chlidList != null)
                {
                    for (int i = 0; i < _chlidList.Length; i++)
                    {
                        _count += GetBTreeChildPreconditionNum(_chlidList[i]);
                    }
                }
            }
            else if (type.Equals(typeof(BTPreconditionOR)))
            {
                _count += ((BTPreconditionOR)_precondition).GetChildPreconditionCount();
                BTPrecondition[] _chlidList = ((BTPreconditionOR)_precondition).GetChildPrecondition();
                if (_chlidList != null)
                {
                    for (int i = 0; i < _chlidList.Length; i++)
                    {
                        _count += GetBTreeChildPreconditionNum(_chlidList[i]);
                    }
                }
            }
            else if (type.Equals(typeof(BTPreconditionNOT)))
            {
                _count += 1;
                _count += GetBTreeChildPreconditionNum(((BTPreconditionNOT
                                                         )_precondition).GetChildPrecondition());
            }
            return(_count);
        }