using System; using System.Collections.Generic; namespace MoleMole { public class CacheDataUtil { private class DataWrapper { public object _data; public Action _req; public ushort _rspID; public NotifyTypes _notify; } private Dictionary _cacheDataUtilDic = new Dictionary(); public void CreateCacheUtil(ECacheData type, object data, Action req, ushort rspID) { DataWrapper dataWrapper = new DataWrapper(); dataWrapper._data = data; dataWrapper._req = req; dataWrapper._rspID = rspID; dataWrapper._notify = NotifyTypes.None; _cacheDataUtilDic.Add(type, dataWrapper); } public void CheckCacheValidAndGo(ECacheData type, NotifyTypes notify) where T : class { foreach (KeyValuePair item in _cacheDataUtilDic) { if (item.Key == type) { CacheData cacheData = item.Value._data as CacheData; if (cacheData.CacheValid) { Singleton.Instance.FireNotify(new Notify(notify)); break; } item.Value._notify = notify; item.Value._req(); break; } } } public void OnGetRsp(ushort cmdID) { foreach (KeyValuePair item in _cacheDataUtilDic) { if (item.Value._rspID == cmdID) { if (item.Value._notify != NotifyTypes.None) { Singleton.Instance.FireNotify(new Notify(item.Value._notify)); item.Value._notify = NotifyTypes.None; } break; } } } } }