1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using UnityEngine;
- using static GFGGame.ConfigUtil;
- namespace GFGGame
- {
- public class DressUpConfigUtil
- {
- private static int loadCount;
- public static int LoadCount { get => loadCount; set => loadCount = value; }
- //多列值查询多个数据
- 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()
- {
- string key = string.Join("_", colValues);
- List<T> cfgs = null;
- if (cfgsDic != null && cfgsDic.ContainsKey(key))
- {
- cfgs = cfgsDic[key];
- return;
- }
- cfgs = new List<T>();
- SQLiteHelper.Instance.OpenConnection();
- int count = 0;
- try
- {
- var reader = SQLiteHelper.Instance.ReadTable(tableName, colNames, colValues);
- while (reader.Read())
- {
- var cfg = new T();
- cfg.setData(reader);
- cfgs.Add(cfg);
- action?.Invoke(cfg);
- ItemCfg itemCfg = cfg as ItemCfg;
- if (itemCfg.isHide != 0)
- {
- continue;
- }
- ++count;
- ++LoadCount;
- if (count == 5)
- {
- count = 0;
- await Task.Delay(1);
- }
- }
- if (cfgsDic != null)
- {
- cfgsDic.Add(key, cfgs);
- }
- }
- catch (System.Exception e)
- {
- ET.Log.Error(e);
- }
- finally
- {
- SQLiteHelper.Instance.CloseConnection();
- }
- }
- }
- }
|