public static ConfigDic GetConfigDic(string aiConfigFile)
 {
     if (!cache.ContainsKey(aiConfigFile))
     {
         var obj = new AIConfigurationReader(aiConfigFile);
         cache.Add(aiConfigFile, obj);
     }
     return(cache[aiConfigFile].ConfigMap);
 }
Example #2
0
 public static Dictionary <string, Dictionary <string, string> > GetConfigMap(string fileName)
 {
     //如果指定配置文件不存在读取器对象,则创建。
     if (!cache.ContainsKey(fileName))
     {
         var reader = new AIConfigurationReader(fileName);
         cache.Add(fileName, reader);
     }
     return(cache[fileName].map);
 }
Example #3
0
        //配置状态机
        //private void ConfigFSM()
        //{
        //    stateList = new List<FSMState>();
        //    //添加状态
        //    DeadState dead = new DeadState();
        //    stateList.Add(dead);

        //    IdleState idle = new IdleState();
        //    stateList.Add(idle);

        //    PursuitState pursuit = new PursuitState();
        //    stateList.Add(pursuit);

        //    AttackingState attacking = new AttackingState();
        //    stateList.Add(attacking);

        //    PatrollingState patrolling = new PatrollingState();
        //    stateList.Add(patrolling);

        //    //添加条件
        //    idle.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
        //    idle.AddMap(FSMTriggerID.SawTarget, FSMStateID.Pursuit);

        //    pursuit.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
        //    pursuit.AddMap(FSMTriggerID.ReachTarget, FSMStateID.Attacking);
        //    pursuit.AddMap(FSMTriggerID.LoseTarget, FSMStateID.Default);

        //    attacking.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
        //    attacking.AddMap(FSMTriggerID.WithoutAttackRange, FSMStateID.Pursuit);
        //    attacking.AddMap(FSMTriggerID.KilledTarget, FSMStateID.Default);

        //    patrolling.AddMap(FSMTriggerID.NoHealth, FSMStateID.Dead);
        //    patrolling.AddMap(FSMTriggerID.SawTarget, FSMStateID.Pursuit);
        //    patrolling.AddMap(FSMTriggerID.CompletePatrol, FSMStateID.Idle);
        //}

        private void ConfigFSM()
        {
            stateList = new List <FSMState>();
            var map = AIConfigurationReader.Load(aiFile);

            foreach (var item in map.Keys)
            {
                string className = "AI.FSM." + item + "State";
                var    fsmStatus = Activator.CreateInstance(Type.GetType(className)) as FSMState;
                stateList.Add(fsmStatus);
                foreach (var key in map[item].Keys)
                {
                    FSMTriggerID tempTriggerID = (FSMTriggerID)Enum.Parse(typeof(FSMTriggerID), key);
                    FSMStateID   tempStateID   = (FSMStateID)Enum.Parse(typeof(FSMStateID), map[item][key]);
                    fsmStatus.AddMap(tempTriggerID, tempStateID);
                }
            }
        }
Example #4
0
        private void ConfigFSM()
        {
            var dic = AIConfigurationReader.Load(aiConfigFile);

            //创建状态对象
            foreach (var stateName in dic.Keys)
            {
                var type     = Type.GetType("AI.FSM." + stateName + "State");
                var stateObj = Activator.CreateInstance(type) as FSMState;
                //增加映射
                foreach (var triggerId in dic[stateName].Keys)
                {
                    var trigger = (FSMTriggerID)(Enum.Parse(typeof(FSMTriggerID), triggerId));
                    var state   = (FSMStateID)(Enum.Parse(typeof(FSMStateID), dic[stateName][triggerId]));
                    stateObj.AddMap(trigger, state);
                }
                //放入状态库
                states.Add(stateObj);
            }
        }