---
url: https://developers.webzenk.kr/sdk/unity/features.md
---
# 로그인·저장·랭킹·이벤트

## 로그인

```csharp
await api.Auth.LoginAsync();                     // 자동 (저장된 세션 → 게스트)
await api.Auth.LoginGoogleAsync(idToken);        // Google Sign-In ID 토큰
await api.Auth.LoginPlayGamesAsync(serverCode);  // Play Games RequestServerSideAccess 코드
await api.Auth.LoginAppleAsync(identityToken, rawNonce);

await api.Auth.LinkGoogleAsync(idToken);         // 지금 계정(게스트)에 연결
var me = await api.Auth.MeAsync();               // me.Providers, me.Status

api.Auth.SessionLost += e => ShowLoginScreen();  // 제재·탈퇴·토큰 폐기로 세션이 끊김
await api.Auth.LogoutAsync();
await api.Auth.DeleteAccountAsync();             // 탈퇴 요청 (유예 기간 후 파기)
await api.Auth.RestoreAccountAsync();            // 유예 기간 중 철회
```

| 속성 | 설명 |
|---|---|
| `api.Auth.IsLoggedIn` | 세션 있음 |
| `api.Auth.PlayerId` | 서버 유저 ID (문자열) |
| `api.Auth.Provider` | `guest` · `google` · `gpgs` · `apple` |

토큰 만료와 기기 시계 오차는 SDK가 알아서 처리합니다. 세션은 PlayerPrefs에 보관됩니다.

## 저장

```csharp
[Serializable]
public class SaveData { public int stage; public long gold; public List<string> items = new(); }

var save = await api.Storage.GetValueAsync("save", new SaveData());   // 없으면 기본값
await api.Storage.SetAsync("save", save);
await api.Storage.UpdateAsync<SaveData>("save", s => { s.gold += 10; return s; });   // 충돌 시 재시도

var item = await api.Storage.GetAsync("save");      // 없으면 null — item.Version, item.Get<T>()
var all = await api.Storage.ListAsync();
await api.Storage.SetManyAsync(new Dictionary<string, object> { ["a"] = 1, ["b"] = new List<int> { 1, 2 } });
await api.Storage.DeleteAsync("a");
await api.Storage.SetAsync("profile", profile, isPublic: true);   // 다른 유저가 볼 수 있게
var others = await api.Storage.PublicOfAsync(otherPlayerId);
```

* `[Serializable]` 클래스의 public 필드·속성, `List`, `Dictionary<string, T>`, 기본형을 저장할 수 있습니다.
* `SetAsync`는 SDK가 기억한 version으로 저장하고, 다른 기기와 충돌하면 `WKError("VERSION_CONFLICT")`를 던집니다. `UpdateAsync`는 다시 읽어서 최대 3번 시도합니다.

## 랭킹

```csharp
var r = await api.Leaderboard.SubmitAsync("weekly", score);   // r.Score, r.Rank, r.Total, r.Updated
var top = await api.Leaderboard.TopAsync("weekly", 50);        // top.Entries[i].Rank / PlayerId / Score
var me = await api.Leaderboard.MeAsync("weekly", 5);           // me.Me, me.Entries (위아래 5명)
var last = await api.Leaderboard.SeasonAsync("weekly", 202646); // 끝난 시즌 결과
var mine = await api.Leaderboard.SeasonMeAsync("weekly", 202646);
```

## 이벤트

```csharp
api.Events.Track("stage_clear", new Dictionary<string, object> { ["stage"] = 3, ["time_sec"] = 72 });
```

10초마다 모아서 보내고, 앱이 백그라운드로 갈 때도 보냅니다. 보내지 못한 이벤트는 기기에 보관했다가 다음 실행에 이어서 보냅니다.

## 서버 시각

```csharp
long now = api.ServerTime;   // epoch 초 — 일일 보상 등 기기 시계를 믿으면 안 되는 판단에
```
