Token导航 LogoToken导航TokenDH.com
待分类需要联网github未标认证来源可访问许可证需确认审计通过

unity-2dUnity 2D 命令行

Agent Skill

unity-2d 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

404

周安装

17

GitHub Stars

14

下载量

141
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:unity-2d(Unity 2D 命令行)
来源仓库:https://github.com/nice-wolf-studio/unity-claude-skills
仓库路径:skills/unity-2d
安装命令:
npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-2d
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/nice-wolf-studio/unity-claude-skills --skill unity-2d

简介

用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在需要围绕仓库状态、代码变更或协作事项进行整理时使用。
  • 可结合来源仓库和原始 README 核验具体用法。
  • 安装前建议确认权限范围、维护状态及是否会触发联网或文件读写。
  • unity-2d 属于待分类类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

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:

PropertyDescription
spriteThe Sprite asset to render
colorTint color applied to the sprite (default: white = no tint)
flipX / flipYFlip the sprite along an axis without moving the Transform
drawModeSimple, Sliced, or Tiled
sizeDimensions when using Sliced or Tiled draw modes
sortingLayerNameName of the renderer's sorting layer
sortingOrderPriority within a sorting layer (lower renders first)
maskInteractionNone, Visible Inside Mask, or Visible Outside Mask
spriteSortPointCenter 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

PropertyDescription
TypeMaster (default) or Variant
Include in BuildInclude in current build (default: enabled)
Allow RotationRotate sprites when packing to maximize density (default: enabled). Disable for Canvas UI
Tight PackingUse sprite outlines instead of rectangles for denser packing (default: enabled)
PaddingBuffer space between sprites (default: 4 pixels)
Read/Write EnabledAllow script access to texture data (doubles memory)
Generate Mip MapsEnable mipmaps for the atlas
Filter ModeControls texture filtering, overrides individual sprite settings
Objects For PackingList 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

PropertyDescription
Animation Frame RatePlayback speed multiplier for tile animations
ColorTint applied to all tiles (default: white)
Tile AnchorOffset for tile anchor positions (measured in cells)
OrientationXY, XZ, YX, YZ, ZX, ZY, or Custom

TilemapRenderer Modes

ModeDescription
ChunkGroups tiles by location/texture for batching. Best rendering performance
IndividualRenders each tile separately. Allows interaction with other renderers and custom sorting
SRP BatchCompatible with URP 15+. Groups tiles with sequential batching

Additional TilemapRenderer properties:

  • Sort Order: Direction tiles are sorted during rendering
  • Detect Chunk Culling Bounds: Auto or Manual (prevents sprite clipping)
  • Material: Material for rendering sprite textures
  • Mask Interaction: None, Visible Inside Mask, or Visible Outside Mask
  • Sorting Layer / Order in Layer: Render priority controls

Tilemap Scripting API

using UnityEngine;
using UnityEngine.Tilemaps;

Tilemap tilemap = GetComponent<Tilemap>();

// Single tile operations
tilemap.SetTile(new Vector3Int(x, y, 0), tile);      // Place tile
tilemap.SetTile(new Vector3Int(x, y, 0), null);       // Remove tile
TileBase t = tilemap.GetTile(new Vector3Int(x, y, 0)); // Read tile

// Batch operations (faster than individual SetTile in loops)
tilemap.SetTiles(positionsArray, tilesArray);
tilemap.BoxFill(pos, tile, startX, endX, startY, endY);
tilemap.FloodFill(pos, tile);
tilemap.SwapTile(oldTile, newTile);

// Coordinate conversion
Vector3 worldPos = tilemap.CellToWorld(cellPos);
Vector3Int cellPos = tilemap.WorldToCell(worldPosition);

// Bounds management -- ALWAYS call after procedural generation
tilemap.CompressBounds();
BoundsInt bounds = tilemap.cellBounds;

// Clear
tilemap.ClearAllTiles();
tilemap.RefreshAllTiles();

