# UPM Tarball Installation

This guide applies to `core-igp-0.3.7.tgz` on Unity `2022.3`. The shorter artifact file name does not change the internal UPM package name, `cn.indiegp.sdk.unity`.

The public UPM tarball contains the complete Core runtime in `Plugins/IGP.UnitySDK.dll`. The public types and call sequences below are the supported usage contract. Editor integration, documentation, and examples remain available in the package; use the matching `.unitypackage` only when a source distribution is specifically needed.

## Package Contents

| Path | Purpose |
| --- | --- |
| `Plugins/IGP.UnitySDK.dll` | Core runtime API and implementation. |
| `Editor/` | Unity editor integration source. |
| `Documentation~/` | Installation, API behavior, and data structure references. |
| `Samples~/` | Text examples (`.cs.txt`) and optional assembly templates (`.asmdef.txt`). Importing or copying this directory does not compile the examples; explicitly copy and rename only the example you need. |
| `package.json` | UPM package ID, version, and dependencies. |

The UPM carrier is complete for runtime use. It does not include PDB files or the source carrier's runtime implementation files; that packaging distinction does not change the available API or behavior.

## Install

1. Open `Window > Package Manager`.
2. Open the `+` menu and choose `Add package from tarball`.
3. Select `core-igp-0.3.7.tgz`.
4. Wait for Unity to resolve `com.unity.nuget.newtonsoft-json` and compile the project.

The tarball contains the complete Core package. Multiplayer, Compliance, and Game Kit remain separate optional public packages.

For a manifest-based installation, keep the tarball at a stable path and add:

```json
"cn.indiegp.sdk.unity": "file:../LocalPackages/core-igp-0.3.7.tgz"
```

Commit both `Packages/manifest.json` and `Packages/packages-lock.json`. If the tarball is outside the project or source repository, other developers and clean CI agents must receive it at the same referenced path.

## Core Data Structures

The following types are in the `IGP.UnitySDK` or `IGP.UnitySDK.Models` namespaces. Properties with an `internal set` are returned by Core and are read-only to game code.

### Configuration and Runtime

| Type/field | Type | Meaning |
| --- | --- | --- |
| `IGPConfig.sdkEnvironment` | `IGPSDKEnvironment` | Environment used for Desktop and direct Core endpoints; normally `PROD`. |
| `IGPConfig.debugLogging` | `IGPLogLevel` | Diagnostic verbosity; use `Off` for production. |
| `IGPConfig.appId` | `int` | Required game application identifier. It is also used by Multiplayer, Compliance, and GameKit requests. |
| `IGPConfig.showAuthorizationFailureFallback`, `authorizationFailureFallbackTitle`, `authorizationFailureFallbackMessage`, `authorizationFailureFallbackHint`, `authorizationFailureFallbackButtonText`, `authorizationFailureFallbackQuitButtonText` | `bool`/`string` | Optional authorization failure UI values consumed by Core's host integration. |
| `IGPConfig.curioApiBaseUrlDebugOverride` | `string` | DEV-only direct Curio URL override. Leave empty in normal projects; PROD/PREVIEW ignore it. |
| `IGPConfig.desktopSessionAutoAttach` | hidden `bool` | Historical field name used by controlled Desktop integration tests; it does not select the Host platform. |
| `IGPConfig.desktopExecutablePathDebugOverride`, `desktopLaunchCommand` | hidden `string` | Desktop-only integration values. Leave them at their serialized defaults unless a documented Desktop integration explicitly supplies them. |
| `IGPRuntimeManager.Config` | `IGPConfig?` | The explicitly assigned config asset. |
| `IGPRuntimeManager.GameMode` | `IGPGameMode` | Read-only launch mode, captured once before Host/extension initialization. `Unknown=0` before capture or when startup information is unsupported/incomplete; `Normal=1` for an ordinary Windows launch; `Multiplayer=2` for a complete hosted Windows launch. Never follows room/connection changes. |
| `IGPRuntimeManager.Host`, `IIGPRuntimeContext.Host` | `IIGPHostCommandGateway` | Shared Host Session command gateway for Core and optional packages; Core resolves the Unity runtime platform before constructing one Host runtime. |
| `IGPRuntimeManager.RuntimeInfo.SaveRootPath` | `string` | Host-provided save location, or an empty string when unavailable. Reading it has no filesystem side effect. |
| `IGPRuntimeManager.RuntimeInfo.GameParams` | `string` | Read-only optional game launch content, captured once before Host I/O. Empty before capture or when omitted; otherwise preserved verbatim, including whitespace. |
| `IGPRuntimeManager.IsInitialized` | `bool` | Whether normal Core/runtime initialization completed. Account calls can work before this is true. |
| `IGPRuntimeManager.HasUserSession` | `bool` | Whether Core currently holds a usable direct account session. Host login alone does not set this value. |

The Desktop pipe endpoint is resolved internally from `INDIEGP_DESKTOP_PIPE_ENDPOINT`,
then the built-in default for `sdkEnvironment`. It is not an `IGPConfig` setting;
legacy serialized pipe overrides are ignored.

