오늘부터는 개인프로젝트의 도전과제를 진행하게 되었습니다.
그에 따라 구현을 완료한 기능은 아래와 같습니다.



using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class DataManager : MonoBehaviour
{
public static DataManager instance;
private void Awake()
{
if (instance == null)
instance = this;
}
public void Save(List<string> animatorAddresses, string savePath)
{
Debug.Log(savePath);
var dataList = new AnimatorSaveDataList();
foreach (var addr in animatorAddresses)
dataList.animators.Add(new AnimatorSaveData { animatorAddress = addr });
string json = JsonUtility.ToJson(dataList, true);
File.WriteAllText(savePath, json);
}
public void Load( List<Animator> targetAnimators, string savePath)
{
if (!File.Exists(savePath))
{
Debug.LogWarning("저장 파일이 없습니다.");
return;
}
string json = File.ReadAllText(savePath);
var dataList = JsonUtility.FromJson<AnimatorSaveDataList>(json);
if (dataList.animators.Count != targetAnimators.Count)
{
Debug.LogError("Animator 개수 불일치");
return;
}
for (int i = 0; i < dataList.animators.Count; i++)
{
int index = i;
string addr = dataList.animators[i].animatorAddress;
Addressables.LoadAssetAsync<RuntimeAnimatorController>(addr).Completed += handle =>
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
targetAnimators[index].runtimeAnimatorController = handle.Result;
}
else
{
Debug.LogError($"Animator {index} 로드 실패: {addr}");
}
};
}
}
}

using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class DialogueEntry
{
public string key;
[TextArea]
public string text;
}
[CreateAssetMenu(menuName = "Data/NPCDialogue")]
public class DialogueData : ScriptableObject
{
public string npcId;
public List<DialogueEntry> data;
}

Unity에서 자주 사용되는 데이터 저장 및 관리 방식에는 ScriptableObject, JSON, Addressables가 있습니다. 이 문서에서는 각 방식에 대한 설명과 장단점을 간단하게 정리합니다.
ScriptableObject는 Unity의 에디터 자산(Asset)으로, 데이터를 직렬화된 형태로 저장할 수 있는 클래스입니다. 에디터에서 인스펙터를 통해 쉽게 데이터를 편집할 수 있으며, 런타임에서도 불러와 사용할 수 있습니다.
JSON(JavaScript Object Notation)은 경량의 데이터 교환 형식으로, Unity에서는 JsonUtility 또는 Newtonsoft.Json 등을 통해 데이터를 직렬화/역직렬화 하여 저장하거나 불러올 수 있습니다.
Application.persistentDataPath)Addressables 시스템은 Unity에서 에셋을 주소 기반으로 로드하고 관리할 수 있는 모듈입니다. 리소스를 빌드 외부에 저장하고, 필요할 때만 불러와서 메모리 사용을 최적화할 수 있습니다.
| 항목 | ScriptableObject | JSON | Addressables |
|---|---|---|---|
| 편집 용이성 | 에디터에서 우수 | 직접 편집 가능 (텍스트) | 에디터 내 설정 필요 |
| 런타임 저장 | 제한적 | 가능 | 불가 (주소 데이터만 관리됨) |
| 데이터 크기 관리 | 제한적 (메모리 상 상주) | 우수 (텍스트 저장) | 우수 (필요 시 로딩/언로딩) |
| 동적 리소스 관리 | 불가 | 가능 (수동 구현) | 매우 우수 |
| 학습 난이도 | 낮음 | 낮음 | 높음 |
| 사용 예시 | 설정값, 정적 데이터 | 세이브 파일, 유저 설정 | 스킨, 캐릭터 리소스, 사운드 등 |
상황에 따라 이들을 병행해서 사용하는 것이 가장 효과적입니다.
아니 민우님 너무 잘하시는거아니에요?? 진짜 자괴감들어서 서럽고 괴롭습니다