//============================================ //--4>: // Exported by ExcelConfigExport // // 此代码为工具根据配置自动生成, 请不要修改 // //============================================ using System; using Sog; using System.Collections.Generic; #if UNITY_2019_1_OR_NEWER using GameLogic; #endif public partial class TradeGoodsDescMgr : IConfigManager { //Singleton private static TradeGoodsDescMgr _instance; private static readonly object syslock = new object(); public static TradeGoodsDescMgr Instance { get { if (_instance == null) { lock (syslock) { if (_instance == null) { _instance = new TradeGoodsDescMgr(); }}} return _instance; }} public class ItemData { public TradeGoodsDesc Item; public int Line; public bool ReadAlready; } protected SortedList m_ItemTable = new SortedList(); //for server only, m_readKeyOnly must be false protected SortedList m_ItemDescTable = new SortedList(); public SortedList ItemTable { get { if (m_ItemDescTable.Count == 0) { foreach (var item in m_ItemTable) { m_ItemDescTable.Add(item.Key, item.Value.Item); }} return m_ItemDescTable; } } private TabBinFile m_tbf; //private TabTextFile m_tf; private int m_curAsynKey1; public override bool InitBin(string fileName, byte[] fileContent) { m_ErrorCount = 0; m_ItemTable.Clear(); m_ItemDescTable.Clear(); m_allRead = false; m_curAsynKey1 = 0; m_tbf = new TabBinFile(fileName, fileContent); while (m_tbf.Next()) { ItemData itemData = new ItemData() { Item = new TradeGoodsDesc() }; var item = itemData.Item; if (m_readKeyOnly) {m_tbf.SetCurrentCol(0); } if (item.ReadItemBin(m_tbf, m_readKeyOnly) == false) { TraceLog.Error("Failed to InitBin TabManager:{0}, read line error, line: {1}", this.ToString(), m_tbf.CurrentLine); m_ErrorCount++; continue; } if (m_ItemTable.ContainsKey(item.GetKey1())) { TraceLog.Error("Failed to InitBin TabManager:{0}, multi key:{1}, line: {2}", this.ToString(), item.GetKey1(), m_tbf.CurrentLine); m_ErrorCount++; continue; } m_ItemTable.Add(item.GetKey1(), itemData); if (m_readKeyOnly) { itemData.Line = m_tbf.CurrentLine; } else { itemData.ReadAlready = true; } } if (!m_readKeyOnly) { m_tbf = null; } return true; } #if UNITY_2019_1_OR_NEWER public override bool InitBinByIL(string fileName, byte[] fileContent) { m_ErrorCount = 0; m_ItemTable.Clear(); m_tbf = new TabBinFile(fileName, fileContent); while (m_tbf.Next()) { ItemData itemData = new ItemData() { Item = new TradeGoodsDesc() }; int keyCount = 0; if(m_readKeyOnly) { keyCount = 1;} var item = itemData.Item; item = item.ReadItemInIL(m_tbf, keyCount); if (item == null) { TraceLog.Error("Failed to init TabManager:{0}, read line error, line: {1}", this.ToString(), m_tbf.CurrentLine); m_ErrorCount++; continue; } if (m_ItemTable.ContainsKey(item.GetKey1())) { TraceLog.Error("Failed to init TabManager:{0}, multi key:{1}, line: {2}", this.ToString(), item.GetKey1(), m_tbf.CurrentLine); m_ErrorCount++; continue; } m_ItemTable.Add(item.GetKey1(), itemData); if (m_readKeyOnly) { itemData.Line = m_tbf.CurrentLine; } else { itemData.ReadAlready = true; } } return true; } #endif public TradeGoodsDesc GetConfig(int key) { ItemData itemData; if (m_ItemTable.TryGetValue(key, out itemData) == false) { return null; } if(itemData.ReadAlready) { return itemData.Item; } if (m_tbf == null) { TraceLog.Error("Cfg1KeyMgrTemplate.GetConfig Failed fs null TabManager:{ 0}, read line error,", this.ToString()); return null; } m_tbf.SetCurrentLine(itemData.Line); m_tbf.SetCurrentCol(0); itemData.ReadAlready = true; if (itemData.Item.ReadItemBin(m_tbf, false) == false) { TraceLog.Error("Cfg1KeyMgrTemplate.GetConfig Failed to init TabManager:{0}, read line error, line: {1}", this.ToString(), m_tbf.CurrentLine); return null; } return itemData.Item; } public override int AsynReadBin(int maxTimes) { int times = 0; if (m_allRead) { return times; } if (m_tbf == null) { return times; } for (; m_curAsynKey1 < m_ItemTable.Count && times < maxTimes; m_curAsynKey1++) { var itemData = m_ItemTable.Values[m_curAsynKey1]; if (itemData.ReadAlready) { continue; } m_tbf.SetCurrentLine(itemData.Line); m_tbf.SetCurrentCol(0); itemData.ReadAlready = true; if (itemData.Item.ReadItemBin(m_tbf, false) == false) { TraceLog.Error("Cfg1KeyMgrTemplate.AsynReadBin Failed to init TabManager:{ 0}, read line error, line: { 1}", this.ToString(), m_tbf.CurrentLine); return times; } times++; } if (m_curAsynKey1 >= m_ItemTable.Count) { m_allRead = true; m_tbf = null; } return times; } } public partial class TradeGoodsDesc { public static readonly string _KEY_id = "id"; public static readonly string _KEY_weight = "weight"; public static readonly string _KEY_price_2_0 = "price_2_0"; public static readonly string _KEY_price_2_1 = "price_2_1"; public int id { get; set; } // //id public int weight { get; set; } // //货物随机权重 public int[] price { get; set; } // //货物价格左区间 public Dictionary listDic = new Dictionary(); public TradeGoodsDesc() { price = new int[2]; listDic.Add("price", typeof(int)); } public int GetKey1() { return id; } public bool ReadItem(TabTextFile txf, bool readKeyOnly) { id = txf.Get(_KEY_id); if(readKeyOnly) { return true; } weight = txf.Get(_KEY_weight); price[0] = txf.Get(_KEY_price_2_0); price[1] = txf.Get(_KEY_price_2_1); return true; } public bool ReadItemBin(TabBinFile txf, bool readKeyOnly) { id = txf.GetintByIndex(_KEY_id); if(readKeyOnly) { return true; } weight = txf.GetintByIndex(_KEY_weight); price[0] = txf.GetintByIndex(_KEY_price_2_0); price[1] = txf.GetintByIndex(_KEY_price_2_1); return true; } #if UNITY_2019_1_OR_NEWER public TradeGoodsDesc ReadItemInIL(TabBinFile txf ,int keyCount = 0) { byte[] ret = txf.GetLength(); if (ret.Length == 0) { return null; } return SerializeObj.ConfigDeSerialize(this, ret, txf.ColPosList, txf.listPosList, this.listDic, txf.m_stringBlock, keyCount); } #endif }