123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Newtonsoft.Json;
- using System.IO;
- using Unity.VisualScripting.FullSerializer;
- using System;
- /* EnviromentController类主要功能是操作EnviromentSetting类,包含初始化数据,设置语言等
- * 必须挂载在第一个场景的Camera上
- */
- 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);
- PlayerPrefsLoader();
- }
- 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;
- }
- void PlayerPrefsLoader()
- {
- if (PlayerPrefs.HasKey("lastTrainingDate"))
- {
- // 读取存储的日期
- string lastTrainingDate = PlayerPrefs.GetString("lastTrainingDate");
- string today = System.DateTime.Now.ToString("yyyy-MM-dd");
- if (lastTrainingDate != today)
- {
- // 如果不是同一天,执行相应的操作
- GameData.isVoiceTrainingToday = false;
- }
- else
- {
- GameData.isVoiceTrainingToday = true;
- }
- }
-
- if (PlayerPrefs.HasKey("lastFeedbackTime"))
- {
- // 读取存储的日期
- string lastFeedbackTime = PlayerPrefs.GetString("lastFeedbackTime");
- GameData.lastFeedbackTime = DateTime.Parse(lastFeedbackTime);
- }
- // if (PlayerPrefs.HasKey("isFirstInteraction"))
- // {
- // string isFirstInteraction = PlayerPrefs.GetString("isFirstInteraction");
- // if (isFirstInteraction == "true")
- // {
- // GameData.isFirstInteraction = true;
- // }
- // else
- // {
- // GameData.isFirstInteraction = false;
- // }
- // }
- }
- // Update is called once per frame
- //void Update()
- //{
- //}
- }
|