ConfigMgr.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class ConfigMgr : Singleton<ConfigMgr>
  5. {
  6. private int linestart = 1;
  7. private int rowstart = 1;
  8. private string splitword = ",";
  9. private static bool m_bInitCSVFinished = false;
  10. private static bool m_bInitXMLFinished = false;
  11. private byte[] urldatas;
  12. public byte[] UrlDatas { get => urldatas; }
  13. public static bool InitFinished
  14. {
  15. get { return m_bInitCSVFinished && m_bInitXMLFinished; }
  16. }
  17. private static string m_strCurLangKey = LangKeys.ChinaSimplifiedFull;
  18. public static string CurLangKey
  19. {
  20. get { return m_strCurLangKey; }
  21. set
  22. {
  23. if (m_strCurLangKey != value)
  24. {
  25. //m_bInitCSVFinished = false;
  26. m_strCurLangKey = value;
  27. //I18N
  28. }
  29. }
  30. }
  31. public Dictionary<string, Dictionary<string, Dictionary<string, string>>> ConfigDictionary;
  32. public Dictionary<string, int> ConfigLongthDictionary;
  33. private Dictionary<string, string> mXmlConfigDict;
  34. public Dictionary<string, string> XmlConfigDict
  35. {
  36. get { return mXmlConfigDict; }
  37. }
  38. public override void Init()
  39. {
  40. base.Init();
  41. m_bInitCSVFinished = false;
  42. m_bInitXMLFinished = false;
  43. ConfigDictionary = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>(19);
  44. ConfigLongthDictionary = new Dictionary<string, int>(19);
  45. mXmlConfigDict = new Dictionary<string, string>();
  46. GetConfigAsset();
  47. }
  48. public override void UnInit()
  49. {
  50. if (LaunchThread.HasInstance())
  51. {
  52. LaunchThread.Instance.Stop(LaunchThread.AsyncLaunchState.ConfigInit);
  53. }
  54. base.UnInit();
  55. }
  56. private void GetConfigAsset()
  57. {
  58. if (InitFinished)
  59. return;
  60. ResourceMgr.Instance.LoadDirAsset<List<TextAsset>>(OnLoadXmlCallback, Constants.XmlConfig);
  61. ResourceMgr.Instance.LoadDirAsset<List<TextAsset>>(OnCallBack, Constants.CsvConfig);
  62. }
  63. public void ResetKeywords()
  64. {
  65. if (InitFinished)
  66. return;
  67. string m_tableName = string.Format("LanguagePackage{0}", ConfigMgr.CurLangKey);
  68. if (ConfigDictionary != null && ConfigDictionary.ContainsKey(m_tableName))
  69. {
  70. m_bInitCSVFinished = true;
  71. DebugHelper.Log(" [ConfigMgr] getKeywordsConfigAsset");
  72. }
  73. else
  74. {
  75. ResourceMgr.Instance.LoadAsset<List<TextAsset>>(OnResetKeywordsCallBack, Constants.CsvConfig, ELoadType.UI, m_tableName);
  76. }
  77. }
  78. void OnCallBack(List<TextAsset> objs, string path_, string[] assetNames_)
  79. {
  80. if (objs == null || objs.Count <= 0)
  81. {
  82. EventMgr.DispatchEvent(new CoreEvent<int>(ECoreEventType.EID_ConfigMgrInit, 0));
  83. return;
  84. }
  85. if (LaunchThread.HasInstance())
  86. {
  87. string keyword = "LanguagePackage";
  88. string keywordname = string.Format("{0}{1}", keyword, CurLangKey);
  89. string curname = string.Empty;
  90. TextAsset tx;
  91. List<string> names = new List<string>();
  92. List<string> contents = new List<string>();
  93. for (int i = 0; i < objs.Count; ++i)
  94. {
  95. tx = objs[i];
  96. curname = tx.name;
  97. if (curname == "DownLoadUrlCfg")
  98. {
  99. Debug.Log("====== you DownLoadUrlCfg =======11");
  100. urldatas = tx.bytes;
  101. continue;
  102. }
  103. //Debug.Log($"Config Name = [{curname}]");
  104. if (/*curname.Contains(keyword) && !curname.Equals(keywordname) ||*/ tx.text.Length <= 0)
  105. continue;
  106. names.Add(curname);
  107. contents.Add(tx.text);
  108. }
  109. keyword = string.Empty;
  110. keywordname = string.Empty;
  111. curname = string.Empty;
  112. System.Action action = () =>
  113. {
  114. for (int i = 0, iMax = names.Count; i < iMax; i++)
  115. {
  116. curname = names[i];
  117. Dictionary<string, Dictionary<string, string>> ts = getData(curname, contents[i]);
  118. if (ConfigDictionary.ContainsKey(curname))
  119. {
  120. ConfigDictionary[curname] = ts;
  121. }
  122. else
  123. {
  124. ConfigDictionary.Add(curname, ts);
  125. }
  126. }
  127. m_bInitCSVFinished = true;
  128. };
  129. LaunchThread.Instance.Start(LaunchThread.AsyncLaunchState.ConfigInit, action, CheckCfgOk, null);
  130. }
  131. else
  132. {
  133. string keyword = "LanguagePackage";
  134. string keywordname = string.Format("{0}{1}", keyword, CurLangKey);
  135. string curname = string.Empty;
  136. TextAsset tx;
  137. for (int i = 0; i < objs.Count; ++i)
  138. {
  139. tx = objs[i];
  140. curname = tx.name;
  141. if(curname == "DownLoadUrlCfg")
  142. {
  143. Debug.Log("====== you DownLoadUrlCfg =======");
  144. urldatas = tx.bytes;
  145. continue;
  146. }
  147. if (/*curname.Contains(keyword) && !curname.Equals(keywordname) || */tx.text.Length <= 0)
  148. continue;
  149. Dictionary<string, Dictionary<string, string>> ts = getData(curname, tx.text);
  150. if (ConfigDictionary.ContainsKey(curname))
  151. {
  152. ConfigDictionary[curname] = ts;
  153. }
  154. else
  155. {
  156. ConfigDictionary.Add(curname, ts);
  157. }
  158. }
  159. m_bInitCSVFinished = true;
  160. keyword = string.Empty;
  161. keywordname = string.Empty;
  162. curname = string.Empty;
  163. tx = null;
  164. CheckCfgOk();
  165. }
  166. }
  167. void OnLoadXmlCallback(List<TextAsset> objs, string path_, string[] assetNames_)
  168. {
  169. TextAsset tx;
  170. for (int i = 0; i < objs.Count; ++i)
  171. {
  172. tx = objs[i];
  173. mXmlConfigDict.Add(tx.name, tx.text);
  174. }
  175. m_bInitXMLFinished = true;
  176. CheckCfgOk();
  177. }
  178. void CheckCfgOk()
  179. {
  180. if(InitFinished)
  181. {
  182. EventMgr.DispatchEvent(new CoreEvent<int>(ECoreEventType.EID_ConfigMgrInit, 1));
  183. }
  184. }
  185. void OnResetKeywordsCallBack(List<TextAsset> objs, string assetPath_, string[] assetNames_)
  186. {
  187. if (objs == null || objs.Count <= 0)
  188. {
  189. DebugHelper.Log("No Config Data AssetBundle");
  190. return;
  191. }
  192. string keyword = "LanguagePackage";
  193. string keywordname = string.Format("{0}{1}", keyword, CurLangKey);
  194. TextAsset tx;
  195. string curname = string.Empty;
  196. for (int i = 0; i < objs.Count; ++i)
  197. {
  198. tx = objs[i];
  199. curname = tx.name;
  200. if (/*curname.Contains(keyword) && !curname.Equals(keywordname) ||*/ tx.text.Length <= 0)
  201. continue;
  202. Dictionary<string, Dictionary<string, string>> ts = getData(curname, tx.text);
  203. if (ConfigDictionary != null)
  204. {
  205. if (ConfigDictionary.ContainsKey(curname))
  206. {
  207. ConfigDictionary[curname] = ts;
  208. }
  209. else
  210. {
  211. ConfigDictionary.Add(curname, ts);
  212. }
  213. }
  214. }
  215. m_bInitCSVFinished = true;
  216. }
  217. private Dictionary<string, Dictionary<string, string>> getData(string name, string content)
  218. {
  219. if (name.Contains("Language"))
  220. {
  221. return getData_New(name,content);
  222. }
  223. string[] lineArray;
  224. string[] charArray = null;
  225. // string text = content.Replace("\r", "@");
  226. // lineArray = text.Split("@"[0]);
  227. System.IO.StringReader reader = new System.IO.StringReader(content);
  228. string str = reader.ReadLine();
  229. List<string> tempList = new List<string>();
  230. while (!string.IsNullOrEmpty(str))
  231. {
  232. tempList.Add(str);
  233. str = reader.ReadLine();
  234. }
  235. lineArray = tempList.ToArray();
  236. //DebugHelper.LogWarning("[TableName: {0}]lineArray {1}",name, lineArray[0]);
  237. string[] indexname = null;
  238. if (name.Contains("Language"))
  239. {
  240. indexname = FileHelper.SpiltData(lineArray[1]);
  241. }
  242. else
  243. {
  244. indexname = lineArray[1].Split(splitword[0]);
  245. }
  246. Dictionary<string, Dictionary<string, string>> Table = new Dictionary<string, Dictionary<string, string>>(lineArray.Length);
  247. int linelength = 0;
  248. for (int i = linestart; i < lineArray.Length; ++i)
  249. {
  250. if (name.Contains("Language"))
  251. {
  252. charArray = FileHelper.SpiltData(lineArray[i]);
  253. }
  254. else
  255. {
  256. charArray = lineArray[i].Split(splitword[0]);
  257. }
  258. linelength = charArray.Length;
  259. if (linelength > 0 && charArray[0] == string.Empty)
  260. {
  261. //DebugHelper.LogWarning("[ConfigMgr. getData] Empty Index {0} {1}", name, i);
  262. continue;
  263. }
  264. Dictionary<string, string> Row = new Dictionary<string, string>(linelength);
  265. for (int j = rowstart; j < linelength; ++j)
  266. {
  267. if (j == rowstart && indexname[j] == string.Empty)
  268. {
  269. DebugHelper.LogWarning("[ConfigMgr. getData] Empty key {0} {1}", name, j);
  270. continue;
  271. }
  272. #if UNITY_EDITOR
  273. if (j >= indexname.Length)
  274. {
  275. DebugHelper.LogError("{0},Split error in {1}", name, charArray[0]);
  276. }
  277. #endif
  278. if (Row.ContainsKey(indexname[j]))
  279. {
  280. //DebugHelper.LogWarning("[ConfigMgr. getData] {0} {1}", name, indexname[j]);
  281. continue;
  282. }
  283. Row.Add(indexname[j], charArray[j]);
  284. }
  285. if (Table.ContainsKey(charArray[0]))
  286. {
  287. //DebugHelper.LogWarning("[ConfigMgr. getData] {0} {1} {2}" , name , i, lineArray[i-1]);
  288. continue;
  289. }
  290. Table.Add(charArray[0], Row);
  291. }
  292. if (ConfigLongthDictionary != null && !ConfigLongthDictionary.ContainsKey(name))
  293. {
  294. //int length = lineArray.Length - (linestart + 1);
  295. int length = lineArray.Length - (linestart);
  296. ConfigLongthDictionary.Add(name, length);
  297. }
  298. return Table;
  299. }
  300. private string[] GetLanguageString(string text)
  301. {
  302. string[] ret = null;
  303. int i = text.IndexOf(',');
  304. if (i >= 0)
  305. {
  306. ret = new string[2];
  307. ret[0] = text.Substring(0,i);
  308. ret[1] = FileHelper.RemoveHeadandTailChar(text.Substring(i + 1, text.Length - i - 1), '"');
  309. //Debug.Log($"1 = {ret[0]} 2 = {ret[1]}");
  310. }
  311. return ret;
  312. }
  313. private Dictionary<string, Dictionary<string, string>> getData_New(string name, string content)
  314. {
  315. string[] lineArray;
  316. string[] charArray = null;
  317. System.IO.StringReader reader = new System.IO.StringReader(content);
  318. string str = reader.ReadLine();
  319. List<string> tempList = new List<string>();
  320. while (!string.IsNullOrEmpty(str))
  321. {
  322. tempList.Add(str);
  323. str = reader.ReadLine();
  324. }
  325. lineArray = tempList.ToArray();
  326. string[] indexname = null;
  327. indexname = GetLanguageString(lineArray[1]);
  328. Dictionary<string, Dictionary<string, string>> Table = new Dictionary<string, Dictionary<string, string>>(lineArray.Length);
  329. int linelength = 0;
  330. for (int i = linestart; i < lineArray.Length; ++i)
  331. {
  332. charArray = GetLanguageString(lineArray[i]);
  333. linelength = charArray.Length;
  334. if (linelength > 0 && charArray[0] == string.Empty)
  335. {
  336. //DebugHelper.LogWarning("[ConfigMgr. getData] Empty Index {0} {1}", name, i);
  337. continue;
  338. }
  339. Dictionary<string, string> Row = new Dictionary<string, string>(linelength);
  340. for (int j = rowstart; j < linelength; ++j)
  341. {
  342. if (j == rowstart && indexname[j] == string.Empty)
  343. {
  344. DebugHelper.LogWarning("[ConfigMgr. getData] Empty key {0} {1}", name, j);
  345. continue;
  346. }
  347. #if UNITY_EDITOR
  348. if (j >= indexname.Length)
  349. {
  350. DebugHelper.LogError("{0},Split error in {1}", name, charArray[0]);
  351. }
  352. #endif
  353. if (Row.ContainsKey(indexname[j]))
  354. {
  355. //DebugHelper.LogWarning("[ConfigMgr. getData] {0} {1}", name, indexname[j]);
  356. continue;
  357. }
  358. Row.Add(indexname[j], charArray[j]);
  359. }
  360. if (Table.ContainsKey(charArray[0]))
  361. {
  362. //DebugHelper.LogWarning("[ConfigMgr. getData] {0} {1} {2}" , name , i, lineArray[i-1]);
  363. continue;
  364. }
  365. Table.Add(charArray[0], Row);
  366. }
  367. if (ConfigLongthDictionary != null && !ConfigLongthDictionary.ContainsKey(name))
  368. {
  369. //int length = lineArray.Length - (linestart + 1);
  370. int length = lineArray.Length - (linestart);
  371. ConfigLongthDictionary.Add(name, length);
  372. }
  373. return Table;
  374. }
  375. public Dictionary<string, Dictionary<string, string>> getTable(string tablename)
  376. {
  377. if (!InitFinished || ConfigDictionary == null)
  378. return null;
  379. Dictionary<string, Dictionary<string, string>> ts;
  380. ConfigDictionary.TryGetValue(tablename, out ts);
  381. if (ts != null && ts.Count > 0)
  382. return ts;
  383. else
  384. {
  385. DebugHelper.LogWarning("[ConfigMgr] {0} cant find", tablename);
  386. return null;
  387. }
  388. }
  389. public string GetXmlCfg(string fileName)
  390. {
  391. string cfg;
  392. mXmlConfigDict.TryGetValue(fileName, out cfg);
  393. return cfg;
  394. }
  395. public int getTableLength(string tablename)
  396. {
  397. if (!InitFinished)
  398. return -1;
  399. if (ConfigLongthDictionary.ContainsKey(tablename))
  400. return ConfigLongthDictionary[tablename];
  401. return 0;
  402. }
  403. public Dictionary<string, string> getLine(int id, string tablename)
  404. {
  405. return getLine(id.ToString(), tablename);
  406. }
  407. public Dictionary<string, string> getLine(string id, string tablename)
  408. {
  409. if (!InitFinished) {
  410. Debug.LogError("配置未加载!!!");
  411. return null;
  412. }
  413. Dictionary<string, Dictionary<string, string>> ts = getTable(tablename);
  414. if (ts != null && ts.ContainsKey(id))
  415. {
  416. return ts[id];
  417. }
  418. else
  419. return null;
  420. }
  421. public string getValue(int id, string keyname, string tablename)
  422. {
  423. return getValue(id.ToString(), keyname, tablename);
  424. }
  425. public string getValue(string id, string keyname, string tablename)
  426. {
  427. if (!InitFinished)
  428. return null;
  429. Dictionary<string, Dictionary<string, string>> ts = getTable(tablename);
  430. //Log.E("id {0} {1} {2}",id,keyname,tablename);
  431. if (ts != null && ts.ContainsKey(id) && ts[id].ContainsKey(keyname))
  432. {
  433. return ts[id][keyname];
  434. }
  435. else
  436. return null;
  437. }
  438. public void ClearDLUrlData()
  439. {
  440. urldatas = null;
  441. }
  442. }
  443. public class I18N
  444. {
  445. static string m_tableName = "";
  446. static string m_curLangKey = "";
  447. static string tableName
  448. {
  449. get
  450. {
  451. if (string.IsNullOrEmpty(m_tableName) || m_curLangKey != ConfigMgr.CurLangKey)
  452. {
  453. m_tableName = string.Format("LanguagePackage{0}", ConfigMgr.CurLangKey);
  454. m_curLangKey = ConfigMgr.CurLangKey;
  455. }
  456. return m_tableName;
  457. }
  458. }
  459. public static string T(string key)
  460. {
  461. string result = key;
  462. if (key == null)
  463. {
  464. DebugHelper.LogWarning("[ I18N.T ] keyword is null!!!");
  465. return "";
  466. }
  467. if (ConfigMgr.HasInstance())
  468. {
  469. if (!ConfigMgr.InitFinished)
  470. {
  471. ConfigMgr.Instance.ResetKeywords();
  472. m_tableName = string.Empty;
  473. }
  474. string value = ConfigMgr.Instance.getValue(key, "Language", tableName);
  475. if (value != null)
  476. {
  477. result = value.Replace("\\n", "\n");
  478. }
  479. }
  480. return result;
  481. }
  482. public static string SetLanguageValue(string key, params string[] param)
  483. {
  484. if (param == null || param.Length == 0)
  485. {
  486. return T(key);
  487. }
  488. string result = key;
  489. if (key == null)
  490. {
  491. DebugHelper.LogWarning("[ I18N.T ] keyword is null!!!");
  492. return "";
  493. }
  494. if (ConfigMgr.HasInstance())
  495. {
  496. if (!ConfigMgr.InitFinished)
  497. {
  498. ConfigMgr.Instance.ResetKeywords();
  499. m_tableName = string.Empty;
  500. }
  501. string value = ConfigMgr.Instance.getValue(key, "Language", tableName);
  502. if (value != null)
  503. {
  504. result = value.Replace("\\n", "\n");
  505. result = string.Format(result, param);
  506. }
  507. else
  508. {
  509. DebugHelper.LogWarning("[ I18N.T ]ConfigMgr.cant find the key or keyword is null!!! " + key);
  510. }
  511. }
  512. return result;
  513. }
  514. }
  515. public class I18NOpera
  516. {
  517. static string m_tableName = "";
  518. static string tableName
  519. {
  520. get
  521. {
  522. if (string.IsNullOrEmpty(m_tableName))
  523. m_tableName = string.Format("OperaKeywords{0}", ConfigMgr.CurLangKey);
  524. return m_tableName;
  525. }
  526. }
  527. public static string T(int key)
  528. {
  529. string result = key.ToString();
  530. if (ConfigMgr.HasInstance())
  531. {
  532. if (!ConfigMgr.InitFinished)
  533. {
  534. ConfigMgr.Instance.ResetKeywords();
  535. m_tableName = string.Empty;
  536. }
  537. result = ConfigMgr.Instance.getValue(key, "info", tableName);
  538. result = result.Replace("\\n", "\n");//��������
  539. //if (value != null)
  540. //{
  541. // result = value.Replace("|", "\r\n");
  542. //}
  543. //else
  544. //{
  545. // DebugHelper.LogWarning("[ I18NOpera.T ]ConfigMgr.cant find the key or keyword is null!!!");
  546. //}
  547. }
  548. return result;
  549. }
  550. }
  551. public class I18NOperaBranch
  552. {
  553. static string m_tableName = "";
  554. static string tableName
  555. {
  556. get
  557. {
  558. if (string.IsNullOrEmpty(m_tableName))
  559. m_tableName = string.Format("OperaBranchwords{0}", ConfigMgr.CurLangKey);
  560. return m_tableName;
  561. }
  562. }
  563. public static string T(int key)
  564. {
  565. string result = key.ToString();
  566. if (ConfigMgr.HasInstance())
  567. {
  568. if (!ConfigMgr.InitFinished)
  569. {
  570. ConfigMgr.Instance.ResetKeywords();
  571. m_tableName = string.Empty;
  572. }
  573. result = ConfigMgr.Instance.getValue(key, "info", tableName);
  574. if (result == null)
  575. {
  576. DebugHelper.LogError(string.Format("in {0},can not find value by key :{1}", tableName, key));
  577. }
  578. result = result.Replace("\\n", "\n");//��������
  579. }
  580. return result;
  581. }
  582. }
  583. public class EditorConfigCSV
  584. {
  585. private string m_tableName = "";
  586. public string TableName
  587. {
  588. get
  589. {
  590. return m_tableName;
  591. }
  592. }
  593. private int linestart = 1;
  594. private int rowstart = 1;
  595. private string splitword = ",";
  596. private Dictionary<string, Dictionary<string, string>> m_tableData;
  597. public string T(string key, string filed, string tableName_)
  598. {
  599. m_tableName = tableName_;
  600. string result = key;
  601. #if UNITY_EDITOR
  602. string value = GetValue(key, filed);
  603. if (value != null)
  604. {
  605. result = value.Replace("\\n", "\n");
  606. }
  607. #endif //UNITY_EDITOR
  608. return result;
  609. }
  610. public string GetValue(string id, string keyName_, string tableName_ = null)
  611. {
  612. #if UNITY_EDITOR
  613. if (m_tableData == null)
  614. {
  615. if (tableName_ != null)
  616. m_tableName = tableName_;
  617. string path = string.Format("{0}/{1}.csv", Constants.CsvConfig, TableName);
  618. TextAsset tx = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(path) as TextAsset;
  619. m_tableData = GetData(tx);
  620. }
  621. if (id == null)
  622. {
  623. return null;
  624. }
  625. if (m_tableData.ContainsKey(id) && m_tableData[id].ContainsKey(keyName_))
  626. {
  627. return m_tableData[id][keyName_];
  628. }
  629. #endif //UNITY_EDITOR
  630. return null;
  631. }
  632. public List<string> GetId2Key(string keyName_, string keyValue_, string tableName_ = null)
  633. {
  634. List<string> idList = new List<string>();
  635. #if UNITY_EDITOR
  636. if (m_tableData == null)
  637. {
  638. if (tableName_ != null)
  639. m_tableName = tableName_;
  640. string path = string.Format("{0}/{1}.csv", Constants.CsvConfig, TableName);
  641. TextAsset tx = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(path) as TextAsset;
  642. m_tableData = GetData(tx);
  643. }
  644. foreach (var dic in m_tableData)
  645. {
  646. if (dic.Value[keyName_] == keyValue_)
  647. {
  648. idList.Add(dic.Key);
  649. }
  650. }
  651. #endif //UNITY_EDITOR
  652. return idList;
  653. }
  654. private Dictionary<string, Dictionary<string, string>> GetData(Object obj)
  655. {
  656. if (obj == null)
  657. return null;
  658. string[] lineArray;
  659. string[] charArray;
  660. TextAsset binAsset = obj as TextAsset;
  661. string text = binAsset.text.Replace("\r\n", "@");
  662. lineArray = text.Split("@"[0]);
  663. //DebugHelper.LogWarning("[TableName: {0}]lineArray {1}",binAsset.name, lineArray[0]);
  664. string[] indexname = lineArray[1].Split(splitword[0]);
  665. Dictionary<string, Dictionary<string, string>> Table = new Dictionary<string, Dictionary<string, string>>();
  666. for (int i = linestart; i < lineArray.Length; ++i)
  667. {
  668. charArray = lineArray[i].Split(splitword[0]);
  669. if (charArray.Length > 0 && charArray[0] == string.Empty)
  670. {
  671. DebugHelper.LogWarning("[ConfigMgr. GetData] Empty Index {0} {1}", binAsset.name, i);
  672. continue;
  673. }
  674. Dictionary<string, string> Row = new Dictionary<string, string>();
  675. for (int j = rowstart; j < charArray.Length; ++j)
  676. {
  677. if (indexname[j] == "" || indexname[j] == string.Empty)
  678. {
  679. DebugHelper.LogWarning("[ConfigMgr. GetData] Empty key {0} {1}", binAsset.name, j);
  680. continue;
  681. }
  682. if (Row.ContainsKey(indexname[j]))
  683. {
  684. DebugHelper.LogWarning("[ConfigMgr. GetData] {0} {1}", binAsset.name, indexname[j]);
  685. continue;
  686. }
  687. Row.Add(indexname[j], charArray[j]);
  688. }
  689. if (Table.ContainsKey(charArray[0]))
  690. {
  691. DebugHelper.LogWarning("[ConfigMgr. GetData] {0} {1} {2}", binAsset.name, i, lineArray[i - 1]);
  692. continue;
  693. }
  694. Table.Add(charArray[0], Row);
  695. }
  696. return Table;
  697. }
  698. }