对txt配置文件的 读取架构2

 表的数据结构

   

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CharTable : DataTable
{
    /// <summary> 编号索引 </summary>
    private Dictionary<int , Template> idDict;

    /// <summary> 名字缩影 </summary>
    private Dictionary<string , Template> strDict;

    /// <summary> 唯一索引 </summary>
    private Dictionary<string , List<Template>> uniqueIndexDic;

    public CharTable(string path) : base(path)
    {
        this.idDict = new Dictionary<int , Template>();
        this.strDict = new Dictionary<string , Template>();
        this.uniqueIndexDic = new Dictionary<string , List<Template>>();
    }

    public CharTable(string[] paths) : base(paths)
    {
        this.idDict = new Dictionary<int , Template>();
        this.strDict = new Dictionary<string , Template>();
        this.uniqueIndexDic = new Dictionary<string , List<Template>>();
    }


    #region 数据 获取

    /// <summary>
    /// 获取所有的角色数据模型
    /// </summary>
    /// <returns></returns>
    public Dictionary<int ,Template> GetAllCharTemplate()
    {
        return this.idDict;
    }

    /// <summary>
    /// 获取所有图鉴显示的字典
    /// </summary>
    /// <returns></returns>
    public Dictionary<int ,Template> GetAllFlagShow()
    {
        Dictionary<int ,Template> flag=new Dictionary<int,Template>();
        foreach(KeyValuePair<int ,Template> temp in idDict)
        {
            string str=temp.Value.charFlagStr;
           if( str.Equals("1")||str.Equals("2")||str.Equals("3"))
           {
               flag.Add(temp.Key , temp.Value);
           }
        }
        return flag;
    }

    /// <summary>
    /// 通过id 获取唯一角色模型
    /// </summary>
    /// <param name="prototypeID"></param>
    /// <returns></returns>
    public Template GetTemplate(int prototypeID)
    {
        Template template = null;
        if(this.idDict.TryGetValue(prototypeID,out template))
        {
            return template;
        }
        return null;
    }

    /// <summary>
    /// 通过 字符串索引获取角色模型
    /// </summary>
    /// <param name="prototypeStr"></param>
    /// <returns></returns>
    public Template GetTemplate(string prototypeStr)
    {
        Template template = null;
        if(this.strDict.TryGetValue(prototypeStr,out template))
        {
            return template;
        }
        return null;
    }

    /// <summary>
    /// 通过唯一索引获取数据模型列表
    /// </summary>
    /// <param name="uniqueIndex"></param>
    /// <returns></returns>
    public List<Template> GetTemplateByUniqueIndex(string uniqueIndex)
    {
        List<Template> list = null;
        if (this.uniqueIndexDic.TryGetValue(uniqueIndex , out list))
        {
            return list;
        }
        return null;
    }

    /// <summary>
    /// 数据购建
    /// </summary>
    /// <returns></returns>
    public override bool OnBuild()
    {
        string text = DataMngr.GetText("名字_怪通用");
        foreach(KeyValuePair<int,Template> pair in this.idDict)
        {
            //角色数据模型表
            Template template = pair.Value;

            //技能临时存储表
            SkillTable.Template skillTemplate = null;
            //从技能表skill.txt获取 默认技能 信息
            skillTemplate = DataMngr.GetSkillTemplate(template._defaultSkillPrototype);
            //技能数据表空,没有找到 角色标准标记的技能数据
            if((skillTemplate==null)&&(template._defaultSkillPrototype.Length>0))
            {
                Debug.LogError(string.Concat(new string[] { "<" , template.prototypeStr , ">not found default skill" }));
                return false;
            }
            //将技能数据表插进角色数据表
            template.defaultSkill = skillTemplate;
            //默认技能的索引,在获取到 需要的数据后, 这个索引就不需要了,可以置空交给 垃圾回收,减少内存消耗
            template._defaultSkillPrototype = null;

            //获取 xpskill 技能
            skillTemplate = DataMngr.GetSkillTemplate(template._xpSkillPrototype);
            if((skillTemplate ==null)&&(template._xpSkillPrototype.Length>0))
            {
                Debug.LogError(string.Concat(new string[] { "<" , template.prototypeStr , ">not found xp skill" }));
                return false;
            }
            template.xpSkill = skillTemplate;
            template._xpSkillPrototype = null;

            //领导技
            skillTemplate = DataMngr.GetSkillTemplate(template._leaderSkillPrototype);
            if((skillTemplate==null)&&(template._leaderSkillPrototype.Length>0))
            {
                Debug.LogError(string.Concat(new string[] { "<" , template.prototypeStr , ">not found leader skill" }));
                return false;
            }
            template.leaderSkill = skillTemplate;
            template._leaderSkillPrototype = null;

            //名字索引有
            if(template._nameIndex.Length>0)
            {
                //获取角色名字
                template.name = DataMngr.GetText(template._nameIndex);
                if(template.name.Length<=0)
                {
                    Debug.LogError(string.Concat(new string[] { "<" , template.prototypeStr , ">not found char name" }));
                    return false;
                }
            }
            else
            {
                //对于 没有指定名字的 都使用统一命名 "名字_怪通用"
                template.name = text;
            }

            //角色进阶数据表
            CharacterEvlotionTable.Template characterEvolutionTemlate = DataMngr.GetCharacterEvolutionTemlate(template._evolution);
            if(characterEvolutionTemlate!=null)
            {
                template.characterEvolution = characterEvolutionTemlate;
            }
            template._nameIndex = null;

            //角色 觉醒数据模型
            CharacterAwakeTable.Template characterAwakeTemplate = DataMngr.GetCharacterAwakeTemplate(template._awake);
            if(characterAwakeTemplate!=null)
            {
                template.characterAwake = characterAwakeTemplate;
            }
            //角色 将魂数据模型 获取
            template.heroSoul = DataMngr.GetHeroSoulTemplate(template._heroSoulPrototype);
            template._heroSoulPrototype = null;

            //获取角色描述  
            template.description = DataMngr.GetText(template.description);
            //获取简 述
            template.shortDesc = DataMngr.GetText(template.shortDesc);
            //有天赋索引  
            if(template._talentTemplate.Length>0)
            {
                //获取天赋 数据表
                TalentTable.Template talentTemplate = DataMngr.GetTalentTemplate(template._talentTemplate);
                if(talentTemplate==null)
                {
                    return false;
                }
                template.talentTemplate = talentTemplate;
            }
            //专精 技能 
            if(template._masterTemplate.Length>0)
            {
                MasterTable.Template masterTemplate = DataMngr.GetMasterTemplate(template._masterTemplate);
                if(masterTemplate==null)
                {
                    return false;
                }
                //将取得的专精 技能表数据 存入角色表数据
                template.masterTemplate = masterTemplate;
            }
            //赠送 数据
            if(template._giftIndex.Length>0)
            {
                template.giftTemplate = DataMngr.GetDropsObjectTemplate(template._giftIndex);
            }
        }
        return true;
        
    }
   
    protected override bool OnLoadComplete()
    {
        return true;
    }
    protected override bool OnParseLine(int lineNum)
    {
        Template template = new Template
        {
            prototypeID =base.GetInt("编号",-1,true),
            prototypeStr = base.GetString("武将索引",string.Empty,true),
            uniqueIndex=base.GetString("同名武将",string.Empty,false),
            headID=base.GetString("头像ID","head_cao_ren",false),
            _nameIndex=base.GetString("名称索引",string.Empty,false),
            characterType=base.GetInt("将型",0,true),
            soldierType=base.GetInt("兵种",-1,true),
            isShowHeader=base.GetBoolean("是否隐藏血条",true,false),
            _defaultSkillPrototype=base.GetString("普通技",string.Empty,true),
            _xpSkillPrototype = base.GetString("武将技",string.Empty,false),
            _leaderSkillPrototype =base.GetString("领导技",string.Empty,false),
            charModel=base.GetString("角色模型",string.Empty,false).ToLower(),//全部 小型
            friendModel=base.GetString("小伙伴模型",string.Empty,false).ToLower(),
            weaponModle=base.GetString("武器模型",string.Empty,false).ToLower(),
            weaponAttachPoint=base.GetString("默认武器挂接位置",string.Empty,false).ToLower(),
            weapon1Model=base.GetString("副手武器模型",string.Empty,false).ToLower(),
            weapon1AttachPoint=base.GetString("默认副手武器挂接位置",string.Empty,false).ToLower(),
            quality=base.GetInt("品质",0,true),
            country=base.GetInt("国家",0,true),
            star =base.GetInt("星阶",0,true)
        };
        int num = base.GetInt("升级类型" , 0 , true) - 1;
        template.expType = num;
        template.textureInCharList = base.GetString("角色列表贴图" , string.Empty , false);
        template.xpValue = base.GetInt("初始怒气" , 0 , true);
        template.zonghePingJi = base.GetInt("综合评价" , 0 , true);
        template.gongjiPingJi = base.GetInt("攻击评价" , 0 , true);
        template.shengcunPingJi=base.GetInt("生存评价",0,true);
        template.fuzhuPingJi =base.GetInt("辅助评价",0,true);
        template.physAtk = base.GetInt("初始物攻" , 0 , true);
        template.physAtkUpFactor = base.GetFloat("物攻成长" , 0f , true);
        template.physDef = base.GetInt("初始物防" , 0 , true);
        template.physDefUpFactor = base.GetFloat("物防成长" , 0f , true);
        template.magicAtk = base.GetInt("初始法攻" , 0 , true);
        template.magicAtkUpFactor = base.GetFloat("法攻成长" , 0f , true);
        template.magicDef = base.GetInt("初始法防" , 0 , true);
        template.magicDefUpFactor = base.GetFloat("法防成长" , 0f , true);
        template.hp = base.GetInt("初始血量" , 0 , true);
        template.hpUpFactor = base.GetFloat("血量成长" , 0f , true);
        template.soulNumOfOverLev = base.GetInt("突破需求魂数" , 0 , false);
        template._heroSoulPrototype = base.GetString("将魂索引" , string.Empty , false);
        template.description = base.GetString("描述索引" , string.Empty , false);
        template.shortDesc = base.GetString("简述索引" , string.Empty , false);
        template._evolution = base.GetString("进阶索引" , null , false);
        template._awake = base.GetString("神魔觉醒索引" , null , false);
        template.maxLevel = base.GetInt("等级上限" , 0 , true);
        template.levelNpc = base.GetInt("等级" , 1 , false);
        template._talentTemplate = base.GetString("天赋索引" , string.Empty , false);
        template._masterTemplate = base.GetString("专精索引" , string.Empty , false);
        template.charTableType = base.GetInt("武将类型" , -1 , true);
        template.charFlagStr = base.GetString("图鉴显示" , "0" , true);
        template.charValue = base.GetInt("出售价格" , -1 , true);
        template._yfWeapon = base.GetString("缘分武器" , string.Empty , false);
        template._giftIndex = base.GetString("赠送索引" , string.Empty , false);
        //含有当前角色 
        if(this.idDict.ContainsKey(template.prototypeID))
        {
            return false;
        }
        if(this.strDict.ContainsKey(template.prototypeStr))
        {
            return false;
        }
        //没有添加
        this.idDict.Add(template.prototypeID , template);
        this.strDict.Add(template.prototypeStr , template);
        //如果 uniqueIndexDic没有取到
        if(template.uniqueIndex.Length>0)
        {
            List<Template> list = null;
            if(!this.uniqueIndexDic.TryGetValue(template.uniqueIndex,out list))
            {
                list = new List<Template>();
                this.uniqueIndexDic.Add(template.uniqueIndex , list);
            }
            list.Add(template);
        }
        return true;
    }

    /// <summary> 角色数据模型类</summary>
    public class Template
    {
        public string uniqueIndex;
        //神魔觉醒索引
        public string _awake;
        //普通技
        public string _defaultSkillPrototype;
        public string _evolution;
        public string _giftIndex =string.Empty;
        public string _heroSoulPrototype;
        public string _leaderSkillPrototype;
        public string _masterTemplate;
        public string _nameIndex;
        public string _talentTemplate;
        public string _xpSkillPrototype;
        public string _yfWeapon;
        public CharacterAwakeTable.Template characterAwake;
        public CharacterEvlotionTable.Template characterEvolution;
        public int characterType = -1;
        public string charFlagStr;
        public string charModel;
        public int charTableType = -1;
        public int charValue = -1;
        public int country;
        public SkillTable.Template defaultSkill;
        public string description = string.Empty;
        public int expType;
        public string friendModel;
        public int fuzhuPingJi;
        public DropsObjectTable.Template giftTemplate;
        public int gongjiPingJi;
        public string headID = string.Empty;
        public HeroSoulTable.Template heroSoul;
        public int hp;
        public float hpUpFactor;
        public bool isShowHeader = true;
        public SkillTable.Template leaderSkill;
        public int levelNpc;
        public int magicAtk;//魔法攻击
        public float magicAtkUpFactor;
        public int magicDef;
        public float magicDefUpFactor;
        public MasterTable.Template masterTemplate;
        public int maxLevel;
        public string name;
        public int physAtk;
        public float physAtkUpFactor;
        public int physDef;
        public float physDefUpFactor;
        public int prototypeID = -1;
        public string prototypeStr;
        public int quality;
        public int shengcunPingJi;
        public string shortDesc = string.Empty;
        public int soldierType = -1;
        public int soulNumOfOverLev;
        public int star;
        public TalentTable.Template talentTemplate;
        public string textureInCharList;
        public string weapon1AttachPoint;
        public string weapon1Model;
        public string weaponAttachPoint;
        public string weaponModle;
        public SkillTable.Template xpSkill;
        public int xpValue;
        public EquipTable.Template[] yfEquips = new EquipTable.Template[6];
        public YuanfenTable.Template yuanfenTemplate;
        public int zonghePingJi;
    }
    #endregion

}

 

posted @ 2015-11-28 01:47  bambom  阅读(208)  评论(0编辑  收藏  举报