Communitygithub.com

unity-technologies/build-live-game

使用 Unity Gaming Services 建構並營運即時遊戲。當使用者需要實作、連接或除錯後端驅動功能時使用,包含戰鬥通行證、成就、玩家進度、雲端存檔、排行榜、配對、虛擬經濟、伺服器授權邏輯、反作弊、玩家帳號與驗證、遠端設定、功能開關、A/B 測試、分析或雲端資源部署。觸發於即時營運、後端服務、伺服器授權、雲端程式碼、雲端存檔、遠端設定、玩家資料、留存、營利循環、季票、排名、多人遊戲階段、大廳或任何 Unity Services 整合。

build-live-game 是什麼?

這個技能提供了使用 Unity Gaming Services(UGS)構建即時遊戲的完整指南。它涵蓋了所有核心 UGS 套件,包括 Core、Authentication、Cloud Code、Cloud Save、Remote Config、Economy、Multiplayer、Leaderboards 和 Analytics,並說明了它們如何在 Unity 遊戲中協同工作。此技能主要適用於 Unity Editor 和 C# 開發環境,為遊戲客戶端和伺服器端邏輯提供支援。關鍵的架構原則是:對於任何影響遊戲完整性(例如經驗值、獎勵、貨幣)的資料,都應透過 Cloud Code 模組路由寫入,以確保資料安全;而對於非敏感資料(如偏好設定),則允許客戶端直接寫入。該指南還包括初始化模式、套件地圖、快速參考、資產儲存庫建置區塊、現成功能藍圖、常見架構模式、驗證與部署檢查清單,以及詳細參考資料。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

