12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Newtonsoft.Json;
- using System.IO;
- /* EnviromentController类主要功能是操作EnviromentSetting类,包含初始化数据,设置语言等 */
- public class EnviromentController : MonoBehaviour
- {
- // Start is called before the first frame update
- //private string logFilePath;
- void Awake()
- {
- InitialGameEnviroment();
- // 启动log功能
- //logFilePath = Path.Combine(Application.persistentDataPath, "game_log.txt");
- //Application.logMessageReceived += LogMessage;
- //Debug.Log("日志系统已启动,日志将保存到: " + logFilePath);
- }
- void Start()
- {
- // todo 开发代码,加载狗的信息,以后要移到ProgressBar页面
- //DogProperty puppy_1 = new();
- //UserProperty.dogs.Add(puppy_1);
- }
- public static void InitialGameEnviroment()
- {
- // 读取language.json
- string filePath = EnviromentSetting.langFilePath;
- string json = File.ReadAllText(filePath);
- EnviromentSetting.languageData = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
- // 读取系统语言
- string systemLanguage = Application.systemLanguage.ToString();
- if (systemLanguage == "ChineseSimplified")
- {
- EnviromentSetting.languageCode = "zh-cn";
- }
- // 默认语言为en
- // 读取操作系统,unique Id,版本
- EnviromentSetting.platform = Application.platform.ToString();
- EnviromentSetting.UUID = SystemInfo.deviceUniqueIdentifier;
- EnviromentSetting.version = Application.version.ToString();
- // 读取Dogbreeds 数据
- DogBreedController.LoadDogBreed();
- }
- //void LogMessage(string condition, string stackTrace, LogType type)
- //{
- // string logEntry = $"[{System.DateTime.Now}] [{type}] {condition}\n{stackTrace}\n";
- // File.AppendAllText(logFilePath, logEntry);
- //}
- void OnDestroy()
- {
- // 关闭log系统
- //Application.logMessageReceived -= LogMessage;
- }
- // Update is called once per frame
- //void Update()
- //{
- //}
- }
|