1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Newtonsoft.Json;
- using System.IO;
- using Unity.VisualScripting.FullSerializer;
- /* 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 jsonText = File.ReadAllText(filePath);
- // 正确的方式(跨平台工作)
- string jsonText = string.Empty;
- TextAsset textAsset = Resources.Load<TextAsset>(filePath);
- if (textAsset != null)
- {
- jsonText = textAsset.text;
- // 处理JSON数据
- }
- else
- {
- Debug.LogError("无法加载语言文件!");
- }
- EnviromentSetting.languageData = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonText);
- // 读取系统语言
- 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()
- //{
- //}
- }
|