mirror of
https://gitee.com/cssfw/EasyTools.git
synced 2026-03-28 12:01:36 +08:00
feat: 玩家数据储存系统(序列化和反序列化部分)
This commit is contained in:
34
DataBase/DataAPI.cs
Normal file
34
DataBase/DataAPI.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using EasyTools.DataBase.Serialization;
|
||||
using EasyTools.Events;
|
||||
using LiteDB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine.LowLevel;
|
||||
|
||||
namespace EasyTools.DataBase
|
||||
{
|
||||
public static class DataAPI
|
||||
{
|
||||
public static List<string> TimerHidden { get; } = [];
|
||||
public static Dictionary<string, PlayerData> PlayerDataDic = [];
|
||||
|
||||
public static bool TryGetData(string id, out PlayerData data)
|
||||
{
|
||||
if (PlayerDataDic.TryGetValue(id, out data))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
using LiteDatabase database = new(CustomEventHandler.DataBaseConfig.database_path);
|
||||
|
||||
if ((data = database.GetCollection<PlayerData>("Players")?.FindById(id)) != null)
|
||||
{
|
||||
PlayerDataDic.Add(id, data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user