Files
YachtDice/Assets/Scripts/Persistence/SaveSystem.cs
T
horooko bee20fd1f8 [Refactor] Add folder-based namespaces to all C# scripts
Wrap all 39 scripts and 6 test files in namespaces matching their folder
structure (e.g. Assets/Scripts/Dice/ → YachtDice.Dice). Add cross-namespace
using directives where types are referenced across modules. Set rootNamespace
in both .asmdef files (YachtDice, YachtDice.Tests).

Namespace mapping:
- YachtDice.Dice — Dice, DiceRoller
- YachtDice.Economy — CurrencyBank
- YachtDice.Game — GameManager, DiceManager, DebugGameInput
- YachtDice.Inventory — InventoryController/Model/SlotView/View
- YachtDice.Modifiers — ModifierData/Effect/Enums/Pipeline/Runtime/Target
- YachtDice.Persistence — SaveData, SaveSystem
- YachtDice.Scoring — CategoryScorer, ScoreResult, ScoringSystem, YachtCategory
- YachtDice.Shop — ShopCatalog/Controller/ItemView/Model/View
- YachtDice.UI — CategoryRowView, DicePanelView, GameController, GameInfoView, ScoreCardView
- YachtDice.Editor — ModifierAssetCreator
- YachtDice.Tests — all test files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 19:06:57 +07:00

47 lines
1.0 KiB
C#

using Newtonsoft.Json;
using UnityEngine;
namespace YachtDice.Persistence
{
public static class SaveSystem
{
private const string SaveKey = "YachtDice_SaveData";
public static void Save(SaveData data)
{
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
PlayerPrefs.SetString(SaveKey, json);
PlayerPrefs.Save();
}
public static SaveData Load()
{
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);
}
}
}