Communitygithub.com

unity-technologies/build-live-game

使用 Unity 服务构建和运营一款在线游戏。当用户需要实现、连接或调试后端驱动的功能时使用——例如战斗通行证、成就、玩家进度、云存档、排行榜、匹配、虚拟经济、服务器权威逻辑、反作弊、玩家账户与身份验证、远程配置、功能开关、A/B 测试、分析或云资源部署。

build-live-game 是什么?

该技能(Skill)提供了一套完整的 Unity Gaming Services(UGS)集成指南,帮助开发者快速构建和运营在线游戏。它覆盖了从基础初始化到高级功能(如云代码、云存档、排行榜、匹配、虚拟经济、反作弊等)的完整流程,并提供了详细的包依赖关系表、架构图、快速参考和部署核对表。技能强调使用 Cloud Code(服务器权威 C# 模块)来处理所有涉及游戏完整性的数据写入(如经验值、奖励、货币),以防范作弊和保证公平性。它支持 Unity Editor 内的云资源部署,并包含可复用的“构建块”(Building Blocks),如玩家账户、成就、排行榜等,可显著加速开发。主要面向使用 Unity 引擎的客户端和服务器端开发者,平台覆盖所有 Unity 支持的平台(移动端、PC、主机、Web)。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/unity-technologies/skills/tree/main/skills/build-live-game

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

用 Unity 游戏服务构建在线游戏

UGS 包

包最低版本用途
com.unity.services.core1.16.0初始化、依赖图
com.unity.services.authentication3.6.1玩家登录与身份
com.unity.services.cloudcode2.10.3服务器权威 C# 模块
com.unity.services.cloudsave3.4.0每位玩家及共享的键值存储
com.unity.remote-config4.2.5服务端游戏配置
com.unity.services.deployment1.7.2从编辑器部署云资源
com.unity.services.tooling1.4.1访问控制与游戏覆盖
com.unity.services.apis1.1.1所有 UGS 服务生成的 REST 客户端

初始化模式

每个 UGS 游戏的启动方式相同。com.unity.services.core 必须首先初始化,然后玩家登录:

using Unity.Services.Core;
using Unity.Services.Authentication;

await UnityServices.InitializeAsync();
await AuthenticationService.Instance.SignInAnonymouslyAsync();
// 所有其他服务现在已就绪

InitializeAsync() 完成后,服务单例(如 CloudSaveService.Instance、CloudCodeService.Instance)即可使用。

包映射

基础

包用途单例 / 入口点
Core初始化、依赖图、组件注册UnityServices.InitializeAsync()
Authentication玩家登录(匿名、社交、Unity、用户名/密码)、身份AuthenticationService.Instance
Services APIs所有 UGS 服务的生成 REST 客户端;通过服务账户的管理 API 访问直接 API 类

玩家数据与配置

包用途单例 / 入口点
Cloud Save每位玩家的键值数据(默认、公开、受保护)和游戏范围内的自定义数据CloudSaveService.Instance.Data.Player / .Data.Custom
Remote Config服务端游戏配置、功能开关、JSON 定义RemoteConfigService.Instance
Economy虚拟货币、库存物品、购买、商店EconomyService.Instance

服务器逻辑与安全

包用途单例 / 入口点
Cloud Code用于可信写入和验证的服务器权威 C# 模块CloudCodeService.Instance → CallModuleEndpointAsync
Tooling编写和部署访问控制(.ac)和游戏覆盖(.ugo)文件仅编辑器(部署窗口)
Deployment从 Unity 编辑器部署云资源(.rc、.ac、.ccmr、.lb 等)仅编辑器(服务 > 部署)

社交与竞技

包用途单例 / 入口点
Multiplayer会话、匹配、大厅。构建块:多人会话、匹配会话、服务器会话MultiplayerService.Instance
Leaderboards分数提交、排名、层级、版本历史。构建块:排行榜LeaderboardsService.Instance

遥测

包用途单例 / 入口点
Analytics自定义事件、标准事件、用户同意管理AnalyticsService.Instance

架构——包如何组合

                    UnityServices.InitializeAsync()
                              │
                              ▼
                     AuthenticationService
                    (登录 → PlayerId)
                              │
              ┌───────────────┼───────────────┐
              ▼               ▼               ▼
        Remote Config     Cloud Save      Economy
      (游戏配置、       (玩家状态、    (货币、
       定义、          进度、         库存、
       功能开关)       偏好)         购买)
              │               │               │
              └───────┬───────┘               │
                      ▼                       │
                 Cloud Code                   │
              (服务器权威                     │
               写入、验证、        ◄─────────┘
               反作弊逻辑)
                      │
              ┌───────┼───────┐
              ▼       ▼       ▼
         Cloud Save  Economy  Leaderboards
         (受保护    (服务器   (分数
          写入)     授予)    提交)

关键原则: 对于任何影响游戏完整性的数据(经验值、奖励、货币),请通过 Cloud Code 模块进行写入。直接客户端写入仅适用于非敏感数据(偏好、显示设置)。

核心服务——快速参考

身份验证

包: com.unity.services.authentication (>= 3.6.1)

处理玩家身份。登录方式:匿名、社交提供商(Google、Apple、Steam、Facebook、Oculus 等)、Unity 浏览器、用户名/密码以及设备代码流程。

登录后:PlayerId 和 PlayerName 可用。所有登录方式都会触发 SignedIn 事件。PlayerAccountService(用于 Unity 浏览器登录)位于独立程序集 (Unity.Services.Authentication.PlayerAccounts) 中。

云代码

包: com.unity.services.cloudcode (>= 2.10.3)

运行服务端 C# 模块 (.NET 9) 以执行受信任的操作。模块部署为 .ccmr 文件。客户端调用:

var result = await CloudCodeService.Instance.CallModuleEndpointAsync<TResult>(
    "ModuleName", "FunctionName", args);

对于生产环境,建议使用 C# 模块而非 JavaScript 脚本。模块还支持通过订阅、事件驱动触发器和多人会话范围进行实时推送消息。

云存档

包: com.unity.services.cloudsave (>= 3.4.0)

每位玩家的键值存储,具有三种访问类别,以及游戏范围内的自定义数据:

访问类别读取写入用例
默认所有者所有者私人设置、偏好
公开任何人所有者公开资料、显示名称
受保护所有者仅服务器(云代码)反作弊数据、服务器授予的状态
自定义任何玩家仅服务器共享游戏状态、全局配置

值以 JSON 序列化。支持通过 SaveItem 进行写锁定并发控制、通过 QueryAsync 进行服务器端查询,以及二进制文件存储。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

unity-technologies/2d-pixel-perfect

Sets up, diagnoses, and fixes pixel perfect 2D rendering in Unity projects. Use when working on any retro-style or pixel art 2D game.

unity-technologies/audio-setup-mixers

Scans the scene and audio assets to appropriately route Audio Sources into existing Audio Mixer Groups, classifying each source by what it plays. Use when the user asks about cleaning up mixer assignments, routing audio through a mixer, or which group a sound belongs in. Creating mixers and groups, and setting volumes, are not automated — the skill inventories what exists and asks the user to add anything missing.

unity-technologies/generate-editor-search-query

Generates Unity Search / Quick Search queries and opens the Unity Search window for read-only Unity Editor asset or scene-object lookup requests. Always use when the user asks to find, search, show, locate, filter, look up, query, or list concrete assets or scene objects in the current project or scene, even if Unity Search is not named. Covers materials, textures, prefabs, scenes, scripts, shaders, GameObjects, components, Lights, Cameras, UI objects, labels, paths, references, selected or named assets, and asset types. Also use when the user explicitly mentions Unity Search, Quick Search, Search window, open Search, or asks what Unity Search query to use. Do not use for general project overview, project structure, folder-purpose summaries, gameplay/system explanations, how-to programming questions, web search, repository text search, build logs, package installation, menu or settings search, modifying results, or non-Unity filesystem search unless the user explicitly asks to use Unity Search.

unity-technologies/implement-in-app-purchases

Implement, configure, and debug Unity In-App Purchases (IAP) — store connection, product catalog, consumable/non-consumable/subscription purchases, two-step pending-confirm flow, receipt validation, entitlement checking, restore transactions, Apple extensions (promotional purchases, Ask-to-Buy, code redemption), and Google Play extensions (subscription upgrade/downgrade), D2C Capabilities(direct to customer), 3rd party payment provider (Stripe/Coda) via Unity IAP/Unity Cloud. Use when the user needs to add, modify, debug, or migrate from native Android/iOS billing, 3rd party packages(RevenueCat/Adapty/Essential Kit/Unipay supported) to IAP. Triggers on microtransactions (MTX), monetization, real-money purchases, store purchases, buying items, support D2C, purchase via Stripe/Coda, migrate from native billing(Google's BillingClient or Apple's StoreKit/SKPaymentQueue/SKProduct)/RevenueCat/Adapty/EssentialKit/Unipay.

unity-technologies/initialize-ai-navigation

Sets up and configures the Unity AI Navigation system — NavMesh surfaces, NavMesh agents, obstacles, links, modifiers, areas and costs. Use when creating walkable navigation meshes, adding pathfinding agents, setting up patrol routes, configuring obstacle avoidance and carving, connecting separate NavMeshes with links, coupling navigation with animation, or troubleshooting navigation issues.

unity-technologies/levelplay-unity-integration

Integrates the LevelPlay Mediation SDK via the Ads Mediation UPM package. Use when a developer asks about adding ads to a Unity game, implementing rewarded, interstitial, or banner ads, setting up ad mediation, configuring ad networks, installing or updating the Ads Mediation package, troubleshooting LevelPlay namespace errors, resolving Android gradle or iOS CocoaPods dependency issues for ads, configuring ATT or privacy settings for ad compliance, tracking impression-level revenue (ILRD), initializing the LevelPlay SDK, or setting up ad unit IDs. Also use when a developer wants to monetize their Unity game with ads, asks how to get started with LevelPlay, ads, or mediation, or needs help with any part of the LevelPlay integration workflow including platform-specific setup for iOS or Android. Also use when upgrading the LevelPlay or IronSource SDK version, migrating from deprecated IronSource.Agent APIs, or migrating a game from Unity Ads to LevelPlay.

unity-technologies/localization

Sets up and configures Unity Localization, including locales, String/Asset Tables, CJK font support, and Addressables workflows. Use when the user wants to add languages to a project, translate UI text, support Asian (CJK) languages with TMP fonts, or mentions i18n, l10n, multilingual support, or making a game support multiple languages.

unity-technologies/manage-sprite-atlas

Manage SpriteAtlas using prebuild pipeline with IPreprocessBuildWithReport (DEFAULT approach). Use it to configure master atlases, variant atlases, texture settings, packing settings, and platform-specific configurations. Use when the user asks about creating sprite atlases, optimizing sprites, configuring atlas settings, adding sprites to atlases, creating variant atlases, implementing automated atlas generation, or runtime sprite atlas access. Always use prebuild approach unless user explicitly requests manual authoring.

unity-technologies/migrate-birp-to-urp

Plans, executes, and troubleshoots Unity projects moving from the Built-in Render Pipeline (BiRP/BIRP/Built-in RP) to the Universal Render Pipeline (URP). Use when the user asks to upgrade, convert, switch, or migrate a project, scene, material, or shader to URP/Universal Render Pipeline; fix pink or magenta materials after URP; convert Built-in materials/shaders; move a 2D project to URP 2D; review lighting, quality, post-processing, baked lightmaps, or reflection probes after URP; or diagnose visual problems after a render-pipeline migration.

相关技能