MuharremTozan/Agentic-Duel / .agent/skills/unity-data-persistence
unity-data-persistence
VerifiedRobust 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).
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.3 KB |
| assets/code/FileDataService.cs.txt | markdown | 2.3 KB |
| assets/code/PersistenceCore.cs.txt | markdown | 3.4 KB |
| assets/code/SaveLoadManager.cs.txt | markdown | 1.4 KB |
| assets/code/SaveLoadSystem.cs.txt | markdown | 4.7 KB |
| references/guide.md | markdown | 4.4 KB |
assets/code/FileDataService.cs.txt
View on GitHubusing System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace Standard.Systems.Persistence {
/// <summary>
/// Concrete IDataService that persists GameData as JSON files at
/// Application.persistentDataPath. Swap this with a CloudDataService
/// without touching any other part of the system.
/// </summary>
public class FileDataService : IDataService {
readonly ISerializer serializer;
readonly string dataPath;
readonly string fileExtension;
public FileDataService (ISerializer serializer) {
this.serializer = serializer;
this.dataPath = Application.persistentDataPath;
this.fileExtension = "json";
}
string GetPathToFile (string fileName) =>
Path.Combine(dataPath, string.Concat(fileName, ".", fileExtension));
public void Save (GameData data, bool overwrite = true) {
string path = GetPathToFile(data.Name);
if (!overwrite && File.Exists(path)) {
throw new IOException(
$"[SaveLoad] Save file '{data.Name}.{fileExtension}' already exists.");
}
File.WriteAllText(path, serializer.Serialize(data));
Debug.Log($"[SaveLoad] Status: Game Saved | Data: Name={data.Name}");
}
public GameData Load (string name) {
string path = GetPathToFile(name);
if (!File.Exists(path)) {
throw new ArgumentException(
$"[SaveLoad] No save file found | Data: Name={name}");
}
Debug.Log($"[SaveLoad] Status: Game Loaded | Data: Name={name}");
return serializer.Deserialize<GameData>(File.ReadAllText(path));
}
public void Delete (string name) {
string path = GetPathToFile(name);
if (File.Exists(path)) File.Delete(path);
}
public void DeleteAll () {
foreach (string filePath in Directory.GetFiles(dataPath))
File.Delete(filePath);
}
public IEnumerable<string> ListSaves () {
foreach (string path in Directory.EnumerateFiles(dataPath)) {
if (Path.GetExtension(path) == fileExtension)
yield return Path.GetFileNameWithoutExtension(path);
}
}
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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 implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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 fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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 always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |