private static BTreeNodePrecondition CreatePrecondition(ref BTreeNodePrecondition[] _nodePreconditions, PreconditionConfig[] _condConfigs, int _index) { int[] _childIndexs = _condConfigs[_index].m_ChildIndexs; //int _parentIndex = _condConfigs[_index].m_ParentIndex; if (_childIndexs != null && _childIndexs.Length != 0) { for (int i = 0; i < _childIndexs.Length; i++) { if (_nodePreconditions[_childIndexs[i]] == null) { _nodePreconditions[_childIndexs[i]] = CreatePrecondition(ref _nodePreconditions, _condConfigs, _childIndexs[i]); } } } BTreeNodePrecondition _precondition = null; if (_childIndexs != null && _childIndexs.Length > 0) { PreconditionType type = (PreconditionType)_condConfigs[_index].m_Type; BTreeNodePrecondition[] _childNodePreconditions = new BTreeNodePrecondition[_childIndexs.Length]; for (int i = 0; i < _childIndexs.Length; i++) { _childNodePreconditions[i] = _nodePreconditions[_childIndexs[i]]; } switch (type) { case PreconditionType.And: _precondition = new BTreeNodePreconditionAND(_childNodePreconditions); break; case PreconditionType.Or: _precondition = new BTreeNodePreconditionOR(_childNodePreconditions); break; case PreconditionType.Not: _precondition = new BTreeNodePreconditionNOT(_childNodePreconditions[0]); break; default: break; } } else { string typeName = _condConfigs[_index].m_PreconditionName; if (PreconditionTypeDic.ContainsKey(typeName)) { Type type = PreconditionTypeDic[typeName]; _precondition = (BTreeNodePrecondition)type.GetConstructor(new Type[] { }).Invoke(new object[] { }); } } return(_precondition); }
public static void RegisterPreconditionType(Type type) { if (type.IsSubclassOf(typeof(BTPrecondition))) { if (PreconditionTypeDic.ContainsKey(type.Name)) { PreconditionTypeDic[type.Name] = type; } else { PreconditionTypeDic.Add(type.Name, type); } } }