클라우드 저장
플레이어별 JSON 문서를 키 단위로 저장합니다. 리비전이 있어 두 기기가 모르는 사이에 서로의 데이터를 덮어쓰지 않습니다.
코드 주석과 API 이름은 SDK와 일치하도록 영어로 유지합니다.
저장#
직렬화 가능한 모든 객체(Unity) 또는 JSON 값을 키 아래에 저장합니다. 저장할 때마다 다음 리비전 번호가 부여됩니다.
[System.Serializable]
public class Progress { public int level; public int coins; }
var saved = await Majacloud.CloudSave.SaveAsync("progress", new Progress { level = 3, coins = 120 });
if (saved.Ok) Debug.Log("Saved revision " + saved.Value.Revision);var saved := await Majacloud.cloud_save.save("progress", {"level": 3, "coins": 120})
if saved.ok:
print("Saved revision ", saved.value.revision)const saved = await mc.cloudSave.save('progress', { level: 3, coins: 120 });
if (saved.ok) console.log('Saved revision ' + saved.value.revision);curl -X PUT https://majacloud.majanite.com/v1/cloud/progress -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"data": {"level": 3, "coins": 120}}'불러오기#
한 번도 저장하지 않은 키를 불러오면 not_found가 반환됩니다. 첫 실행으로 처리하세요.
var loaded = await Majacloud.CloudSave.LoadAsync<Progress>("progress");
if (loaded.Ok) progress = loaded.Value.Data;
else if (loaded.IsNotFound) progress = new Progress(); // first launchvar loaded := await Majacloud.cloud_save.load_save("progress")
if loaded.ok:
progress = loaded.value.data
elif loaded.is_not_found():
progress = {} # first launchconst loaded = await mc.cloudSave.load('progress');
if (loaded.ok) progress = loaded.value.data;
else if (loaded.error.code === 'not_found') progress = {}; // first launchcurl https://majacloud.majanite.com/v1/cloud/progress -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"리비전과 충돌#
불러온 리비전을 예상 리비전으로 전달하세요. 그사이 다른 기기에서 저장했다면 저장이 revision_mismatch와 details.current_revision으로 실패합니다. 다시 불러와 병합한 뒤 재시도하세요. 예상 리비전이 0이면 새로 만들 때만 저장된다는 뜻입니다.
// Only overwrite the revision we loaded; another device may have saved since
var safe = await Majacloud.CloudSave.SaveAsync("progress", progress, expectedRevision: loaded.Value.Revision);
if (!safe.Ok && safe.Error.Code == MajacloudErrorCode.RevisionMismatch)
{
// Load again, merge, and save with the new revision
}# Only overwrite the revision we loaded; another device may have saved since
var safe := await Majacloud.cloud_save.save("progress", progress, loaded.value.revision)
if safe.error == "revision_mismatch":
pass # load again (details.current_revision), merge, save// Only overwrite the revision we loaded; another device may have saved since
const safe = await mc.cloudSave.save('progress', progress, { expectedRevision: loaded.value.revision });
if (!safe.ok && safe.error.code === 'revision_mismatch') {
// load again (safe.error.details.current_revision), merge, save
}curl -X PUT https://majacloud.majanite.com/v1/cloud/progress -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"data": {"level": 4}, "revision": 3}'
# 409 revision_mismatch → details.current_revision목록과 삭제#
플레이어의 키를 리비전, 크기와 함께 조회하고, 더 이상 필요 없는 키는 삭제합니다:
var keys = await Majacloud.CloudSave.ListAsync();
foreach (var entry in keys.Value) Debug.Log(entry.Key + " r" + entry.Revision + " " + entry.SizeBytes + " B");
await Majacloud.CloudSave.DeleteAsync("old_slot");var keys := await Majacloud.cloud_save.list_saves()
for entry in keys.value.keys:
print(entry.key, " r", entry.revision, " ", entry.size_bytes, " B")
await Majacloud.cloud_save.delete_save("old_slot")const keys = await mc.cloudSave.list();
for (const entry of keys.value.keys) console.log(entry.key, entry.revision, entry.size_bytes);
await mc.cloudSave.delete('old_slot');curl https://majacloud.majanite.com/v1/cloud -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"
curl -X DELETE https://majacloud.majanite.com/v1/cloud/old_slot -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"한도#
- 문서당 최대 256 KB, 플레이어당 최대 100개 키.
- 키에는 문자, 숫자, 점, 대시, 밑줄을 사용할 수 있습니다(최대 80자).
- 계정당 전체 저장 공간은 플랜에 따라 다릅니다(한도 참고). 이를 초과하면 저장이
plan_limit으로 실패하며, 데이터는 삭제되지 않습니다.