Key properties: cellBounds, localBounds, size, origin, animationFrameRate Key events: tilemapTileChanged, tilemapPositionsChanged, loopEndedForTileAnimation

See references/tilemaps.md for procedural generation examples, Rule Tiles, and TilemapCollider2D setup.

Source: https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Tilemaps.Tilemap.html

2D Physics Overview

Unity's 2D physics system provides optimized components for 2D interactions. "Unity's physics system lets you handle 2D physics to make use of optimizations available with 2D."

Core Components

ComponentDescription
Rigidbody2D"A component that allows a GameObject to be affected by simulated gravity and other forces"
Collider2D"An invisible shape that is used to handle physical collisions for an object"
Physics Material 2DControls friction and bounce between colliding 2D physics objects
Constant Force 2DAdds constant force or torque to GameObjects with a Rigidbody
Effectors 2DControl forces when GameObject colliders are in contact
2D JointsDynamic connections between Rigidbody components allowing constrained movement

Rigidbody2D Key Properties

PropertyDescription
bodyTypeDynamic, Kinematic, or Static
linearVelocityRate of position change (world units/second)
angularVelocityRotation speed (degrees/second)
massRigidbody weight
gravityScaleDegree of gravity influence
linearDampingLinear velocity resistance
angularDampingAngular velocity resistance
constraintsFreeze position/rotation on axes
collisionDetectionModeDiscrete or Continuous
interpolationNone, Interpolate, or Extrapolate

Rigidbody2D Key Methods

Rigidbody2D rb = GetComponent<Rigidbody2D>();

// Apply forces
rb.AddForce(Vector2.up * 10f);
rb.AddForce(Vector2.right * 5f, ForceMode2D.Impulse);
rb.AddForceAtPosition(force, position);
rb.AddTorque(15f);

// Move (use in FixedUpdate for physics-safe movement)
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
rb.MoveRotation(rb.rotation + rotationSpeed * Time.fixedDeltaTime);

// Query
rb.Cast(direction, results, distance);
rb.ClosestPoint(worldPoint);
rb.Distance(otherCollider);
rb.GetContacts(contacts);
rb.IsAwake();
rb.IsSleeping();

Physics2D Static Methods (Queries)

// Raycast
RaycastHit2D hit = Physics2D.Raycast(origin, direction, distance, layerMask);
RaycastHit2D[] hits = Physics2D.RaycastAll(origin, direction);

// Shape casts
RaycastHit2D boxHit = Physics2D.BoxCast(origin, size, angle, direction, distance);
RaycastHit2D circleHit = Physics2D.CircleCast(origin, radius, direction, distance);

// Overlap detection
Collider2D col = Physics2D.OverlapCircle(point, radius, layerMask);
Collider2D[] cols = Physics2D.OverlapCircleAll(point, radius);
Collider2D boxCol = Physics2D.OverlapBox(point, size, angle, layerMask);
Collider2D pointCol = Physics2D.OverlapPoint(point, layerMask);

// Utilities
float dist = Physics2D.Distance(colliderA, colliderB).distance;
bool touching = Physics2D.IsTouching(colliderA, colliderB);
// 2D platformer: ground check + jump + horizontal movement
Rigidbody2D rb = GetComponent<Rigidbody2D>();

// In Update: ground check and jump
bool isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
// Note: Uses legacy Input Manager for simplicity. See unity-input for the new Input System.
if (Input.GetButtonDown("Jump") && isGrounded)
    rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);

// In FixedUpdate: horizontal movement (preserves vertical velocity)
float move = Input.GetAxisRaw("Horizontal");
rb.linearVelocity = new Vector2(move * moveSpeed, rb.linearVelocity.y);

Source: https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Rigidbody2D.html Source: https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Physics2D.html

2D Lighting (URP)

2D Lighting requires the Universal Render Pipeline (URP) with a 2D Renderer. Use the 2D (URP) template or configure URP manually.

Light 2D Types

