private static void LoadProductInfo() { string persistPath = Application.persistentDataPath + "/Config/ProductCfg.txt"; if (File.Exists(persistPath)) { string info = File.ReadAllText(persistPath); ProductCfgNormal productcfgnormal = JsonUtility.FromJson <ProductCfgNormal>(info); if (productcfgnormal != null) { foreach (var p in productcfgnormal.Products) { ProductInfosDict[p.ProductID] = p; } } } else { ProductCfg productcfg = Resources.Load <ProductCfg>("Configs/ProductCfg"); if (productcfg != null) { foreach (var p in productcfg.Products) { ProductInfosDict[p.ProductID] = p; } } } }
public static void SaveProductInfo(List <ProductInfo> newInfo) { ProductCfgNormal newCfg = new ProductCfgNormal(); newCfg.Products = newInfo; string info = JsonUtility.ToJson(newCfg); string persistPath = Application.persistentDataPath + "/Config/ProductCfg.txt"; Utility.CreateDir(persistPath); File.WriteAllText(persistPath, info); LoadProductInfo(); }