对数据的读取
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
internal class DataMngr
{
#region 数据定义
private static DataMngr instMngr;
private string dirPath = string.Empty;
private string extName = string.Empty;
private bool inPack;
private List<DataTable> tableList;
//角色
private CharacterAwakeTable characterAwakeTable;
private CharacterEvlotionTable characterEvolutionTable;
private CharTable charTable;
//专精
private MasterAttrTable masterAttrTable;
private MasterTable masterTable;
//天赋
private TalentLevUpTable talentLevUpTable;
private TalentSubitemTable talentSubitemTable;
private TalentTable talentTable;
//装备
private EquipEvolutionTable equipEvolutionTable;
private EquipTable equipTable;
private EquipUpTable equipUpTable;
private ExpTable expTable;
//缘分物品
private YuanfenDetailTable yuanfenDetailTable;
private YuanfenTable yuanfenTable;
//物品.
private ItemTable itemTable;
//英雄升级用的将魂
private HeroSoulTable heroSoulTable;
//掉落
private DropsObjectTable dropsObjTable;
private DropsTable dropsTable;
//美女
private GirlsTable girlsTable;
//技能
private SkillTable skillTable;
//武器装备残片
private PieceTable pieceTable;
//文本表述
private TextTable textTable;
#endregion
#region 初始化
private DataMngr()
{
}
public static DataMngr GetInstance()
{
if(instMngr==null)
{
instMngr = new DataMngr();
}
return instMngr;
}
/// <summary>
///第一次调用前必须调用此函数初始化
/// </summary>
/// <param name="inPack_">true 通过 AssetsBundle加载 false 通过C#加载 </param>
/// <param name="dir">文件的路径 ,不包含文件名 Assets/Resources </param>
/// <returns></returns>
public static bool InitMngr(bool inPack_ , string dir)
{
return GetInstance()._InitMngr(inPack_ , dir);
}
#endregion
public static string _GetDirPath()
{
return GetInstance().dirPath;
}
public static DropsTable _GetDropsTable()
{
return GetInstance().dropsTable;
}
/// <summary>获取拓展名/ </summary>
public static string _GetExtName()
{
return GetInstance().extName;
}
private bool _InitMngr(bool inPack_, string dir)
{
this.tableList = new List<DataTable>();
this.inPack = inPack_;
if (!_isPack())
{
this.extName = ".csv";
}
else
{
this.extName = string.Empty;
}
this.dirPath = dir;
//角色表
string[] paths = new string[] { "/character", "/npc", "/botchar", "/actor" };
this.charTable = new CharTable(paths);
this.tableList.Add(this.charTable);
//技能表
string[] textArray2 = new string[] { "/skill", "/skill_leader" };
this.skillTable = new SkillTable(textArray2);
this.tableList.Add(this.skillTable);
//将魂表
this.heroSoulTable = new HeroSoulTable("/hero_soul");
this.tableList.Add(this.heroSoulTable);
//物品表
this.itemTable = new ItemTable("/item");
this.tableList.Add(this.itemTable);
//装备表
this.equipTable = new EquipTable("/item_equipment");
this.tableList.Add(this.equipTable);
//装备升级表
this.equipUpTable = new EquipUpTable("/item_equipment_up");
this.tableList.Add(this.equipUpTable);
//装备
this.equipEvolutionTable = new EquipEvolutionTable("/item_equipment_evolution");
this.tableList.Add(this.equipEvolutionTable);
//
this.characterEvolutionTable = new CharacterEvlotionTable("/character_evolution");
this.tableList.Add(this.characterEvolutionTable);
//
this.characterAwakeTable = new CharacterAwakeTable("/character_awake");
this.tableList.Add(this.characterAwakeTable);
this.dropsTable = new DropsTable();
this.dropsObjTable = new DropsObjectTable("/drops_object");
this.tableList.Add(this.dropsObjTable);
this.yuanfenTable = new YuanfenTable("/yuanfen");
this.tableList.Add(this.yuanfenTable);
this.yuanfenDetailTable = new YuanfenDetailTable("/yuanfen_detail");
this.tableList.Add(this.yuanfenDetailTable);
this.pieceTable = new PieceTable("/piece");
this.tableList.Add(this.pieceTable);
this.masterTable = new MasterTable("/master");
this.tableList.Add(this.masterTable);
this.masterAttrTable = new MasterAttrTable("/master_attr");
this.tableList.Add(this.masterAttrTable);
//文本表述
string[] textArray5 = new string[] { "/text", "/text_mission", "/text_character", "/text_skill", "/text_item", "/text_quest", "/text_ui", "/text_story", "/text_tip", "/text_levelup", "/text_ui_localization" };
this.textTable = new TextTable(textArray5);
this.tableList.Add(this.textTable);
foreach (DataTable table in this.tableList)
{
if (!table.Load())
{
Debug.LogError(string.Concat("File: \"" , table.GetFilePath() , "\" load failed!"));
return false;
}
}
foreach (DataTable table in this.tableList)
{
if (!table.OnBuild())
{
Debug.LogError(string.Concat("File: \"" , table.GetFilePath() , "\" build failed!"));
return false;
}
}
return true;
}
/// <summary>
/// true 打包方式加载 false C# 加载数据
/// </summary>
/// <returns></returns>
public static bool _isPack()
{
return GetInstance().inPack;
}
#region 数据获取
//===============角色==========================//
/// <summary>
/// 获取所有角色字典 ,来自character.txt文本
/// </summary>
/// <returns></returns>
public static Dictionary<int , CharTable.Template> GetAllCharDict()
{
return GetInstance().charTable.GetAllCharTemplate();
}
public static Dictionary<int , CharTable.Template> GetAllFlagDict()
{
return GetInstance().charTable.GetAllFlagShow();
}
public static CharacterAwakeTable.Template GetCharacterAwakeTemplate(int prototypeID)
{
return GetInstance().characterAwakeTable.GetTemplate(prototypeID);
}
public static CharacterAwakeTable.Template GetCharacterAwakeTemplate(string prototypeStr)
{
return GetInstance().characterAwakeTable.GetTemplate(prototypeStr);
}
public static CharacterEvlotionTable.Template GetCharacterEvolutionTemlate(string prototypeStr)
{
return GetInstance().characterEvolutionTable.GetTemplate(prototypeStr);
}
public static CharacterEvlotionTable.Template GetCharacterEvolutionTemplate(int prototypeID)
{
return GetInstance().characterEvolutionTable.GetTemplate(prototypeID);
}
public static CharTable.Template GetCharTemplate(int prototypeID)
{
return GetInstance().charTable.GetTemplate(prototypeID);
}
public static CharTable.Template GetCharTemplate(string prototypeStr)
{
return GetInstance().charTable.GetTemplate(prototypeStr);
}
public static List<CharTable.Template> GetCharTemplateByUniqueIndex(string uniqueIndex)
{
return GetInstance().charTable.GetTemplateByUniqueIndex(uniqueIndex);
}
//===================掉落物品========================//
public static DropsObjectTable.Template GetDropsObjectTemplate(int prototypeID)
{
return GetInstance().dropsObjTable.GetTemplate(prototypeID);
}
public static DropsObjectTable.Template GetDropsObjectTemplate(string prototypeStr)
{
return GetInstance().dropsObjTable.GetTemplate(prototypeStr);
}
public static DropsTable.Template GetDropsTemplate(int prototypeID)
{
return GetInstance().dropsTable.GetTemplate(prototypeID);
}
public static DropsTable.Template GetDropsTemplate(string prototypeStr)
{
return GetInstance().dropsTable.GetTemplate(prototypeStr);
}
//==========================装备=========================//
public static Dictionary<int , EquipTable.Template> GetAllEquipDict()
{
return GetInstance().equipTable.GetAllEquipTemplate();
}
public static EquipEvolutionTable.Template GetEquipEvolutionTemlate(string prototypeStr)
{
return GetInstance().equipEvolutionTable.GetTemplate(prototypeStr);
}
public static EquipEvolutionTable.Template GetEquipEvolutionTemplate(int prototypeID)
{
return GetInstance().equipEvolutionTable.GetTemplate(prototypeID);
}
public static EquipTable.Template GetEquipTemplate(int prototypeID)
{
return GetInstance().equipTable.GetTemplate(prototypeID);
}
public static EquipTable.Template GetEquipTemplate(string prototypeStr)
{
return GetInstance().equipTable.GetTemplate(prototypeStr);
}
public static EquipUpTable.Template GetEquipUpTemplate(int prototypeID)
{
return GetInstance().equipUpTable.GetTemplate(prototypeID);
}
public static EquipUpTable.Template GetEquipUpTemplate(string prototypeStr)
{
return GetInstance().equipUpTable.GetTemplate(prototypeStr);
}
public static int GetExpByLevel(int expType , int level)
{
return GetInstance().expTable.GetExp(expType , level);
}
public static HeroSoulTable.Template GetHeroSoulTemplate(int prototypeID)
{
return GetInstance().heroSoulTable.GetTemplate(prototypeID);
}
public static HeroSoulTable.Template GetHeroSoulTemplate(string prototypeStr)
{
return GetInstance().heroSoulTable.GetTemplate(prototypeStr);
}
public static ItemTable.Template GetItemTemplate(int prototypeID)
{
return GetInstance().itemTable.GetTemplate(prototypeID);
}
public static ItemTable.Template GetItemTemplate(string prototypeStr)
{
return GetInstance().itemTable.GetTemplate(prototypeStr);
}
public static PieceTable.Template GetPieceTemplate(int prototyoeID)
{
return GetInstance().pieceTable.getTemplate(prototyoeID);
}
public static PieceTable.Template GetPieceTemplate(string prototypeStr)
{
return GetInstance().pieceTable.getTemplate(prototypeStr);
}
public static MasterAttrTable.Template GetMasterAttrTemplate(string prototype)
{
return GetInstance().masterAttrTable.GetTemplate(prototype);
}
public static MasterTable.Template GetMasterTemplate(string prototype)
{
return GetInstance().masterTable.GetTemplate(prototype);
}
public static SkillTable.Template GetSkillTemplate(int prototypeID)
{
return GetInstance().skillTable.GetTemplate(prototypeID);
}
public static SkillTable.Template GetSkillTemplate(string prototypeStr)
{
return GetInstance().skillTable.GetTemplate(prototypeStr);
}
public static GirlsTable.Template GetGirlTemplate(int id)
{
return GetInstance().girlsTable.GetTemplate(id);
}
public static GirlsTable.Template GetGirlTemplate(string idx)
{
return GetInstance().girlsTable.GetTemplate(idx);
}
public static TalentLevUpTable.Template GetTalentLevUpTemplate(int type)
{
return GetInstance().talentLevUpTable.getTemplate(type);
}
public static TalentSubitemTable.Template GetTalentSubitemTemplate(int prototypeID)
{
return GetInstance().talentSubitemTable.GetTemplate(prototypeID);
}
public static TalentSubitemTable.Template GetTalentSubitemTemplate(string prototypeStr)
{
return GetInstance().talentSubitemTable.GetTemplate(prototypeStr);
}
public static TalentTable.Template GetTalentTemplate(int prototypeID)
{
return GetInstance().talentTable.GetTemplate(prototypeID);
}
public static TalentTable.Template GetTalentTemplate(string prototypeStr)
{
return GetInstance().talentTable.GetTemplate(prototypeStr);
}
/// <summary>
/// 获取文本表述
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public static string GetText(string index)
{
return GetInstance().textTable.getText(index);
}
public static YuanfenDetailTable.Template GetYuanfenDetailTemplate(string prototypeStr)
{
return GetInstance().yuanfenDetailTable.GetTemplate(prototypeStr);
}
#endregion
}