chore: initialize standalone UPM package
Publish UPM package / publish (push) Failing after 1s

This commit is contained in:
2026-08-26 02:50:03 +08:00
commit 739fe328e7
63 changed files with 4243 additions and 0 deletions
+135
View File
@@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace ShrinkDataSaver
{
[Serializable]
public class SaveMeta
{
public int SlotIndex { get; set; }
public string SlotName { get; set; } = "New Save";
public int SaveVersion { get; set; } = 1;
public long LastModified { get; set; }
public float PlaytimeSeconds { get; set; }
public string ScreenshotBase64 { get; set; }
public bool IsEncrypted { get; set; }
[JsonIgnore]
public DateTime LastModifiedTime => DateTimeOffset.FromUnixTimeSeconds(LastModified).LocalDateTime;
}
[Serializable]
internal class SavePacket
{
public SaveMeta Meta { get; set; }
public Dictionary<string, JToken> Modules { get; set; } = new();
public string EncryptedModules { get; set; }
}
public interface ISaveModule
{
string Key { get; }
object SerializeRaw();
void DeserializeRaw(JToken data);
}
public interface ISaveModule<T> : ISaveModule
{
T Serialize();
void Deserialize(T data);
object ISaveModule.SerializeRaw() => Serialize();
void ISaveModule.DeserializeRaw(JToken data) => Deserialize(data.ToObject<T>());
}
internal class LambdaSaveModule<T> : ISaveModule<T>
{
public string Key { get; }
private readonly Func<T> _serialize;
private readonly Action<T> _deserialize;
public LambdaSaveModule(string key, Func<T> serialize, Action<T> deserialize)
{
Key = key; _serialize = serialize; _deserialize = deserialize;
}
public T Serialize() => _serialize();
public void Deserialize(T data) => _deserialize(data);
}
public class SaveOptions
{
public string SlotName = "New Save";
public bool CaptureScreenshot = false;
public UnityEngine.Texture2D Screenshot = null;
public bool Encrypt = false;
public string EncryptionKey = null;
}
public class ModuleConfig
{
/// <summary>是否参与云存档同步(设置模块应设为 false</summary>
public bool EnableCloudSync { get; set; } = true;
/// <summary>自动保存间隔(秒),0 表示不自动保存</summary>
public float AutoSaveIntervalSeconds { get; set; } = 0f;
/// <summary>是否为关键模块(关键模块序列化失败将中止整个保存操作)</summary>
public bool CriticalModule { get; set; } = false;
}
public class SaveStartedEventArgs
{
public int SlotIndex { get; set; }
public long Timestamp { get; set; }
}
public class SaveCompletedEventArgs
{
public int SlotIndex { get; set; }
public string[] ModuleNames { get; set; }
public long Timestamp { get; set; }
}
public class SaveFailedEventArgs
{
public int SlotIndex { get; set; }
public string ErrorMessage { get; set; }
}
public class LoadStartedEventArgs
{
public int SlotIndex { get; set; }
public long Timestamp { get; set; }
}
public class LoadCompletedEventArgs
{
public int SlotIndex { get; set; }
public string[] ModuleNames { get; set; }
public int Version { get; set; }
public long Timestamp { get; set; }
}
public class LoadFailedEventArgs
{
public int SlotIndex { get; set; }
public string ErrorMessage { get; set; }
}
public class MigrationCompletedEventArgs
{
public int SlotIndex { get; set; }
public int FromVersion { get; set; }
public int ToVersion { get; set; }
}
public class SlotDeletedEventArgs
{
public int SlotIndex { get; set; }
}
}