TypeDescription
GlobalIlluminates all objects on target sorting layers. Cannot use normal maps
FreeformCustom-shaped light defined by editable vertices
SpriteUses a sprite texture to define light shape
SpotCone-shaped light with direction and angle
PointEmits light in all directions from a point

Light 2D Properties

PropertyDescription
ColorLight color
IntensityBrightness multiplier (can exceed 1 to overbrighten sprites)
Light OrderRender queue position (lower renders first)
Overlap OperationAdditive (pixel values added) or Alpha Blend
Target Sorting LayersLights only illuminate sprites on selected sorting layers
DistancePerceived distance between light and surface
Volume OpacityVolumetric lighting visibility (0-1)
Shadow IntensityHow much Shadow Caster 2Ds block light (0-1)
Normal MapsSupported on non-global light types
using UnityEngine;
using UnityEngine.Rendering.Universal;

public class DayNightCycle : MonoBehaviour
{
    [SerializeField] private Light2D globalLight;
    [SerializeField] private Color dayColor = Color.white;
    [SerializeField] private Color nightColor = new Color(0.1f, 0.1f, 0.3f);
    [SerializeField] private float cycleDuration = 60f;

    void Update()
    {
        float t = Mathf.PingPong(Time.time / cycleDuration, 1f);
        globalLight.color = Color.Lerp(dayColor, nightColor, t);
        globalLight.intensity = Mathf.Lerp(1f, 0.3f, t);
    }
}

Source: https://docs.unity3d.com/6000.3/Documentation/Manual/urp/2d-light-properties-explained.html

Sorting Layers and Order

"Sorting Groups allow you to group GameObjects with Sprite Renderers together, and control the order in which they render their sprites." Unity treats all Sprite Renderers within the same Sorting Group as a unified rendering unit.

Sorting Layer System

Sorting layers define the broad rendering order. Within each layer, Order in Layer (integer) sets the specific priority. Lower numbers render first (appear behind higher numbers).

Sorting Group Component

The Sorting Group component organizes child renderers into a single sortable unit. Use cases:

  • Complex multi-sprite characters (body parts as separate sprites)
  • Groups of related objects that should sort together against the environment

Properties:

  • Sorting Layer: Assigns the group to a sorting layer
  • Order in Layer: Priority within the sorting layer

Nested Sorting Groups are supported: inner groups sort among themselves first, then the outer group sorts as a unit against other renderers.

// Y-sort for top-down games (attach to entities)
void LateUpdate()
{
    int order = Mathf.RoundToInt(-transform.position.y * 100);
    GetComponent<SpriteRenderer>().sortingOrder = order;
}

// Set sorting layer and order via script
SpriteRenderer sr = GetComponent<SpriteRenderer>();
sr.sortingLayerName = "Characters";
sr.sortingOrder = 10;
sr.sortingLayerID = SortingLayer.NameToID("Characters"); // faster

Source: https://docs.unity3d.com/6000.3/Documentation/Manual/sprite/sorting-group/sorting-group-landing.html

