This commit is contained in:
JA
2026-06-20 19:34:23 +08:00
parent e5031c0068
commit d442805c3f
4136 changed files with 514641 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public static class SaveSystem
{
public static bool IsHaveFile(string FilePath)
{
if (File.Exists(FilePath))
return true;
else
return false;
}
public static void CreateFile(string FilePath, bool IfHaveFileIsCreate = false)
{
if (!File.Exists(FilePath))
{
File.CreateText(FilePath);
}
}
public static void SaveDate(string fileName, object date)
{
var json = JsonUtility.ToJson(date);
string path = Path.Combine(Application.persistentDataPath, fileName);
if (!IsHaveFile(path))
{
//Debug.Log("文件不存在");
CreateFile(path);
}
try
{
File.WriteAllText(path, json);
Debug.Log("存档成功");
}
catch (Exception)
{
Debug.Log("存档创建失败");
SaveDate(fileName,date);
}
}
public static T LoadDate<T>(string fileName)
{
var path = Path.Combine(Application.persistentDataPath, fileName);
if (IsHaveFile(path))
{
var json = File.ReadAllText(path);
T date = JsonUtility.FromJson<T>(json);
Debug.Log("读档成功}");
return date;
}
return default;
}
public static void DeleteDate(string fileName)
{
var path = Path.Combine(Application.persistentDataPath, fileName);
if (!IsHaveFile(path))
{
return;//不存在
}
File.Delete(path);
Debug.Log("删除成功");
}
}