# IGP Unity SDK Core

Core owns the shared Google.Protobuf 3.33.5 and Unsafe 4.5.2 runtime binaries and
licenses under `Scripts/Plugins/` (binary UPM: `Plugins/`). Multiplayer and Object
Runtime reuse this copy; no separate Protobuf package is required. Upgrade Core
and Multiplayer together to avoid DLL duplication with older Multiplayer releases.

`cn.indiegp.sdk.unity` is the Unity platform base package. It contains:

- `IGPConfig` and `IGPRuntimeManager`
- automatic Unity runtime-platform resolution before Host Session construction
- shared Host Session protobuf client with Desktop Named Pipe and Mobile Flutter transports
- authorization, achievements, optional account, user profile, and Arena session APIs
- an allowlisted Direct Curio path for phone SMS sign-in, session refresh, profiles, and Arena session acquisition
- runtime extension contracts for optional packages

It intentionally exposes no Hosted room control, Room projection, Realtime,
KCP, UDP, network diagnostics, or Mirror API. Its Desktop platform runtime keeps
an internal one-shot compatibility client solely for obtaining a RoomNode
descriptor. Install `cn.indiegp.sdk.unity.multiplayer` only when the game needs
RoomNode Game data synchronization, Realtime, or Mirror.

See [Documentation~/UPM-INSTALL.md](Documentation~/UPM-INSTALL.md) when installing a distributed UPM tarball.

For the binary UPM usage contract and field-level Core models, start with [Documentation~/UPM-INSTALL.md](Documentation~/UPM-INSTALL.md) and [Documentation~/ACCOUNT-AND-PROFILES.md](Documentation~/ACCOUNT-AND-PROFILES.md). The runtime implementation is in the package DLL; these guides are the intended reference for configuring and calling it.

## Minimal Setup

1. Create one `IGPConfig` asset and set `appId`.
2. Add `IGPRuntimeManager` to a persistent GameObject.
3. Assign the config and call `await runtime.InitializeAsync()`.

Optional runtime extensions on the same GameObject are discovered, initialized in order, and shut down by the core runtime.

`runtime.GameMode` is the read-only launch mode (`Unknown`, `Normal`, or
`Multiplayer`), captured before Host/extension initialization. It remains fixed
when players enter/leave rooms or reconnect. It does not report network readiness.
Windows shares the existing Multiplayer launch-context parser; Mobile currently
returns Unknown. See [Launch Mode](Documentation~/QUICKSTART.md#launch-mode).

There is no Host platform setting. Core maps `WindowsEditor`/`WindowsPlayer` to
Desktop and `Android`/`IPhonePlayer` to Mobile, checking in that priority before
constructing exactly one matching runtime. Attach failure does not switch the
runtime. Game code keeps calling the same profile, capability, and Multiplayer
APIs.

The Multiplayer bootstrap provider is currently implemented only by the
Desktop platform runtime. On Mobile, a bootstrap request reports the stable
Host capability-unavailable error and does not replay the request through
Desktop or construct a Named Pipe client. A future Mobile
provider implements the same Core contract; Multiplayer does not change.

The embedding host wires its native bridge through the dedicated integration
surface:

```csharp
runtime.MobileHostIntegration.SetFrameSender(SendFrameToFlutter);
runtime.MobileHostIntegration.MarkReady();

// Called by the native/Flutter bridge for each IgpHostFrame carrier.
runtime.MobileHostIntegration.ReceiveFrame(frameJson);

// Called when the host channel is torn down.
runtime.MobileHostIntegration.Close("mobile-host-channel-closed");
```

`MobileHostIntegration` is for the application shell, not game capability
calls. It only forwards carrier frames and does not expose credentials. The
Unity SDK foundation is complete, while UAAL export wiring and Android/iOS
device verification remain pending.

## Account And Profiles

Explicit phone sign-in is independent from Desktop attach and does not require `InitializeAsync()`:

```csharp
var sendResult = await runtime.SendPhoneSignInCodeAsync("13800138000");
var session = await runtime.SignInWithPhoneCodeAsync("13800138000", verificationCode);
var profile = await runtime.GetCurrentUserProfileAsync();
var players = await runtime.GetPlayerProfilesAsync(new[] { otherUserId });
```

The sign-in call also creates the user when Curio has no account for that phone. `IGPUserSession` exposes only `Profile`; Core retains access and refresh tokens in memory. `runtime.SignOut()` clears only this explicit account session and does not change Desktop login.

Profile calls use an already attached, signed-in Host Session `userContext` when available. Otherwise they use the explicit Core account session. The source choice is internal, and a failed Host command is never replayed against Curio. See [Documentation~/ACCOUNT-AND-PROFILES.md](Documentation~/ACCOUNT-AND-PROFILES.md).

`RequestArenaSessionAsync()` uses the in-memory Direct login when present;
otherwise it asks the active attached Desktop or Mobile Host when that Host
advertises Arena capability. Provider selection happens once per request, so a
Direct failure is never replayed through Host. Core returns only the short-lived
Arena credential and does not construct a room-control client. See
[Documentation~/ARENA-SESSION.md](Documentation~/ARENA-SESSION.md).

After initialization, host-provided values are available through named, parameter-free runtime info properties:

```csharp
var saveRootPath = runtime.RuntimeInfo.SaveRootPath;
string gameParams = runtime.RuntimeInfo.GameParams;
```

`SaveRootPath` is always non-null. It is an empty string when the runtime host did not provide a save location; reading it does not create or modify the directory.

`GameParams` is the optional string supplied through `--game-params`, preserved
verbatim without JSON parsing or whitespace trimming. It is captured once at
initialization entry, before Host I/O; it is empty before capture or when omitted.
Initialization failure, reconnects and shutdown do not change the captured value.
SDK logs never include its content. See
[Game launch content](Documentation~/QUICKSTART.md#game-launch-content) for usage.

All public runtime notifications are code-only C# events; they are not Inspector-bindable `UnityEvent` fields. See [Documentation~/EVENT-REFERENCE.md](Documentation~/EVENT-REFERENCE.md) for the maintained event list.

See [Documentation~/QUICKSTART.md](Documentation~/QUICKSTART.md) for the core-only flow. Multiplayer setup is documented by the separately installed `cn.indiegp.sdk.unity.multiplayer` package.

Core does not provide a live room projection or room commands. It can return an
explicit short-lived Arena session for caller-owned Gateway clients and broker a
complete immutable Multiplayer bootstrap through the active Desktop or Mobile
Host provider. A Gateway-facing integration still owns room control, and
caller-owned orchestration can pass the same Core bootstrap to Multiplayer.

## 查询会员权益状态

`GetCurrentUserProfileAsync()` 与 `CurrentUserProfile` 的用户资料，以及
`GetPlayerProfilesAsync(userIds)` 返回的玩家资料，均提供只读
`bool? SubscriptionBenefitsActive`：`true` 表示会员权益生效，`false` 表示未生效，
`null` 表示尚未获取或旧宿主未提供。该值由服务端计算，包含符合条件的赠送会员，
不表示是否付费。字段是查询时的快照；需要最新状态时显式重新查询，不自动推送变化。
