using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /* 本文件中包含2各类文件 * UserProperty用于保存用户游戏中的相关数据 * GameRunningData 保存游戏中全局的数据 */ [System.Serializable] public static class UserProperty { // Start is called before the first frame update public static string userId; public static string name = "任天堂"; public static int coin = 1005; public static string email, mobile, level; public static bool isRegUser = false; public static int advWatchTimes = 0; // 记录用户当天一共看过几次广告 //public static List food = new(); //public static List toy = new(); //public static List other = new(); // 这里dict string对应的是物品大类food, toy, other public static Dictionary food = new(); public static Dictionary toy = new(); public static Dictionary other = new(); public static List dogs = new(); public static string dogNames() { // 获取狗名字列表 List dogNameList = new List(); foreach (var dog in UserProperty.dogs) { dogNameList.Add(dog.dog_name); } string dogNames = string.Join(", ", dogNameList); return dogNames; } // 更新用户信息 public static void FreshUserInfo(Dictionary userInfo) { //UserProperty.userId = userInfo["userId"]; UserProperty.name = userInfo["name"]; UserProperty.coin = int.Parse(userInfo["coin"]); UserProperty.email = userInfo["email"]; UserProperty.mobile = userInfo["mobile"]; UserProperty.level = userInfo["level"]; if (UserProperty.level == "pro") { EnviromentSetting.maxDogQty = 3; } UserProperty.isRegUser = bool.Parse(userInfo["isRegUser"]); } // 更新用户food, toy, other数据 public static void FreshUserItems(string itemsJson) { UserProperty.food.Clear(); UserProperty.toy.Clear(); UserProperty.other.Clear(); Dictionary items = JsonConvert.DeserializeObject>(itemsJson); Dictionary foods = JsonConvert.DeserializeObject>(items["food"].ToString()); Dictionary toys = JsonConvert.DeserializeObject>(items["toy"].ToString()); Dictionary others = JsonConvert.DeserializeObject>(items["other"].ToString()); foreach (var food in foods) { UserProperty.food.Add(food.Key, int.Parse(food.Value.ToString())); } foreach (var toy in toys) { UserProperty.toy.Add(toy.Key, int.Parse(toy.Value.ToString())); } foreach (var other in others) { UserProperty.other.Add(other.Key, int.Parse(other.Value.ToString())); } } // 更新用户名下狗的信息 public static void FreshDogInfo(string dogsJson) { UserProperty.dogs.Clear(); DogProperty[] dogProperties = JsonConvert.DeserializeObject(dogsJson); foreach (var dog in dogProperties) { UserProperty.dogs.Add(dog); } } } // 待删除代码,废弃 // string id 表示具体的物品id,如food_00001 // qty 表示数量 public class Item { public string id; public int qty; public Item(string id, int qty) { this.id = id; this.qty = qty; } }