게임 센터
게임 센터 프로필, 리더보드, 리워드 등 게임 관련 API예요.
API
| API | 반환 타입 | 설명 |
|---|---|---|
AIT.GetGameCenterGameProfile() | GameCenterGameProfile | 게임 센터 프로필을 조회해요 |
AIT.GetUserKeyForGame() | string | 게임용 사용자 키를 조회해요 |
AIT.GrantPromotionRewardForGame() | GrantPromotionRewardForGameResult | 게임 프로모션 리워드를 지급해요 |
AIT.OpenGameCenterLeaderboard() | void | 게임 센터 리더보드를 열어요 |
AIT.SubmitGameCenterLeaderBoardScore() | void | 리더보드에 점수를 제출해요 |
GetGameCenterGameProfile
게임 센터에서 사용자의 게임 프로필을 조회해요.
csharp
try
{
var profile = await AIT.GetGameCenterGameProfile();
Debug.Log($"프로필: {profile}");
}
catch (AITException ex)
{
Debug.LogError($"프로필 조회 실패: {ex.Message}");
}GetUserKeyForGame
게임용 사용자 키를 조회해요. 게임 내에서 사용자를 식별할 때 사용할 수 있어요.
csharp
try
{
string userKey = await AIT.GetUserKeyForGame();
Debug.Log($"User Key: {userKey}");
}
catch (AITException ex)
{
Debug.LogError($"사용자 키 조회 실패: {ex.Message}");
}GrantPromotionRewardForGame
게임 프로모션 리워드를 사용자에게 지급해요.
csharp
try
{
var result = await AIT.GrantPromotionRewardForGame(new GrantPromotionRewardForGameParams
{
// 프로모션 지급에 필요한 파라미터
});
Debug.Log($"리워드 지급 성공: key={result.Key}");
}
catch (AITException ex)
{
Debug.LogError($"리워드 지급 실패: {ex.ErrorCode} - {ex.Message}");
}에러 코드
| 에러 코드 | 설명 |
|---|---|
4100 | 프로모션 정보를 찾을 수 없어요 |
4104 | 프로모션이 중지되었어요 |
4105 | 프로모션이 종료되었어요 |
4108 | 프로모션이 승인되지 않았어요 |
4109 | 프로모션이 실행 중이 아니에요 |
4110 | 리워드를 지급/회수할 수 없어요 |
4112 | 프로모션 머니가 부족해요 |
4113 | 이미 지급/회수된 내역이에요 |
4114 | 프로모션에 설정된 1회 지급 금액을 초과했어요 |
40000 | 게임 앱이 아닌 미니앱에서 호출했어요 |
OpenGameCenterLeaderboard
게임 센터 리더보드 화면을 열어요.
csharp
try
{
await AIT.OpenGameCenterLeaderboard();
Debug.Log("리더보드 열기 완료");
}
catch (AITException ex)
{
Debug.LogError($"리더보드 열기 실패: {ex.Message}");
}SubmitGameCenterLeaderBoardScore
리더보드에 점수를 제출해요.
csharp
try
{
await AIT.SubmitGameCenterLeaderBoardScore(new SubmitGameCenterLeaderBoardScoreParams
{
Score = 1500
});
Debug.Log("점수 제출 완료");
}
catch (AITException ex)
{
Debug.LogError($"점수 제출 실패: {ex.Message}");
}게임 센터 연동 예제
게임 시작 시 프로필을 조회하고, 게임 종료 시 점수를 제출하는 예제예요.
csharp
using AppsInToss;
using UnityEngine;
public class GameCenterExample : MonoBehaviour
{
async void Start()
{
try
{
// 1. 사용자 키 조회
string userKey = await AIT.GetUserKeyForGame();
Debug.Log($"User Key: {userKey}");
// 2. 게임 프로필 조회
var profile = await AIT.GetGameCenterGameProfile();
Debug.Log($"프로필: {profile}");
}
catch (AITException ex)
{
Debug.LogError($"게임 센터 초기화 실패: {ex.Message}");
}
}
public async void OnGameEnd(int score)
{
try
{
// 점수 제출
await AIT.SubmitGameCenterLeaderBoardScore(new SubmitGameCenterLeaderBoardScoreParams
{
Score = score
});
Debug.Log($"점수 {score} 제출 완료");
// 리더보드 열기
await AIT.OpenGameCenterLeaderboard();
}
catch (AITException ex)
{
Debug.LogError($"점수 제출 실패: {ex.Message}");
}
}
}TIP
- 게임 센터 API는 게임 앱으로 등록된 미니앱에서만 사용할 수 있어요. 일반 미니앱에서 호출하면
40000에러가 발생해요. - 리더보드 점수 제출 시 게임 종료 시점이나 스테이지 클리어 시점 등 적절한 타이밍에 호출해 주세요.