EnviromentController.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Newtonsoft.Json;
  5. using System.IO;
  6. /* EnviromentController类主要功能是操作EnviromentSetting类,包含初始化数据,设置语言等 */
  7. public class EnviromentController : MonoBehaviour
  8. {
  9. // Start is called before the first frame update
  10. //private string logFilePath;
  11. void Awake()
  12. {
  13. InitialGameEnviroment();
  14. // 启动log功能
  15. //logFilePath = Path.Combine(Application.persistentDataPath, "game_log.txt");
  16. //Application.logMessageReceived += LogMessage;
  17. //Debug.Log("日志系统已启动,日志将保存到: " + logFilePath);
  18. }
  19. void Start()
  20. {
  21. // todo 开发代码,加载狗的信息,以后要移到ProgressBar页面
  22. //DogProperty puppy_1 = new();
  23. //UserProperty.dogs.Add(puppy_1);
  24. }
  25. public static void InitialGameEnviroment()
  26. {
  27. // 读取language.json
  28. string filePath = EnviromentSetting.langFilePath;
  29. string json = File.ReadAllText(filePath);
  30. EnviromentSetting.languageData = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
  31. // 读取系统语言
  32. string systemLanguage = Application.systemLanguage.ToString();
  33. if (systemLanguage == "ChineseSimplified")
  34. {
  35. EnviromentSetting.languageCode = "zh-cn";
  36. }
  37. // 默认语言为en
  38. // 读取操作系统,unique Id,版本
  39. EnviromentSetting.platform = Application.platform.ToString();
  40. EnviromentSetting.UUID = SystemInfo.deviceUniqueIdentifier;
  41. EnviromentSetting.version = Application.version.ToString();
  42. // 读取Dogbreeds 数据
  43. DogBreedController.LoadDogBreed();
  44. }
  45. //void LogMessage(string condition, string stackTrace, LogType type)
  46. //{
  47. // string logEntry = $"[{System.DateTime.Now}] [{type}] {condition}\n{stackTrace}\n";
  48. // File.AppendAllText(logFilePath, logEntry);
  49. //}
  50. void OnDestroy()
  51. {
  52. // 关闭log系统
  53. //Application.logMessageReceived -= LogMessage;
  54. }
  55. // Update is called once per frame
  56. //void Update()
  57. //{
  58. //}
  59. }