Create and assign one `IGPConfig` asset explicitly:

```csharp
var profile = await runtime.GetCurrentUserProfileAsync();
// runtime.Config.appId is the app identity used by Core and dependent packages.
```

For choosing the startup screen, read `GameMode` once after calling
`InitializeAsync()` (it is captured synchronously before the first Host await).
See [Launch Mode](QUICKSTART.md#launch-mode). It does not report connection
readiness, does not expose launch credentials, and has no change event. Mobile
currently returns Unknown because an equivalent mobile launch input is not yet
implemented. Unknown must not be treated as Normal.

For `GameParams`, see [Game launch content](QUICKSTART.md#game-launch-content).
This additive API is available in the current source; existing release artifacts
must be upgraded to a build containing the addition before calling it.

### Account and Profile Results

| Type | Public fields/properties | Meaning |
| --- | --- | --- |
| `IGPPhoneCodeSendResult` | `Succeeded`, `DevelopmentCode`, `IsTestAccount` | Result of sending the phone sign-in code. `DevelopmentCode` is only populated by the configured development/test path. |
| `IGPUserSession` | `Profile` | Successful explicit sign-in or refresh result. Access and refresh tokens are never exposed. |
| `IGPUserProfile` | `Id`, `Nickname`, `Discriminator`, `DisplayTag`, `AvatarUrl`, `AvatarFrameUrl` | Current user's stable identity and display assets. URLs may be empty when the service has no asset. |
| `IGPPlayerProfileSummary` | `Id`, `Nickname`, `AvatarUrl`, `AvatarFrameUrl` | Lightweight profile returned by a batch lookup. |
| `IGPArenaSession` | `AppId`, `ServerUrl`, `Token`, `ExpiresAtUtc`, `Player` | Direct-first, Host-fallback short-lived Arena credential. Core does not persist or refresh it. |
| `IGPArenaSessionPlayer` | `Id`, `Name`, `Avatar` | Player identity bound to an Arena session. |
| `IGPRuntimeManager.CurrentUserProfile` | `IGPUserProfile?` | Cached current profile, or `null` before a provider has supplied one. |

The normal account flow is:

```csharp
using System.Collections.Generic;
using IGP.UnitySDK.Models;

var sent = await runtime.SendPhoneSignInCodeAsync(phone);
var session = await runtime.SignInWithPhoneCodeAsync(phone, code, inviteCode);
IGPUserProfile current = session.Profile;
IReadOnlyList<IGPPlayerProfileSummary> players =
    await runtime.GetPlayerProfilesAsync(playerIds);
```

`SignInWithPhoneCodeAsync` logs in an existing account or creates the missing account after the SMS challenge. `RefreshUserSessionAsync` refreshes the in-memory session; `SignOut` clears only that direct Core session. These methods do not require `InitializeAsync`. If Desktop is attached and has a valid user context, profile lookup may use Desktop; otherwise Core uses its direct session. A failed Desktop call is not replayed through another provider.

`RequestArenaSessionAsync` uses the Direct session when `HasUserSession` is true
at call start. Otherwise it uses the currently active Desktop or Mobile Host
when attached, signed in, and advertising capability 11. A selected Direct
request is never replayed through Host after failure. Host login does not set
`HasUserSession`.

### Error and Lifetime Rules

- Core methods throw `IGPSDKException` or a capability-specific exception with a stable `Code`; callers should branch on the code rather than localized message text.
- Direct authenticated requests refresh once after a `401` and retry once. A failed refresh or second `401` clears the direct session.
- Access and refresh credentials remain in memory and are redacted from logs and `ToString()` output.
- Destroying the `IGPRuntimeManager` cancels new and in-flight calls through its lifetime token.

See [ACCOUNT-AND-PROFILES.md](ACCOUNT-AND-PROFILES.md) for validation limits and provider selection details.

## Migrate From `.unitypackage`

Do not keep the legacy `Assets/IGP.UnitySDK` directory and this UPM package installed at the same time. The two carriers contain the same module and can create duplicate assemblies.

Before switching:

1. Back up user-owned `IGPConfig` assets, modified samples, and custom scripts.
2. Remove the legacy `Assets/IGP.UnitySDK` directory and install the UPM tarball at the same SDK version.
3. If an existing `IGPConfig.asset` shows `Missing (Mono Script)`, it was serialized against the source package's `IGPConfig.cs` `MonoScript`. Changing the asset `.meta` GUID or editing the package cache cannot repair that reference. Recreate a new `IGPConfig` through `Assets > Create > IGP > Config`, re-enter the values (especially `appId`), assign it to `IGPRuntimeManager`, and verify the scene/prefab. Keep the source `.unitypackage` instead when preserving the original serialized asset is required.
4. Confirm scenes and prefabs have no missing script references before upgrading the SDK version.

Create and bind configuration assets explicitly. The package does not scan or modify the consuming project's assets, scenes, prefabs, or project settings.
