123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using Newtonsoft.Json;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using UnityEngine;
- /* 本文件中包含2各类文件
- * UserProperty用于保存用户游戏中的相关数据
- * GameRunningData 保存游戏中全局的数据 */
- [System.Serializable]
- public static class UserProperty
- {
- // Start is called before the first frame update
- public static string userId = "JTYNZP9O";
- 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<Item> food = new();
- //public static List<Item> toy = new();
- //public static List<Item> other = new(); // 这里dict string对应的是物品大类food, toy, other
- public static Dictionary<string, int> food = new();
- public static Dictionary<string, int> toy = new();
- public static Dictionary<string, int> other = new();
- public static List<DogProperty> dogs = new();
- public static string runEnv = "Release"; // NA, Dev, Release
- public static string dogNames()
- {
- // 获取狗名字列表
- List<string> dogNameList = new List<string>();
- foreach (var dog in UserProperty.dogs)
- {
- dogNameList.Add(dog.dog_name);
- }
- string dogNames = string.Join(", ", dogNameList);
- return dogNames;
- }
- // 更新用户信息
- public static void RefreshUserInfo(string userInfoJson)
- {
- Dictionary<string, string> userInfo = JsonConvert.DeserializeObject<Dictionary<string, string>>(userInfoJson);
- UserProperty.name = userInfo["user_name"];
- UserProperty.coin = int.Parse(userInfo["coin"]);
- UserProperty.email = userInfo["email"];
- UserProperty.mobile = userInfo["mobile"];
- UserProperty.level = userInfo["level"];
- if (UserProperty.level == "basic") { EnviromentSetting.maxDogQty = 2; }
- if (UserProperty.level == "pro") { EnviromentSetting.maxDogQty = 3; }
- UserProperty.isRegUser = bool.Parse(userInfo["isRegUser"]);
- }
- // 更新用户food, toy, other数据
- public static void RefreshUserItems(string itemsJson)
- {
- UserProperty.food.Clear();
- UserProperty.toy.Clear();
- UserProperty.other.Clear();
- // 保存道具数据
- Dictionary<string, object> props = JsonConvert.DeserializeObject<Dictionary<string, object>>(itemsJson);
- Dictionary<string, int> foods = JsonConvert.DeserializeObject<Dictionary<string, int>>(props["food"].ToString());
- Dictionary<string, int> toys = JsonConvert.DeserializeObject<Dictionary<string, int>>(props["toy"].ToString());
- Dictionary<string, int> others = JsonConvert.DeserializeObject<Dictionary<string, int>>(props["other"].ToString());
- foreach (var food in foods)
- UserProperty.food.Add(food.Key, food.Value);
- foreach (var toy in toys)
- UserProperty.toy.Add(toy.Key, toy.Value);
- foreach (var other in others)
- UserProperty.other.Add(other.Key, other.Value);
- }
- // 更新用户名下狗的信息
- public static void RefreshDogInfo(string dogsJson)
- {
- UserProperty.dogs.Clear();
- DogProperty[] dogProperties = JsonConvert.DeserializeObject<DogProperty[]>(dogsJson);
- foreach (var dog in dogProperties)
- {
- UserProperty.dogs.Add(dog);
- }
- }
- // 用Dog id搜索Gamedata.focusDog的下标
- public static int GetDogIndexById(string dogId)
- {
- for (int i = 0; i < UserProperty.dogs.Count; i++)
- {
- if (UserProperty.dogs[i].d_id == dogId)
- {
- return i;
- }
- }
- return -1;
- }
- // 用Gamedata.focusDog的下标获取Dog id
- public static string GetDogIdByIndex(int dogIndex)
- {
- if (dogIndex < 0 || dogIndex >= UserProperty.dogs.Count)
- {
- return null;
- }
- return UserProperty.dogs[dogIndex].d_id;
- }
- }
- // 待删除代码,废弃
- // 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;
- }
- }
|