public static GameKit <TObj> LoadKit <TObj>(string filePath) where TObj : new() { if (File.Exists(filePath)) { GameKit <TObj> kit = new GameKit <TObj>(); string[] allStr = File.ReadAllLines(filePath).Where(str => !string.IsNullOrWhiteSpace(str)).ToArray(); List <string> unitInfo = new List <string>(); bool startBlockInformation = false; foreach (var str in allStr) { if (str.Trim().StartsWith("}")) { startBlockInformation = false; kit.Add(unitInfo); unitInfo.Clear(); } if (startBlockInformation) { unitInfo.Add(str.Trim()); } if (str.Trim().StartsWith("{")) { startBlockInformation = true; } } return(kit); } Console.WriteLine("Файл не найден: {0}!", filePath); return(null); }
public static void SetUp() { weapon = Loader.LoadKit <Weapon>(@".\\PlayerItems\\Weapons\\Weapons.csv"); subjects = Loader.LoadKit <Subject>(@".\cWorld\Models.csv"); potions = Loader.LoadKit <Potion>(@".\\PlayerItems\\Potions\\Potions.csv"); }