Communitygithub.com

unity-technologies/manage-sprite-atlas

使用预构建管道(IPreprocessBuildWithReport)管理 SpriteAtlas。用于配置主图集、变体图集、纹理设置、打包设置和平台特定配置。

manage-sprite-atlas 是什么?

该技能为 Unity 项目中的精灵图集(SpriteAtlas)管理提供了一套完整的、编辑器安全的自动化方案。它强制遵循 V2 架构原则,严格区分编辑器阶段的 `SpriteAtlasAsset` 和运行时的 `SpriteAtlas`,避免了常见的上下文混淆。默认采用 `IPreprocessBuildWithReport` 预构建管道,在构建时自动生成或更新图集,无需手动操作菜单项,从而减少了人为错误。技能内置了丰富的参考资源(`resources/` 目录下的 C# 脚本和文档),涵盖了自定义打包器、变体、平台设置和运行时访问等功能。在使用前,它会强制要求开发者检查现有脚本、选择分发机制(内建或 Addressables 延迟绑定)、并确认精灵打包器模式已正确启用,确保图集能够在运行时真正生效。

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

在你喜欢的 AI 中提问

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

文档

Unity SpriteAtlas V2

提供编辑器安全的程序化知识,用于在 Unity 项目中编写图集脚本。V2 强制编辑器创作和运行时访问之间的严格分离。

⚠️ 关键的 V2 原则:SpriteAtlas 是仅限运行时的。SpriteAtlasAsset 是仅限编辑器的。切勿混淆上下文。始终使用 V2。

🚨 关键:实施前必须进行的检查和用户输入

在生成任何代码之前,始终执行以下检查并询问这些问题:

在编写代码前阅读随附的资源(必需)

此技能附带 resources/ 下的可工作 C# 代码,而出错的图集代码几乎总是没先阅读就直接编写的结果。打开你所选路径对应的文件,然后再编写。

选择此路径先阅读这些文件
任何图集相关工作resources/authoringvsruntime.cs, references/common-errors.md
预构建生成(默认)resources/spriteatlasprebuildgenerator.cs, resources/enablespritepacking.cs, resources/savespriteatlasasset.cs
选项 B,Addressables 延迟绑定resources/buildaddressablespostprocess.cs, resources/spriteatlaslatebinding.cs, resources/handlelatebinding.cs
任何可能使用旧版 API 的情况resources/deprecatedmethods.cs, resources/dontscriptspriteatlasineditor.cs, resources/dontpackinruntimebuilds.cs

resources/ 目录共包含 38 个文件,涵盖了自定义打包器、变体、平台设置和运行时访问。当你的任务不在上表中时,请浏览该目录,而不是凭空发明方法。仅凭记忆调用 API 而不是阅读这些文件,是导致图集能顺利导入但在运行时毫无作用的单一最常见原因。

0. 检查现有脚本(必需的第一步)

在生成任何代码之前,在项目中扫描由本技能生成的现有 SpriteAtlas 脚本。

搜索包含以下标识符的文件:// [UNITY-SKILL:SPRITEATLAS]

如果找到现有脚本,始终使用以下格式询问用户:

"我在您的项目中找到了现有的 SpriteAtlas 脚本:

预构建生成器:

  • Assets/Editor/SpriteAtlas/SpriteAtlasPrebuildGenerator.cs

Addressables 构建器:

  • Assets/Editor/SpriteAtlas/BuildAddressablesPostprocess.cs

运行时加载器:

  • Assets/Scripts/SpriteAtlas/SpriteAtlasLateBinding.cs

您希望怎么做?"

然后提供选项:

  • 选项 A:更新现有脚本(如果需求有变更,推荐)

    • 在现有路径上重新生成脚本
    • 保留文件位置
    • 更新到最新版本
    • ⚠️ 可能会覆盖自定义修改
  • 选项 B:使用不同名称创建新脚本

    • 与现有脚本并排生成
    • 支持多个图集配置
    • 原始脚本保持不变
    • 您需要指定新的名称/路径
  • 选项 C:中止(保持现有的不改变)

    • 不生成代码
    • 不更改项目
    • 如果您想保留当前设置,请选择此项

用户选择处理:

  • 如果选择 A:在现有路径重新生成,版本号递增至 2.0.1+
  • 如果选择 B:询问新脚本名称(例如 "SpriteAtlasPrebuild_Custom.cs"),然后生成
  • 如果选择 C:立即停止,告知用户未做任何更改

1. 交付机制(必需)

询问:"您希望如何交付精灵图集?"

选项 A:内建数据(立即加载)

  • 图集包含在构建中并立即加载
  • 设置 includeInBuild = true
  • 适用于:核心 UI、主要游戏性精灵、始终需要的资源
  • 优点:简单,无需额外包,即时访问
  • 缺点:增加初始构建大小,不能在没有新构建的情况下更新

选项 B:通过 Addressables 延迟绑定(按需加载)

  • 图集不包含在构建中,通过 Addressables 按需加载
  • 设置 includeInBuild = false
  • 为每个图集创建 Addressables 条目
  • 将 Addressables 设置作为预构建步骤添加
  • 🚨 必需:将 Addressables 内容构建作为构建步骤
  • 🚨 必需:创建延迟绑定运行时加载器脚本
  • 适用于:DLC 内容、可选功能、大型资源、可下载内容
  • 优点:更小的初始构建,可独立更新,按需加载
  • 缺点:需要 Addressables 包,异步加载,网络依赖
使用场景推荐
始终可见的核心 UI 精灵选项 A:内建
教程或引导精灵选项 A:内建
特定关卡的精灵(100 关以上)选项 B:Addressables
DLC 或季节性内容选项 B:Addressables
本地化 UI 精灵(多种语言)选项 B:Addressables
角色皮肤或装饰品选项 B:Addressables

2. SpritePacker 模式(必需)

在创建图集之前启用 Sprite Packer 模式,然后读回设置并确认其生效。 使用 resources/enablespritepacking.cs 中的代码;它设置 EditorSettings.spritePackerMode 并配置导入器的打包设置。

这是决定您生成的图集是否真实有效的步骤。Disabled 是 SpritePackerMode 的零值,因此任何没有人设置过它的项目都携带打包 Disabled,而在 Disabled 状态下创建的图集仍然可以导入、仍然作为资源显示、仍然看起来完成了,但永远无法打包。Unity 在 Inspector 中会这样说:"Sprite Atlas packing is disabled"。工作流中的其他任何步骤都不会失败,因此以这种方式交付的图集会被视为成功。不要假设项目已配置好:请读取该值。

因此,不要认为 "我已经设置了" 就完成了。设置之后,再次读取 EditorSettings.spritePackerMode,确认它不是 Disabled,并报告您实际读取到的值。如果您无法读回,请说明,不要假设写入已生效。

不要直接编辑 meta 文件。

🚨 关键:默认方法为预构建生成

始终使用 IPreprocessBuildWithReport 在构建管道期间自动生成或更新 SpriteAtlas。 这是默认且必需的方法,除非用户明确要求手动创作。

❌ 不要创建手动菜单项脚本

除非明确要求,否则切勿创建带有 [MenuItem] 属性的图集生成脚本。 预构建方法消除了手动点击的需要。仅在以下情况下使用手动创作:经过手动优化的布局、特定的精灵排列或编辑器预览需求。请参阅 高级:手动创作。

🚨 关键:精灵源位置限制

仅添加项目 Assets 文件夹中的精灵。切勿添加来自 Unity 内建资源、包或外部位置的精灵。 Unity 内建资源无法打包到 SpriteAtlas 中,而包资源可能会引起导入/依赖问题。

关键的 V2 架构

上下文组件用途允许的使用方式
编辑器SpriteAtlasAsset在编辑器资源中定义图集配置创作、设置纹理/打包/平台设置
编辑器IPreprocessBuildWithReport在构建时自动生成 SpriteAtlasAsset构建前的默认方案
运行时SpriteAtlas在构建或使用 LoadByLocation(延迟绑定)时加载的运行时对象仅用于访问 Sprite;不得在运行时创建
运行时UASSETBUNDLE/ADDRESSABLES包含图集用于按需加载与包含 includeInBuild = false 的 SpriteAtlasAsset 一起使用

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/build-live-game

Build and operate a live game using Unity Services. Use when the user needs to implement, connect, or debug backend-driven features — battle passes, achievements, player progression, cloud saves, leaderboards, matchmaking, virtual economies, server-authoritative logic, anti-cheat, player accounts and authentication, remote configuration, feature flags, A/B testing, analytics, or cloud resource deployment. Triggers on live-ops, live service, backend, server authority, cloud code, cloud save, remote config, player data, retention, monetization loop, season pass, ranking, multiplayer sessions, lobbies, or any Unity Services integration.

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/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.

相关技能