2023-12-10 12:28:20 +08:00
|
|
|
|
using System;
|
2023-12-30 14:20:55 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-12-10 12:28:20 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using Script.UI;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using ZXL.ID;
|
|
|
|
|
|
|
|
|
|
namespace Script
|
|
|
|
|
{
|
|
|
|
|
public class TitleInfo
|
|
|
|
|
{
|
|
|
|
|
public string title;
|
|
|
|
|
public string subject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FileManager : SingleManager<FileManager>
|
|
|
|
|
{
|
|
|
|
|
private string dataPath;
|
|
|
|
|
private string titlePath;
|
|
|
|
|
|
|
|
|
|
private TitleInfo titleInfo;
|
|
|
|
|
public TitleInfo GetTitle => titleInfo;
|
|
|
|
|
|
2023-12-30 14:20:55 +08:00
|
|
|
|
// cache
|
|
|
|
|
private string cachePath;
|
|
|
|
|
|
2023-12-10 12:28:20 +08:00
|
|
|
|
public FileManager()
|
|
|
|
|
{
|
2023-12-30 14:20:55 +08:00
|
|
|
|
// data
|
2023-12-26 23:25:22 +08:00
|
|
|
|
dataPath = Application.streamingAssetsPath + $"/TXT/data{GenerateGlobalID.GenerateIntID()}.txt";
|
2023-12-10 12:28:20 +08:00
|
|
|
|
if (!File.Exists(dataPath))
|
|
|
|
|
{
|
|
|
|
|
var fileStream = File.Create(dataPath);
|
|
|
|
|
fileStream.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 14:20:55 +08:00
|
|
|
|
// title
|
2023-12-10 12:28:20 +08:00
|
|
|
|
titlePath = Application.streamingAssetsPath + "/title.txt";
|
|
|
|
|
var text = File.ReadAllLines(titlePath);
|
|
|
|
|
titleInfo = new TitleInfo() { title = text[0], subject = text[1] };
|
2023-12-30 14:20:55 +08:00
|
|
|
|
|
|
|
|
|
// cache
|
|
|
|
|
cachePath = Application.streamingAssetsPath + "/Cache/cache.txt";
|
|
|
|
|
if (!File.Exists(cachePath))
|
|
|
|
|
{
|
|
|
|
|
var fileStream = File.Create(cachePath);
|
|
|
|
|
fileStream.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// cacheBPath = Application.streamingAssetsPath + "/Cache/cache.txt";
|
|
|
|
|
// if (!File.Exists(cacheBPath))
|
|
|
|
|
// {
|
|
|
|
|
// var fileStream = File.Create(cacheBPath);
|
|
|
|
|
// fileStream.Dispose();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// cacheCPath = Application.streamingAssetsPath + "/Cache/cache.txt";
|
|
|
|
|
// if (!File.Exists(cacheCPath))
|
|
|
|
|
// {
|
|
|
|
|
// var fileStream = File.Create(cacheCPath);
|
|
|
|
|
// fileStream.Dispose();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// cacheDPath = Application.streamingAssetsPath + "/Cache/cache.txt";
|
|
|
|
|
// if (!File.Exists(cacheDPath))
|
|
|
|
|
// {
|
|
|
|
|
// var fileStream = File.Create(cacheDPath);
|
|
|
|
|
// fileStream.Dispose();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
Dictionary<QuestionBankType, List<string>> dic = new Dictionary<QuestionBankType, List<string>>();
|
|
|
|
|
var cache = File.ReadAllLines(cachePath);
|
|
|
|
|
foreach (var s in cache)
|
|
|
|
|
{
|
|
|
|
|
var strings = s.Split(":");
|
|
|
|
|
var questionBankType = Enum.Parse<QuestionBankType>(strings[0]);
|
|
|
|
|
if (dic.TryGetValue(questionBankType, out var list))
|
|
|
|
|
list.Add(strings[1]);
|
|
|
|
|
else
|
|
|
|
|
dic.Add(questionBankType, new List<string>() { strings[1] });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GlobalManager.Instance.questionIDs = dic;
|
2023-12-10 12:28:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SavePlayerData(string content)
|
|
|
|
|
{
|
|
|
|
|
var text = File.ReadAllText(dataPath);
|
|
|
|
|
File.WriteAllText(dataPath, text + "\n" + content);
|
|
|
|
|
}
|
2023-12-30 14:20:55 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存已抽题的题目id
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="questionBankType"></param>
|
|
|
|
|
/// <param name="content"></param>
|
|
|
|
|
public void SaveAnsweredData(QuestionBankType questionBankType, string content)
|
|
|
|
|
{
|
|
|
|
|
var text = File.ReadAllText(cachePath);
|
|
|
|
|
var s = questionBankType.ToString() + ":" + content;
|
|
|
|
|
if (text == "")
|
|
|
|
|
File.WriteAllText(cachePath, s);
|
|
|
|
|
else
|
|
|
|
|
File.WriteAllText(cachePath, text + "\n" + s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearAnsweredData()
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(cachePath, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum QuestionBankType
|
|
|
|
|
{
|
|
|
|
|
A,
|
|
|
|
|
B,
|
|
|
|
|
C,
|
|
|
|
|
D
|
|
|
|
|
}
|
2023-12-10 12:28:20 +08:00
|
|
|
|
}
|
|
|
|
|
}
|