保存独立KV用户服务、固定会话存档与原业务接线,以及C3d资料缓存和C3e本人统计写。 保留原PF/AGG路线、业务公式和时序;榜单读取、好友资料、公告、匹配及首场景闸仍待完成。 验证:ServiceHost两条件各33组646断言;Unity CLI Loop编译0错误269警告。 包含相关方案、评审裁决、测试及状态文档。未操作服务器、正式账号或打包。
64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using System;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
|
|
namespace Activity.Data
|
|
{
|
|
/// <summary>
|
|
/// 基于 PlayFab 的数据存储实现
|
|
/// </summary>
|
|
public class EventDataRepository : IEventDataRepository
|
|
{
|
|
private readonly game.PlayerDataStorage.IPlayerSaveStore store;
|
|
public EventDataRepository(game.PlayerDataStorage.IPlayerSaveStore store)
|
|
{ this.store = store ?? throw new ArgumentNullException(nameof(store)); }
|
|
|
|
public void Save<T>(T data) where T : IEventData
|
|
{
|
|
if (data == null)
|
|
{
|
|
Debug.LogWarning($"[EventDataRepository] Cannot save null data for {typeof(T).Name}");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var json = JsonConvert.SerializeObject(data);
|
|
#if UNITY_EDITOR
|
|
Debug.Log($"[EventDataRepository] Saving {typeof(T).Name}: {json}");
|
|
#endif
|
|
store.Write(typeof(T).Name, json).RequireAccepted();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError($"[EventDataRepository] Failed to save {typeof(T).Name}: {e.Message}\n{e.StackTrace}");
|
|
}
|
|
}
|
|
|
|
public T Load<T>() where T : IEventData, new()
|
|
{
|
|
try
|
|
{
|
|
var dataStr = store.Read(typeof(T).Name).ValueOrThrow();
|
|
if (string.IsNullOrEmpty(dataStr)) return new T();
|
|
// #if UNITY_EDITOR
|
|
// Debug.Log($"[EventDataRepository] Load {typeof(T).Name}: {dataStr}");
|
|
// #endif
|
|
var data = JsonConvert.DeserializeObject<T>(dataStr);
|
|
return data ?? new T();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError($"[EventDataRepository] Failed to load {typeof(T).Name}: {e.Message}\n{e.StackTrace}");
|
|
return new T();
|
|
}
|
|
}
|
|
|
|
public bool Exists<T>() where T : IEventData
|
|
{
|
|
var dataStr = store.Read(typeof(T).Name).ValueOrThrow();
|
|
return !string.IsNullOrEmpty(dataStr);
|
|
}
|
|
}
|
|
}
|