Common Patterns (C#)

Top-Down Movement (Rigidbody2D, no gravity)

public class TopDownMovement : MonoBehaviour
{
    [SerializeField] private float moveSpeed = 5f;
    private Rigidbody2D rb;
    private Vector2 moveInput;

    void Awake() { rb = GetComponent<Rigidbody2D>(); rb.gravityScale = 0f; }
    void Update() // legacy Input; see unity-input
    {
        moveInput = new Vector2(Input.GetAxisRaw("Horizontal"),
            Input.GetAxisRaw("Vertical")).normalized;
    }
    void FixedUpdate()
    {
        rb.MovePosition(rb.position + moveInput * moveSpeed * Time.fixedDeltaTime);
    }
}

Sprite Direction Flip / Camera Follow / Tilemap Click

// Flip sprite based on movement direction (legacy Input; see unity-input)
float h = Input.GetAxisRaw("Horizontal");
if (h != 0) spriteRenderer.flipX = h < 0;

// Simple 2D camera follow (attach to Camera, set offset.z = -10)
void LateUpdate()
{
    Vector3 desired = target.position + offset;
    transform.position = Vector3.Lerp(transform.position, desired, smoothSpeed * Time.deltaTime);
}

// Place tile at mouse click
Vector3 worldPos = cam.ScreenToWorldPoint(Input.mousePosition);
Vector3Int cellPos = tilemap.WorldToCell(worldPos);
tilemap.SetTile(cellPos, tileToPlace);

Anti-Patterns

  1. Using 3D physics for 2D games: Always use Rigidbody2D and Collider2D, never Rigidbody/BoxCollider. The 2D physics engine is separate and optimized for 2D.
  2. Moving Rigidbody2D with Transform: Never use transform.position to move physics objects. Use Rigidbody2D.MovePosition() in FixedUpdate or AddForce(). Direct Transform manipulation bypasses physics simulation and breaks collision detection.
  3. Scaling sprites with Transform.localScale at runtime: Use SpriteRenderer.size with Sliced/Tiled draw modes instead. Transform scale causes issues with colliders and is less performant.
  4. Forgetting to call CompressBounds() on procedural Tilemaps: After generating tiles procedurally, call tilemap.CompressBounds() to recalculate bounds. Without it, iteration over cellBounds includes empty space.
  5. One draw call per sprite (no atlasing): Pack related sprites into a Sprite Atlas. Without atlasing, each unique texture triggers a separate draw call.
  6. Enabling Read/Write on Sprite Atlas unnecessarily: This doubles memory usage. Only enable when you need script access via Texture2D.SetPixels.
  7. Using Allow Rotation on UI sprites: Disable Allow Rotation in Sprite Atlas settings when packing sprites used in Canvas UI, as rotation breaks UI layout.
  8. Not setting TilemapRenderer mode appropriately: Use Chunk mode for static tilemaps (best performance). Use Individual mode only when tiles need to interact with other renderers or require custom sorting.
  9. Using continuous collision detection everywhere: Only set collisionDetectionMode to Continuous on fast-moving objects. Discrete is cheaper and sufficient for most 2D objects.
  10. Ignoring Sorting Layers: Relying solely on Order in Layer leads to magic numbers. Define meaningful Sorting Layers (Background, Midground, Characters, Foreground, UI) and use Order in Layer for fine-tuning within each layer.

Key API Quick Reference

ClassKey Members
SpriteRenderer.sprite, .color, .flipX, .flipY, .drawMode, .size, .sortingLayerName, .sortingOrder
SpriteAtlas.GetSprite(name), .GetSprites(sprites[]), SpriteAtlasManager.atlasRequested
Tilemap.SetTile(), .GetTile(), .SetTiles(), .ClearAllTiles(), .BoxFill(), .FloodFill(), .SwapTile(), .WorldToCell(), .CellToWorld(), .CompressBounds(), .cellBounds
Rigidbody2D.linearVelocity, .angularVelocity, .AddForce(), .MovePosition(), .MoveRotation(), .Cast(), .bodyType, .gravityScale, .mass
Physics2D.Raycast(), .BoxCast(), .CircleCast(), .OverlapCircle(), .OverlapBox(), .OverlapPoint(), .IsTouching()
Light2D.color, .intensity, .lightType (requires UnityEngine.Rendering.Universal)
SortingGroup.sortingLayerName, .sortingOrder

Related Skills

  • unity-foundations -- GameObjects, Components, Transforms, Prefabs, ScriptableObjects
  • unity-physics -- In-depth 3D/2D physics, joints, raycasting, physics materials
  • unity-graphics -- Rendering pipelines, materials, shaders, post-processing
  • unity-lighting-vfx -- URP lighting setup, visual effects, particle systems

Additional Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.83%
按下载量换算49

Claude

29.22%
按下载量换算41

Cursor

18.08%
按下载量换算25

Gemini CLI

7.96%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills