public void Set(int id) { DBIconConf iconConf = DBIconTable.GetRecord(id); if (iconConf == null) { return; } sprite.spriteName = iconConf.spriteName; }
//获取记录,如果不存在返回null public static DBIconConf GetRecord(int iconID, bool errorMsg = true) { if (instance == null) { Debug.LogError("表DBIconTable未加载"); return(null); } DBIconConf record = null; if (recordDict.TryGetValue(iconID, out record)) { return(record); } if (errorMsg) { Debug.LogErrorFormat("表DBIconTable没有iconID = {0}的记录", iconID); } return(null); }
public void Init() { //如果recordDict不为null,说明已经初始化了 if (recordDict != null) { return; } recordDict = new Dictionary <int, DBIconConf>(); for (int i = 0; i < recordArray.Length; i++) { DBIconConf record = recordArray[i]; if (!recordDict.ContainsKey(record.iconID)) { recordDict.Add(record.iconID, record); } else { Debug.LogErrorFormat("表DBIconTable有重复的记录,id = {0}", record.iconID); } } }