DressUpConfigUtil.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using UnityEngine;
  5. using static GFGGame.ConfigUtil;
  6. namespace GFGGame
  7. {
  8. public class DressUpConfigUtil
  9. {
  10. private static int loadCount;
  11. public static int LoadCount { get => loadCount; set => loadCount = value; }
  12. //多列值查询多个数据
  13. public static async Task GetCfgsAsync<T>(string tableName, string[] colNames, string[] colValues, Dictionary<string, List<T>> cfgsDic, HandleCfgInGroupAction<T> action = null) where T : ICfg, new()
  14. {
  15. string key = string.Join("_", colValues);
  16. List<T> cfgs = null;
  17. if (cfgsDic != null && cfgsDic.ContainsKey(key))
  18. {
  19. cfgs = cfgsDic[key];
  20. return;
  21. }
  22. cfgs = new List<T>();
  23. SQLiteHelper.Instance.OpenConnection();
  24. int count = 0;
  25. try
  26. {
  27. var reader = SQLiteHelper.Instance.ReadTable(tableName, colNames, colValues);
  28. while (reader.Read())
  29. {
  30. var cfg = new T();
  31. cfg.setData(reader);
  32. cfgs.Add(cfg);
  33. action?.Invoke(cfg);
  34. ItemCfg itemCfg = cfg as ItemCfg;
  35. if (itemCfg.isHide != 0)
  36. {
  37. continue;
  38. }
  39. ++count;
  40. ++LoadCount;
  41. if (count == 5)
  42. {
  43. count = 0;
  44. await Task.Delay(1);
  45. }
  46. }
  47. if (cfgsDic != null)
  48. {
  49. cfgsDic.Add(key, cfgs);
  50. }
  51. }
  52. catch (System.Exception e)
  53. {
  54. ET.Log.Error(e);
  55. }
  56. finally
  57. {
  58. SQLiteHelper.Instance.CloseConnection();
  59. }
  60. }
  61. }
  62. }