스토리지
모바일 앱의 로컬 저장소에 데이터를 저장하고 관리하는 API예요. 앱이 종료되었다가 다시 시작해도 데이터가 유지돼요.
API
| API | 반환 타입 | 설명 |
|---|---|---|
AIT.StorageGetItem() | string | 저장된 데이터를 조회해요 |
AIT.StorageSetItem() | void | 데이터를 저장해요 |
AIT.StorageRemoveItem() | void | 특정 키의 데이터를 삭제해요 |
AIT.StorageClearItems() | void | 모든 데이터를 삭제해요 |
StorageGetItem
로컬 저장소에서 키에 해당하는 문자열 데이터를 가져와요.
csharp
try
{
string value = await AIT.StorageGetItem("player_name");
Debug.Log($"저장된 값: {value}");
}
catch (AITException ex)
{
Debug.LogError($"데이터 조회 실패: {ex.Message}");
}| 파라미터 | 타입 | 설명 |
|---|---|---|
key | string | 조회할 데이터의 키 |
StorageSetItem
로컬 저장소에 문자열 데이터를 저장해요.
csharp
try
{
await AIT.StorageSetItem("player_name", "토스");
Debug.Log("데이터 저장 완료");
}
catch (AITException ex)
{
Debug.LogError($"데이터 저장 실패: {ex.Message}");
}| 파라미터 | 타입 | 설명 |
|---|---|---|
key | string | 저장할 데이터의 키 |
value | string | 저장할 문자열 값 |
StorageRemoveItem
로컬 저장소에서 특정 키에 해당하는 데이터를 삭제해요.
csharp
try
{
await AIT.StorageRemoveItem("player_name");
Debug.Log("데이터 삭제 완료");
}
catch (AITException ex)
{
Debug.LogError($"데이터 삭제 실패: {ex.Message}");
}| 파라미터 | 타입 | 설명 |
|---|---|---|
key | string | 삭제할 데이터의 키 |
StorageClearItems
로컬 저장소의 모든 데이터를 삭제해요.
csharp
try
{
await AIT.StorageClearItems();
Debug.Log("모든 데이터 삭제 완료");
}
catch (AITException ex)
{
Debug.LogError($"데이터 전체 삭제 실패: {ex.Message}");
}사용 예제
게임 설정을 저장하고 불러오는 예제예요.
csharp
using AppsInToss;
using UnityEngine;
public class StorageExample : MonoBehaviour
{
async void Start()
{
try
{
// 저장된 설정 불러오기
string savedVolume = await AIT.StorageGetItem("bgm_volume");
if (!string.IsNullOrEmpty(savedVolume))
{
float volume = float.Parse(savedVolume);
Debug.Log($"저장된 볼륨: {volume}");
}
}
catch (AITException ex)
{
Debug.LogError($"설정 불러오기 실패: {ex.Message}");
}
}
public async void SaveSettings(float bgmVolume, float sfxVolume)
{
try
{
await AIT.StorageSetItem("bgm_volume", bgmVolume.ToString());
await AIT.StorageSetItem("sfx_volume", sfxVolume.ToString());
Debug.Log("설정 저장 완료");
}
catch (AITException ex)
{
Debug.LogError($"설정 저장 실패: {ex.Message}");
}
}
public async void ResetSettings()
{
try
{
await AIT.StorageClearItems();
Debug.Log("설정 초기화 완료");
}
catch (AITException ex)
{
Debug.LogError($"설정 초기화 실패: {ex.Message}");
}
}
}TIP
- 문자열만 저장할 수 있어요. 객체를 저장하려면 JSON으로 직렬화해서 사용해 주세요.
StorageClearItems()는 모든 데이터를 삭제하므로 주의해서 사용해 주세요.