| | |
| | | //-------------------------------------------------------- |
| | | // [Author]: Fish |
| | | // [ Date ]: Wednesday, February 13, 2019 |
| | | // [ Date ]: Thursday, February 14, 2019 |
| | | //-------------------------------------------------------- |
| | | |
| | | using System.Collections.Generic; |
| | |
| | | using System; |
| | | using UnityEngine; |
| | | |
| | | [XLua.LuaCallCSharp] |
| | | public partial class MapEventPointConfig |
| | | { |
| | | |
| | |
| | | public readonly string Drop1; |
| | | public readonly string Drop2; |
| | | public readonly string EXP; |
| | | |
| | | public MapEventPointConfig() |
| | | { |
| | | } |
| | | |
| | | public MapEventPointConfig(string input) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | static Dictionary<int, MapEventPointConfig> configs = new Dictionary<int, MapEventPointConfig>(); |
| | | public static MapEventPointConfig Get(int id) |
| | | static Dictionary<string, MapEventPointConfig> configs = new Dictionary<string, MapEventPointConfig>(); |
| | | public static MapEventPointConfig Get(string id) |
| | | { |
| | | if (!inited) |
| | | { |
| | |
| | | return config; |
| | | } |
| | | |
| | | public static bool Has(int id) |
| | | public static MapEventPointConfig Get(int id) |
| | | { |
| | | return Get(id.ToString()); |
| | | } |
| | | |
| | | public static List<string> GetKeys() |
| | | { |
| | | var keys = new List<string>(); |
| | | keys.AddRange(configs.Keys); |
| | | keys.AddRange(rawDatas.Keys); |
| | | return keys; |
| | | } |
| | | |
| | | public static List<MapEventPointConfig> GetValues() |
| | | { |
| | | var values = new List<MapEventPointConfig>(); |
| | | values.AddRange(configs.Values); |
| | | |
| | | var keys = new List<string>(rawDatas.Keys); |
| | | foreach (var key in keys) |
| | | { |
| | | values.Add(Get(key)); |
| | | } |
| | | |
| | | return values; |
| | | } |
| | | |
| | | public static bool Has(string id) |
| | | { |
| | | return configs.ContainsKey(id) || rawDatas.ContainsKey(id); |
| | | } |
| | | |
| | | public static bool Has(int id) |
| | | { |
| | | return Has(id.ToString()); |
| | | } |
| | | |
| | | public static bool inited { get; private set; } |
| | | protected static Dictionary<int, string> rawDatas = null; |
| | | protected static Dictionary<string, string> rawDatas = new Dictionary<string, string>(); |
| | | public static void Init(bool sync=false) |
| | | { |
| | | inited = false; |
| | |
| | | path = AssetVersionUtility.GetAssetFilePath("config/MapEventPoint.txt"); |
| | | } |
| | | |
| | | var tempConfig = new MapEventPointConfig(); |
| | | var preParse = tempConfig is IConfigPostProcess; |
| | | |
| | | if (sync) |
| | | { |
| | | var lines = File.ReadAllLines(path); |
| | | rawDatas = new Dictionary<int, string>(lines.Length - 3); |
| | | if (!preParse) |
| | | { |
| | | rawDatas = new Dictionary<string, string>(lines.Length - 3); |
| | | } |
| | | for (int i = 3; i < lines.Length; i++) |
| | | { |
| | | var line = lines[i]; |
| | | var index = line.IndexOf("\t"); |
| | | var idString = line.Substring(0, index); |
| | | var id = int.Parse(idString); |
| | | try |
| | | { |
| | | var line = lines[i]; |
| | | var index = line.IndexOf("\t"); |
| | | if (index == -1) |
| | | { |
| | | continue; |
| | | } |
| | | var id = line.Substring(0, index); |
| | | |
| | | rawDatas[id] = line; |
| | | if (preParse) |
| | | { |
| | | var config = new MapEventPointConfig(line); |
| | | configs[id] = config; |
| | | (config as IConfigPostProcess).OnConfigParseCompleted(); |
| | | } |
| | | else |
| | | { |
| | | rawDatas[id] = line; |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.LogError(ex); |
| | | } |
| | | } |
| | | inited = true; |
| | | } |
| | |
| | | ThreadPool.QueueUserWorkItem((object _object) => |
| | | { |
| | | var lines = File.ReadAllLines(path); |
| | | rawDatas = new Dictionary<int, string>(lines.Length - 3); |
| | | if (!preParse) |
| | | { |
| | | rawDatas = new Dictionary<string, string>(lines.Length - 3); |
| | | } |
| | | for (int i = 3; i < lines.Length; i++) |
| | | { |
| | | var line = lines[i]; |
| | | var index = line.IndexOf("\t"); |
| | | var idString = line.Substring(0, index); |
| | | var id = int.Parse(idString); |
| | | try |
| | | { |
| | | var line = lines[i]; |
| | | var index = line.IndexOf("\t"); |
| | | if (index == -1) |
| | | { |
| | | continue; |
| | | } |
| | | var id = line.Substring(0, index); |
| | | |
| | | rawDatas[id] = line; |
| | | if (preParse) |
| | | { |
| | | var config = new MapEventPointConfig(line); |
| | | configs[id] = config; |
| | | (config as IConfigPostProcess).OnConfigParseCompleted(); |
| | | } |
| | | else |
| | | { |
| | | rawDatas[id] = line; |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Debug.LogError(ex); |
| | | } |
| | | } |
| | | |
| | | inited = true; |