unity-2d
Unity 6 2D game development guide. Use when building 2D games, working with sprites, sprite atlas, SpriteRenderer, tilemaps, 2D physics (Rigidbody2D, Collider2D), 2D lighting, sorting layers, or sorting groups. Based on Unity 6.3 LTS documentation.
Nice-Wolf-Studio · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add Nice-Wolf-Studio/unity-claude-skills --skill unity-2d技能说明
name: unity-2d description: > Unity 6 2D game development guide. Use when building 2D games, working with sprites, sprite atlas, SpriteRenderer, tilemaps, 2D physics (Rigidbody2D, Collider2D), 2D lighting, sorting layers, or sorting groups. Based on Unity 6.3 LTS documentation.
Unity 2D Development
2D Project Setup
Unity supports dedicated 2D project creation. When starting a 2D project:
- Select the 2D template (or 2D (URP) for 2D lighting support) when creating a new project
- The 2D template auto-installs required packages: 2D Sprite, 2D Tilemap Editor, 2D Animation
- The Scene view defaults to orthographic (top-down XY plane)
- The camera is set to Orthographic projection by default
- Imported images default to Sprite (2D and UI) texture type
Core 2D subsystems from the docs:
- Sprites: "2D graphic objects" -- the foundation for 2D games
- Tilemaps: "A GameObject that allows you to quickly create 2D levels using tiles and a grid overlay"
- 2D Physics: Dedicated physics system with 2D-optimized components
- 2D Rendering in URP: 2D lights, lighting effects, and pixelated visual styles
Source: https://docs.unity3d.com/6000.3/Documentation/Manual/Unity2D.html
Sprites and SpriteRenderer
Sprite Assets
Sprites are "a type of 2D asset you can use in your Unity project." They function as 2D graphic objects with specialized import and management features. The 2D Sprite package must be installed (included with 2D templates).
Key sprite capabilities:
- Import sprites or spritesheets from textures
- Use the Sprite Editor to cut sprites from textures (slicing)
- Apply cropping to remove transparent areas
- Create collision geometry for sprite physics
- 9-slicing for reusing sprites at various sizes
- Masking to hide or reveal parts of a sprite or group of sprites
Source: https://docs.unity3d.com/6000.3/Documentation/Manual/sprite/sprite-landing.html
SpriteRenderer Component
The SpriteRenderer component controls how sprites display in scenes. Key properties:
| Property | Description |
|---|---|
sprite | The Sprite asset to render |
color | Tint color applied to the sprite (default: white = no tint) |
flipX / flipY | Flip the sprite along an axis without moving the Transform |
drawMode | Simple, Sliced, or Tiled |
size | Dimensions when using Sliced or Tiled draw modes |
sortingLayerName | Name of the renderer's sorting layer |
sortingOrder | Priority within a sorting layer (lower renders first) |
maskInteraction | None, Visible Inside Mask, or Visible Outside Mask |
spriteSortPoint | Center or Pivot -- determines sort distance from camera |
Draw Modes:
- Simple (default): Uniformly scales the entire sprite
- Sliced: For 9-sliced sprites; scales according to 9-slice regions using Width/Height
- Tiled: For 9-sliced sprites; tiles the middle section. Tile Mode options: Continuous (even tiling) or Adaptive (stretches until threshold, then tiles)
Default material: Sprite-Lit-Default (customizable via Material picker)
// SpriteRenderer basic usage
SpriteRenderer sr = GetComponent<SpriteRenderer>();
sr.sprite = newSprite;
sr.color = Color.red;
sr.flipX = true;
sr.flipY = true;
sr.sortingLayerName = "Foreground";
sr.sortingOrder = 5;
See references/sprites-and-atlas.md for draw mode examples, sprite masking, and change callbacks.
Source: https://docs.unity3d.com/6000.3/Documentation/ScriptReference/SpriteRenderer.html
Sprite Atlas
A Sprite Atlas is "a utility that packs several sprite textures tightly together within a single texture known as an atlas." This reduces draw calls -- Unity uses one draw call for the atlas instead of separate calls per sprite.
Create: Assets > Create > 2D > Sprite Atlas (generates .spriteatlas file)
Sprite Atlas Properties
| Property | Description |
|---|---|
| Type | Master (default) or Variant |
| Include in Build | Include in current build (default: enabled) |
| Allow Rotation | Rotate sprites when packing to maximize density (default: enabled). Disable for Canvas UI |
| Tight Packing | Use sprite outlines instead of rectangles for denser packing (default: enabled) |
| Padding | Buffer space between sprites (default: 4 pixels) |
| Read/Write Enabled | Allow script access to texture data (doubles memory) |
| Generate Mip Maps | Enable mipmaps for the atlas |
| Filter Mode | Controls texture filtering, overrides individual sprite settings |
| Objects For Packing | List of sprites/folders to pack into the atlas |
Runtime API: "You can use the Sprite Atlas API to control loading the Sprite Atlases at your project's runtime."
// Load a sprite from a SpriteAtlas at runtime
using UnityEngine;
using UnityEngine.U2D;
public class AtlasLoader : MonoBehaviour
{
[SerializeField] private SpriteAtlas atlas;
private SpriteRenderer spriteRenderer;
void Start()
{
spriteRenderer = GetComponent<SpriteRenderer>();
Sprite sprite = atlas.GetSprite("player_idle");
spriteRenderer.sprite = sprite;
}
}
Late binding: Subscribe to SpriteAtlasManager.atlasRequested to load atlases on demand (for Addressables/AssetBundle workflows). See references/sprites-and-atlas.md for full late binding example.
Source: https://docs.unity3d.com/6000.3/Documentation/Manual/sprite/atlas/atlas-landing.html
Tilemap System
Tilemaps allow rapid 2D level creation using tiles and a grid overlay. The Tilemap component "stores and manages Tile Assets" and "transfers the required information from the tiles placed on it to other related components such as the Tilemap Renderer and the Tilemap Collider 2D."
Tilemap Component Properties
| Property | Description |
|---|---|
| Animation Frame Rate | Playback speed multiplier for tile animations |
| Color | Tint applied to |