데이터 저장
플레이어의 게임 데이터를 클라우드에 저장하는 API입니다.
URL 확인
이 API는 service-storage-api.playnanoo.com 도메인을 사용합니다.
API 정보
- URL:
https://service-storage-api.playnanoo.com/storage/v20221001/save - Method:
PUT - 인증 필요: 예
DeviceInfo 상속
이 API의 Req 클래스는 DeviceInfo를 상속받습니다. DeviceInfo의 모든 속성이 자동으로 포함됩니다.
요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
| storage_key | string | 필수 | 저장할 데이터의 키 |
| storage_value | string | 필수 | 저장할 데이터의 값 (JSON 문자열 가능) |
| isPrivate | string | 필수 | 데이터 접근 제한 설정 (on/off) - on 설정 시 외부 플레이어의 데이터 접근 차단 |
응답 데이터
Res 클래스
| 필드 | 타입 | 설명 |
|---|---|---|
| Status | string | 처리 상태 |
Unity C# 구현
BaseResponse 클래스
모든 API 응답의 기본 클래스입니다.
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
필드 설명:
ErrorCode: 에러 코드Message: 에러 메시지WithdrawalKey: 탈퇴 유예 상태인 경우 복구에 필요한 키 (탈퇴 유예 중인 계정만 제공)BlockKey: 차단된 계정인 경우 제공되는 키 (차단된 계정만 제공)
데이터 저장 클래스
using System;
using System.Collections;
using UnityEngine.Networking;
public class StorageSave
{
static string path = "https://service-storage-api.playnanoo.com/storage/v20221001/save";
[Serializable]
public class Req : DeviceInfo
{
public string storage_key; // 저장할 데이터의 키
public string storage_value; // 저장할 데이터의 값
public string isPrivate; // 데이터 접근 제한 설정 시 외부 플레이어의 데이터 접근을 차단
public IEnumerator Send(string storage_key, string storage_value, bool isPrivate, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(storage_key)) this.storage_key = storage_key;
if (!string.IsNullOrEmpty(storage_value)) this.storage_value = storage_value;
this.isPrivate = isPrivate ? "on" : "off";
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public string Status;
}
}
사용 예제
public void SaveGameData()
{
StorageSave.Req req = new StorageSave.Req();
// 게임 데이터를 JSON으로 직렬화
var gameData = new
{
level = 10,
score = 1000,
items = new[] { "sword", "shield", "potion" }
};
string jsonData = JsonUtility.ToJson(gameData);
StartCoroutine(req.Send(
storage_key: "player_game_data",
storage_value: jsonData,
isPrivate: false, // 공개 데이터로 저장
onSuccess: res =>
{
Debug.Log("데이터 저장 성공");
},
onError: error =>
{
Debug.LogError($"데이터 저장 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
데이터 형식
storage_value는 문자열이므로 복잡한 데이터 구조는 JSON으로 직렬화하여 저장하는 것을 권장합니다.
자동 저장
게임 데이터는 중요한 시점(레벨업, 아이템 획득 등)마다 저장하는 것을 권장합니다. 네트워크 상태를 확인하고 저장에 실패한 경우 재시도 로직을 구현하세요.