使用 Unity Gaming Services 構建即時遊戲

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 Editor 部署雲端資源 (.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 模組路由寫入。直接客戶端寫入僅適用於非敏感資料(偏好設定、顯示設定)。

核心服務 — 快速參考

Authentication

套件: com.unity.services.authentication (>= 3.6.1)

處理玩家身分識別。登入方式:匿名、社交提供者(Google、Apple、Steam、Facebook、Oculus 等)、Unity 瀏覽器、使用者名稱/密碼和裝置代碼流程。

登入後:可取得 PlayerId 和 PlayerName。所有登入方式都會觸發 SignedIn 事件。PlayerAccountService(用於 Unity 瀏覽器登入)位於單獨的程式集 (Unity.Services.Authentication.PlayerAccounts)。

Cloud Code

套件: com.unity.services.cloudcode (>= 2.10.3)

執行伺服器端 C# 模組 (.NET 9) 以進行可信操作。模組以 .ccmr 檔案部署。客戶端呼叫:

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

在生產環境中,建議優先使用 C# 模組而非 JavaScript 指令碼。模組也支援透過訂閱傳送即時推送訊息、事件驅動觸發器和多人遊戲階段範圍。

Cloud Save

套件: com.unity.services.cloudsave (>= 3.4.0)

每個玩家的鍵值儲存,具有三種存取類別,以及遊戲範圍的自訂資料:

存取類別讀取寫入使用案例
預設擁有者擁有者私人設定、偏好設定
公開任何人擁有者公開個人檔案、顯示名稱
受保護擁有者僅限伺服器 (Cloud Code)反作弊資料、伺服器授予的狀態
自訂任何玩家僅限伺服器共享遊戲狀態、全域設定

值序列化為 JSON。支援透過 SaveItem 的寫入鎖定並發控制、透過 QueryAsync 的伺服器端查詢,以及二進位檔案儲存。

Remote Config

套件: com.unity.remote-config (>= 4.2.5)

從伺服器端調整遊戲行為,無需更新應用程式。支援:

  • 設定值 — 鍵值配對(整數、浮點數、字串、布林值)
  • JSON 定義 — 結構化資料區塊
  • 功能開關 — 布林值開關,用於逐步推出或區域鎖定
  • 遊戲覆蓋 — 針對特定玩家(透過工具套件)的臨時覆蓋
RemoteConfigService.Instance.FetchConfigs(new UserAttributes(), new AppAttributes());
float difficultyMultiplier = RemoteConfigService.Instance.GetFloat("difficulty", 1.0f);
bool isSeasonPassActive = RemoteConfigService.Instance.GetBool("season_pass_enabled", false);

Economy

套件: com.unity.services.economy (>= 3.4.0)

管理虛擬經濟。支援貨幣(軟性、硬性、高級)、庫存物品(消耗品、耐久品、捆綁包)、商店(每日/每週商品)和購買驗證。所有貨幣和庫存授予必須由 Cloud Code 處理:

// 客戶端(僅用於顯示)
var balances = await EconomyService.Instance.GetBalancesAsync();

// 伺服器(透過 Cloud Code 授予/花費)
// modules/economy/GrantCurrency.ccmr

Multiplayer

套件: com.unity.services.multiplayer (>= 1.2.0)

提供階段、配對、大廳和即時訊息傳遞。三個關鍵建置區塊:

  1. 多人遊戲階段 — 玩家可以自由加入/離開的持久階段
  2. 配對階段 — 具有技能/區域/佇列預設條件的自動配對階段
  3. 伺服器階段 — 由專用伺服器託管的階段
var session = await MultiplayerService.Instance.CreateSessionAsync(
    new CreateSessionOptions { MaxPlayers = 10 });
await session.JoinAsync();

Leaderboards

套件: com.unity.services.leaderboards (>= 1.1.0)

分數提交、基於百分比的排名、分層排行榜、版本歷史和時間範圍。

var entry = await LeaderboardsService.Instance.AddPlayerScoreAsync(
    "global_leaderboard", 1500);
var scores = await LeaderboardsService.Instance.GetScoresAsync(
    "global_leaderboard");

Analytics

套件: com.unity.services.analytics (>= 5.1.0)

自訂事件、標準事件和同意管理。用於追蹤玩家行為、留存和營利指標。所有事件在佇列中分批處理,並在背景發送以最小化效能影響。

資產儲存庫建置區塊

這些是可從 Unity Asset Store 下載的即用型功能包,與 UGS 整合。每個建置區塊都包含 UI、指令碼和遊戲設計師設定。

建置區塊描述使用哪些服務
玩家帳號登入 UI、身分管理、玩家資料驗證、Cloud Save(公開資料)
玩家進度關卡、經驗值、等級、解鎖Cloud Save(預設資料)、Cloud Code(升級驗證)
成就成就追蹤、掉落獎勵、UICloud Save(受保護資料)、Cloud Code
虛擬經濟貨幣、庫存、商店 UIEconomy、Cloud Code(授予/花費)
功能開關與 A/B 測試可設定的功能開關、遠端變體Remote Config、Tooling(遊戲覆蓋)
排行榜排行榜 UI、分數提交、層級Leaderboards、Cloud Code(分數驗證)
多人遊戲階段階段列表、建立/加入 UIMultiplayer(階段)
配對階段配對佇列 UI、自動階段建立Multiplayer(配對)
伺服器階段專用伺服器、遊戲狀態、生命週期Multiplayer、Cloud Code

現成功能藍圖

功能藍圖是完整功能的實作模式,顯示多個套件如何協同工作。

每日獎勵

玩家 A 登入
  → 檢查上次領取時間(Cloud Save:預設,"last_claim_date")
  → 如果不同日期:呼叫 Cloud Code
    → Cloud Code 驗證日期
    → Economy 授予貨幣
    → Cloud Save 寫入"last_claim_date"(受保護)
  → 顯示 UI

季票 / 戰鬥通行證

Remote Config 定義通行證獎勵和經驗值門檻
Cloud Save 追蹤玩家的經驗值、等級和已領取獎勵
Cloud Code 驗證等級進度和獎勵領取
Economy 授予付費通行證解鎖後的溢價獎勵線

反作弊驗證管道

玩家完成回合
→ 客戶端發送:分數、遊戲時間戳、輸入哈希
→ Cloud Code 接收
  → 驗證哈希與伺服器模擬
  → 檢查時間戳合理性(防止時間操縱)
  → 將分數寫入 Leaderboards(受保護 Cloud Save 支援)

常見架構模式

僅客戶端模式(原型/單人遊戲階段)

遊戲 → Cloud Save(玩家資料)
     → Remote Config(設定)
     → Analytics(事件)

適合不需要伺服器驗證的原型或單人遊戲階段。所有寫入都是客戶端發起的。

伺服器授權模式(競爭性/排行榜/經濟)

遊戲 → Cloud Code(所有寫入) → Cloud Save(受保護資料)
     → Remote Config(設定)     Economy(授予)
     → Analytics(事件)           Leaderboards(分數)

對於任何具有競爭性或貨幣價值的資料都是必需的。Cloud Code 模組是任何寫入操作的唯一授權者。

多人遊戲模式(階段/配對)

遊戲 → Multiplayer(階段管理)
     → Cloud Code(階段內邏輯)
     → Cloud Save(玩家綁定資料)
     → Analytics(階段結束事件)

將 Multiplayer 用於階段生命週期,使用 Cloud Code 進行階段內伺服器邏輯(例如回合驗證、玩家計分)。

驗證

將以下驗證添加到您的遊戲整合測試套件中:

  1. 初始化驗證: UnityServices.InitializeAsync() 不會拋出 ServicesInitializationException
  2. 登入驗證: SignInAnonymouslyAsync() 完成後,AuthenticationService.Instance.PlayerId 不為空
  3. Cloud Save 讀取/寫入循環: 寫入一個鍵,讀取回來,驗證值
  4. Cloud Code 模組呼叫: 對雲端部署的模組進行端到端測試
  5. Remote Config 取得: FetchConfigs 完成且 GetFloat/GetBool/GetString 傳回預期值
  6. Economy 餘額: GetBalancesAsync() 成功,所有配置的貨幣都已定義
  7. Leaderboards 分數提交: AddPlayerScoreAsync 成功,GetScoresAsync 包含提交的條目
  8. Multiplayer 階段建立: 使用預期選項建立階段,成功加入
  9. Analytics 事件: 自訂事件在不拋出異常的情況下排入佇列

部署檢查清單

  • 已安裝所有必要的 UGS 套件(請參閱套件地圖)
  • 在 Unity 雲端儀表板上設定專案
  • 環境(開發/測試/生產)已正確設定
  • 所有 Cloud Code 模組已透過部署套件部署(.ccmr 檔案)
  • 存取控制已套用至 Cloud Code 模組(僅由玩家呼叫)
  • Remote Config 設定已在儀表板上建立並已推送
  • Economy 配置(貨幣、物品、商店)已定義
  • Leaderboard 配置已建立
  • Multiplayer 階段設定已設定
  • 測試玩家已在 UGS 儀表板上註冊
  • 已執行整合驗證測試(請參閱驗證)
  • 部署後:在編輯器外部(獨立建置)測試以確保正確初始化

詳細參考資料

主題檔案
Authenticationreferences/authentication.md
Cloud Codereferences/cloud-code.md
Cloud Savereferences/cloud-save.md
Remote Configreferences/remote-config.md
Economyreferences/economy.md
Multiplayerreferences/multiplayer.md
Leaderboardsreferences/leaderboards.md
Analyticsreferences/analytics.md
Tooling (Access Control)references/access-control.md
Tooling (Game Overrides)references/game-overrides.md
Deploymentreferences/deployment.md

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.

相關技能