1 Star 2 Fork 1

SteveSimon999/Unity 数独,但是波函数坍缩算法

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SaveSystom.cs 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
SteveSimon999 提交于 2023-03-21 19:17 +08:00 . 第一次提交
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public static class SaveSystom
{
#region Json
/// <summary>
/// 保存存档
/// </summary>
/// <param name="saveFileName">存档文件名</param>
/// <param name="data">保存的对象(必须能序列化)</param>
public static void SaveByJson(string saveFileName, object data)
{
var json = JsonUtility.ToJson(data);
// 自动适应各平台的文件保存路径
var path = Path.Combine(Application.persistentDataPath, saveFileName);
try
{
File.WriteAllText(path, json);
#if UNITY_EDITOR
Debug.Log($"文件保存路径:{path}");
#endif
}
catch (System.Exception e)
{
#if UNITY_EDITOR
Debug.LogError($"文件保存失败,路径:{path} \n{e}");
#endif
}
}
/// <summary>
/// 读取存档文件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="saveFileName">存档文件名</param>
/// <returns>如果读取失败返回null</returns>
public static T LoadFromJson<T>(string saveFileName) where T : class
{
var path = Path.Combine(Application.persistentDataPath, saveFileName);
try
{
if (File.Exists(path))
{
var json = File.ReadAllText(path);
return JsonUtility.FromJson<T>(json);
}
#if UNITY_EDITOR
Debug.Log($"文件读取路径:{path}");
#endif
}
catch (System.Exception e)
{
#if UNITY_EDITOR
Debug.LogError($"文件读取失败,路径:{path} \n{e}");
#endif
}
return null;
}
public static void DeleteSaveFile(string saveFileName)
{
var path = Path.Combine(Application.persistentDataPath, saveFileName);
try
{
if (File.Exists(path))
{
File.Delete(path);
}
}
catch (System.Exception e)
{
#if UNITY_EDITOR
Debug.LogError($"文件删除失败,路径:{path} \n{e}");
#endif
}
}
#endregion
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/stevesimon999/unity-sudoku-of-wave-function-collapse.git
git@gitee.com:stevesimon999/unity-sudoku-of-wave-function-collapse.git
stevesimon999
unity-sudoku-of-wave-function-collapse
Unity 数独,但是波函数坍缩算法
master

搜索帮助