EnviromentController.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Newtonsoft.Json;
  5. using System.IO;
  6. using UnityEngine.Networking;
  7. using System;
  8. /* EnviromentController类主要功能是操作EnviromentSetting类,包含初始化数据,设置语言等 */
  9. public class EnviromentController : MonoBehaviour
  10. {
  11. // Start is called before the first frame update
  12. void Awake()
  13. {
  14. InitialGameEnviroment();
  15. }
  16. void Start()
  17. {
  18. // todo 开发代码,加载狗的信息,以后要移到ProgressBar页面
  19. DogProperty puppy_1 = new();
  20. UserProperty.dogs.Add(puppy_1);
  21. }
  22. public static void InitialGameEnviroment()
  23. {
  24. // 读取language.json
  25. string filePath = EnviromentSetting.langFilePath;
  26. string json = File.ReadAllText(filePath);
  27. EnviromentSetting.languageData = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
  28. // 读取系统语言
  29. string systemLanguage = Application.systemLanguage.ToString();
  30. if (systemLanguage == "ChineseSimplified")
  31. {
  32. EnviromentSetting.languageCode = "zh-cn";
  33. }
  34. // 默认语言为en
  35. // 读取操作系统,unique Id
  36. EnviromentSetting.platform = Application.platform.ToString();
  37. EnviromentSetting.UUID = SystemInfo.deviceUniqueIdentifier;
  38. // 读取Dogbreeds 数据
  39. DogBreedController.LoadDogBreed();
  40. }
  41. // Update is called once per frame
  42. //void Update()
  43. //{
  44. //}
  45. }