实现 P2 槽位/落盘层核心: - SlotTypes:槽位常量、sidecar 元数据、UI 视图模型 - SlotFileSystem:槽位路径工具与原子写 - SlotManager:自动档、手动档、读档、继续游戏、P1 迁移 - SlotThumbnailCapture:存档截图 helper - CloudSave:Steam/TapTap 云存档适配器接口与协调器 在 ConstRef 中补充槽位、截图、文件名常量。
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using AibisDream.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.SaveSystem
|
|
{
|
|
/// <summary>
|
|
/// 存档槽位缩略图捕获工具。
|
|
/// <para>
|
|
/// 使用主相机渲染到 RenderTexture 后读像素并编码为 PNG。
|
|
/// 捕获失败时安全返回 null,不会阻塞存档流程。
|
|
/// </para>
|
|
/// </summary>
|
|
public static class SlotThumbnailCapture
|
|
{
|
|
/// <summary>捕获当前画面的 PNG 字节数组。</summary>
|
|
public static byte[] CapturePng()
|
|
{
|
|
var cam = Camera.main;
|
|
if (cam == null)
|
|
{
|
|
Debug.LogWarning("[SlotThumbnailCapture] 未找到 Camera.main,跳过截图。");
|
|
return null;
|
|
}
|
|
|
|
var width = ConstRef.SaveThumbnailWidth;
|
|
var height = ConstRef.SaveThumbnailHeight;
|
|
|
|
var rt = RenderTexture.GetTemporary(width, height, 24, RenderTextureFormat.Default);
|
|
var prevTarget = cam.targetTexture;
|
|
cam.targetTexture = rt;
|
|
cam.Render();
|
|
cam.targetTexture = prevTarget;
|
|
|
|
RenderTexture.active = rt;
|
|
var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
|
|
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
|
tex.Apply();
|
|
RenderTexture.active = null;
|
|
|
|
var bytes = tex.EncodeToPNG();
|
|
|
|
Object.Destroy(tex);
|
|
RenderTexture.ReleaseTemporary(rt);
|
|
|
|
return bytes;
|
|
}
|
|
}
|
|
}
|