[Fix] Code visual

This commit is contained in:
2026-02-28 19:25:26 +07:00
parent bee20fd1f8
commit e24b30743b
39 changed files with 2611 additions and 2687 deletions
+14 -15
View File
@@ -3,20 +3,19 @@ using System.Collections.Generic;
namespace YachtDice.Persistence
{
[Serializable]
public sealed class SaveData
{
public int Version = 1;
public int Currency;
public List<ModifierSaveEntry> OwnedModifiers = new();
}
[Serializable]
public sealed class SaveData
{
public int Version = 1;
public int Currency;
public List<ModifierSaveEntry> OwnedModifiers = new();
}
[Serializable]
public sealed class ModifierSaveEntry
{
public string ModifierId;
public bool IsActive;
public int RemainingUses;
}
[Serializable]
public sealed class ModifierSaveEntry
{
public string ModifierId;
public bool IsActive;
public int RemainingUses;
}
}
+32 -33
View File
@@ -3,44 +3,43 @@ using UnityEngine;
namespace YachtDice.Persistence
{
public static class SaveSystem
{
private const string SaveKey = "YachtDice_SaveData";
public static void Save(SaveData data)
public static class SaveSystem
{
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
PlayerPrefs.SetString(SaveKey, json);
PlayerPrefs.Save();
}
private const string SaveKey = "YachtDice_SaveData";
public static SaveData Load()
{
if (!PlayerPrefs.HasKey(SaveKey))
return new SaveData();
string json = PlayerPrefs.GetString(SaveKey);
try
public static void Save(SaveData data)
{
return JsonConvert.DeserializeObject<SaveData>(json) ?? new SaveData();
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
PlayerPrefs.SetString(SaveKey, json);
PlayerPrefs.Save();
}
catch (JsonException e)
public static SaveData Load()
{
Debug.LogWarning($"Failed to deserialize save data, returning default: {e.Message}");
return new SaveData();
if (!PlayerPrefs.HasKey(SaveKey))
return new SaveData();
string json = PlayerPrefs.GetString(SaveKey);
try
{
return JsonConvert.DeserializeObject<SaveData>(json) ?? new SaveData();
}
catch (JsonException e)
{
Debug.LogWarning($"Failed to deserialize save data, returning default: {e.Message}");
return new SaveData();
}
}
public static void Delete()
{
PlayerPrefs.DeleteKey(SaveKey);
}
public static bool HasSave()
{
return PlayerPrefs.HasKey(SaveKey);
}
}
public static void Delete()
{
PlayerPrefs.DeleteKey(SaveKey);
}
public static bool HasSave()
{
return PlayerPrefs.HasKey(SaveKey);
}
}
}