Unity Quick Start
本页覆盖 Core 的最小接入。Multiplayer 在进入 Playing 后通过 RoomNode
reliable/unreliable 通道同步游戏数据。Core 初始化时根据当前 Unity 运行平台按
Desktop、Mobile 优先级判断,随后只创建一个 runtime,无需用户选择;attach
失败不会切换平台。Multiplayer 不提供平台或初始化模式
开关。Runtime 既可向 Core 请求 descriptor,也可接收调用方显式传入的 descriptor。旧的
RoomChanged 和 Runtime 房间生命周期 API 不作为数据面接入方式。
- 已安装
cn.indiegp.sdk.unity - Unity
2022.3 LTS - Windows 10 或更高版本
- IGP 运营提供的
appId - 验证 Desktop 能力时,本机已安装并登录对应环境的 IGP 桌面客户端
1. 添加最小初始化脚本
Section titled “1. 添加最小初始化脚本”在工程中新增 Assets/Scripts/IGPQuickstartDriver.cs:
using IGP.UnitySDK;using UnityEngine;
public sealed class IGPQuickstartDriver : MonoBehaviour{ [SerializeField] private IGPRuntimeManager runtime;
private async void Start() { runtime ??= FindObjectOfType<IGPRuntimeManager>(); if (runtime == null || !await runtime.InitializeAsync()) { Debug.LogError("IGP Core initialization failed."); return; }
Debug.Log($"IGP Core ready. Desktop attached={runtime.IsDesktopSessionAttached}"); }
[ContextMenu("IGP/Unlock Quickstart Achievement")] private async void UnlockAchievement() { var result = await IGPSDK.UnlockAchievementAsync(runtime, "first_session"); Debug.Log($"Unlock success={result.success}, duplicated={result.duplicated}"); }}2. 配置场景
Section titled “2. 配置场景”- 创建一个长期存在的场景对象,例如
IGPBootstrap。 - 挂载
IGPRuntimeManager和IGPQuickstartDriver。 - 在项目生成的
IGPConfig中填写appId。 - 确保场景中只有一个有效的
IGPRuntimeManager。
SDK 不会因为组件存在就自动启动。游戏必须在自己的启动流程中显式调用
InitializeAsync()。
进入 Play mode 后确认:
InitializeAsync()返回成功。- 使用 Desktop 能力时,
IsDesktopSessionAttached == true。 - 按需触发成就命令,并检查返回结果。
Core 初始化成功不代表已经进入房间或建立 RoomNode 数据面。当前 Host 缺少
descriptor 链路时,Multiplayer 只记录 warning,并保持
IsRuntimeCreated == false。联机验收应检查 IsRuntimeCreated、
IsRealtimeReady 和 Game 消息收发,不要使用 RoomChanged 验收数据面。
InitializeAsync() 完成后,游戏可以通过 runtime.RuntimeInfo.SaveRootPath
读取当前游戏实例的存档根目录,并在该目录下自行组织、创建、读取和写入游戏存档文件:
var saveRootPath = runtime.RuntimeInfo.SaveRootPath;该属性由 Host 提供;Host 没有提供目录时返回空字符串,游戏应自行决定是否使用其他
本地存储位置。SDK 不会创建、修改、清理或替接入者管理该目录,也不会规范化返回的路径。
SaveRootPath 不是命令行参数,--game-params 仅用于传递游戏启动字符串。