private static void GetPreconditionConfigFromBtreeNode(BTreeNodePrecondition _precondition, ref PreconditionConfig[] _preconditionList, ref int _index, int _parentIndex = -1) { _preconditionList[_index] = new PreconditionConfig(); _preconditionList[_index].m_ParentIndex = _parentIndex; Type type = _precondition.GetType(); _preconditionList[_index].m_PreconditionName = type.Name.Split('`')[0]; if (type.Equals(typeof(BTreeNodePreconditionAND))) { _preconditionList[_index].m_Type = (int)PreconditionType.And; BTreeNodePrecondition[] _childPreconditon = ((BTreeNodePreconditionAND)_precondition).GetChildPrecondition(); _preconditionList[_index].m_ChildIndexs = new int[_childPreconditon.Length]; int parentIndex = _index; for (int i = 0; i < _childPreconditon.Length; i++) { _index = _index + 1; _preconditionList[parentIndex].m_ChildIndexs[i] = _index; GetPreconditionConfigFromBtreeNode(_childPreconditon[i], ref _preconditionList, ref _index, parentIndex); } } else if (type.Equals(typeof(BTreeNodePreconditionOR))) { _preconditionList[_index].m_Type = (int)PreconditionType.Or; BTreeNodePrecondition[] _childPreconditon = ((BTreeNodePreconditionOR)_precondition).GetChildPrecondition(); _preconditionList[_index].m_ChildIndexs = new int[_childPreconditon.Length]; int parentIndex = _index; for (int i = 0; i < _childPreconditon.Length; i++) { _index = _index + 1; _preconditionList[parentIndex].m_ChildIndexs[i] = _index; GetPreconditionConfigFromBtreeNode(_childPreconditon[i], ref _preconditionList, ref _index, parentIndex); } } else if (type.Equals(typeof(BTreeNodePreconditionNOT))) { _preconditionList[_index].m_Type = (int)PreconditionType.Not; BTreeNodePrecondition _childPreconditon = ((BTreeNodePreconditionNOT)_precondition).GetChildPrecondition(); _preconditionList[_index].m_ChildIndexs = new int[1]; _preconditionList[_index].m_ChildIndexs[0] = _index + 1; int parentIndex = _index; _index = _index + 1; GetPreconditionConfigFromBtreeNode(_childPreconditon, ref _preconditionList, ref _index, parentIndex); } }
private static int GetBTreeChildPreconditionNum(BTreeNodePrecondition _precondition) { if (_precondition == null) { return(0); } int _count = 0; Type type = _precondition.GetType(); if (type.Equals(typeof(BTreeNodePreconditionAND))) { _count += ((BTreeNodePreconditionAND)_precondition).GetChildPreconditionCount(); BTreeNodePrecondition[] _chlidList = ((BTreeNodePreconditionAND)_precondition).GetChildPrecondition(); if (_chlidList != null) { for (int i = 0; i < _chlidList.Length; i++) { _count += GetBTreeChildPreconditionNum(_chlidList[i]); } } } else if (type.Equals(typeof(BTreeNodePreconditionOR))) { _count += ((BTreeNodePreconditionOR)_precondition).GetChildPreconditionCount(); BTreeNodePrecondition[] _chlidList = ((BTreeNodePreconditionOR)_precondition).GetChildPrecondition(); if (_chlidList != null) { for (int i = 0; i < _chlidList.Length; i++) { _count += GetBTreeChildPreconditionNum(_chlidList[i]); } } } else if (type.Equals(typeof(BTreeNodePreconditionNOT))) { _count += 1; _count += GetBTreeChildPreconditionNum(((BTreeNodePreconditionNOT )_precondition).GetChildPrecondition()); } return(_count); }