Skip to content

MuharremTozan/Agentic-Duel / .agent/skills/unity-data-persistence

unity-data-persistence

Verified

Robust Save/Load system using Data Binding, Serializable DTOs, and swappable Data Service backends (File/JSON default). Supports per-entity GUID identity for saving multiple actors (player, inventory, enemies).

assets/code/SaveLoadManager.cs.txt

View on GitHub
using UnityEngine;
using Standard.Patterns.Singleton; // Assumes previous skill is available

namespace Standard.Systems.Persistence {
    [System.Serializable]
    public class GameData {
        public string PlayerName;
        public int LastLevelIndex;
        public Vector3 PlayerPosition;
    }

    /// <summary>
    /// Central manager for saving and loading game state.
    /// Inherits from PersistentSingleton to ensure availability across scenes.
    /// </summary>
    public class SaveLoadManager : PersistentSingleton<SaveLoadManager> {
        private IDataService dataService;
        public GameData CurrentData { get; private set; }

        protected override void Awake() {
            base.Awake();
            // Defaulting to File/JSON setup
            dataService = new FileDataService(new JsonSerializer());
            CurrentData = new GameData();
        }

        public void SaveGame(string saveName = "DefaultSave") {
            dataService.Save(saveName, CurrentData);
            Debug.Log($"[SaveLoad] Status: Game Saved | Data: {saveName}");
        }

        public void LoadGame(string saveName = "DefaultSave") {
            var loadedData = dataService.Load<GameData>(saveName);
            if (loadedData != null) {
                CurrentData = loadedData;
                Debug.Log($"[SaveLoad] Status: Game Loaded | Data: {saveName}");
            }
        }
    }
}
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 321kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 321kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 321kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 321kUpdated Claude CodeCodexVerifiedInstall