<!-- skill: Unity 2D Toolkit | version: 1.0.0 | description: Build polished 2D games in Unity with Tilemaps and Cinemachine | category: Games -->
## Instructions
- Use URP 2D Renderer + 2D packages (Tilemap, Sprite Atlas, Cinemachine, Input System); target Unity 2022 LTS+.
- Paint levels with Tilemaps + RuleTiles: one Tilemap per layer (Ground, Decor, Collision), TilemapCollider2D + Composite for perf.
- Pack sprites with Sprite Atlas (tight packing, 2048 max, Crunch for mobile); set PPU 16/32 consistently, filter Point for pixel-art.
- Drive physics with Rigidbody2D (Dynamic for player, Kinematic for movers): interpolate, Continuous collision for fast bodies.
- Frame camera with Cinemachine 2D: Framing Transposer + Confiner (Tilemap bounds), Pixel Perfect Camera for retro looks.
- Manage depth with Sorting Layers (Background/World/Foreground) + Order in Layer; use Y-sort for top-down via SortingGroup.
- Animate with Animator + 2D Animation (bones) or simple sprite-swap; use Animation Events for footstep/hit triggers.
- Handle input via Input System actions (Move/Jump/Dash) with keyboard+gamepad+touch bindings; add on-screen sticks for mobile.
- Optimize mobile 2D: sprite atlas reuse, disable shadows, cap particles, pool projectiles, Application.targetFrameRate 60.
- Persist with JSON in Application.persistentDataPath; version saves, backup slot, test cold start + upgrade path.
- Profile with Profiler 2D Physics + Frame Debugger; keep draw calls <80 mobile, overdraw low, GC alloc zero in Update.
- Ship with Addressables for levels/skins; build profiles for Android (ETC2) + iOS (ASTC), test on low-end device.
## Examples
- Example 1 — Platformer Tilemap: RuleTile ground + CompositeCollider, player Rigidbody2D Dynamic, coyote 0.1s, jump buffer wired via Input.
- Example 2 — Top-down Y-sort: SortingGroup on props, Transparency Sort Axis Y=1, Cinemachine confiner locked to level bounds.
- Example 3 — Mobile runner: Sprite Atlas packed env, pooled coins (50), Pixel Perfect on, 60fps locked on Pixel 4a test.
## Workflows
1. Setup: URP 2D template, PPU 32, Input Actions asset, Sorting Layers, Atlas v1, Cinemachine confiner from Tilemap.
2. Level: paint RuleTile ground, add hazards/pickups prefabs, Camera follow + parallax 0.5 layers, playtest jump feel.
3. Systems: health/inventory singletons, save/load JSON, HUD (TMP) + pause, audio mixer groups, pool manager.
4. Mobile pass: atlas crunch, touch controls, targetFrameRate, profiler on device, reduce overdraw + colliders.
5. Ship: Addressables build, Android App Bundle + TestFlight, store icons/screenshots, staged rollout with crash reporting.
## Templates
### Unity C# 2D Controller (Rigidbody2D)
```csharp
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(Rigidbody2D))]
public class Player2D : MonoBehaviour {
  public float speed = 7f, jumpForce = 13f;
  Rigidbody2D rb; Vector2 move; float coyote, buffer;
  void Awake(){ rb = GetComponent<Rigidbody2D>(); rb.interpolation = RigidbodyInterpolation2D.Interpolate; }
  public void OnMove(InputValue v){ move = v.Get<Vector2>(); }
  public void OnJump(InputValue v){ if(v.isPressed) buffer = 0.12f; }
  void Update(){
    coyote -= Time.deltaTime; buffer -= Time.deltaTime;
    float tx = move.x * speed;
    rb.linearVelocity = new Vector2(tx, rb.linearVelocity.y);
    if(buffer>0 && coyote>0){ rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce); buffer=0; coyote=0; }
  }
  void OnCollisionEnter2D(Collision2D c){ if(c.contacts[0].normal.y > 0.7f) coyote = 0.1f; }
}
```
### RuleTile + Sorting Setup
```
Tilemaps: Ground(RuleTile, Collider+Composite) / Decor(NoCollider) / Hazards(IsTrigger)
Sorting Layers: BG(0) < Ground(5) < Entities(10) < FX(20) < UI(100)
Sprite Atlas: 2048, padding 4, Crunch 75 mobile / Truecolor PC
Cinemachine: vcam Follow=Player, DeadZone 0.3, Confiner=LevelBounds Collider
```
### Pool Manager snippet
```csharp
public class Pool : MonoBehaviour {
  public GameObject prefab; public int size=40; Queue<GameObject> q=new();
  void Start(){ for(int i=0;i<size;i++){var o=Instantiate(prefab,transform);o.SetActive(false);q.Enqueue(o);} }
  public GameObject Get(Vector2 p){var o=q.Count>0?q.Dequeue():Instantiate(prefab,transform);o.transform.position=p;o.SetActive(true);return o;}
  public void Release(GameObject o){o.SetActive(false);q.Enqueue(o);}
}
```
## Tools
- Unity 2022 LTS, URP 2D, Tilemap Extras (RuleTile), Sprite Atlas, Cinemachine, Input System, TextMeshPro.
- Profiler + Frame Debugger, Addressables, Cloud Diagnostics/Crashlytics, git + LFS for art.
- Aseprite, Tiled importer, Kenney 2D packs, PrimeTween/DOTween for juice.
## Advanced
- Use 2D lights (Freeform/Point) sparingly on mobile; bake glow into sprites, use normal maps only on hero assets.
- Implement predictive touch: fixed timestep 60Hz, max 3 substeps, deterministic pickups via seed; test airplane-mode saves.
- Automate builds with Build Profiles + Cloud Build; gate releases on FPS (p95 >55) and ANR <0.5%.
## Documentation
- https://docs.unity3d.com/Manual/TilemapsOverview.html
- https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@latest
- https://docs.unity3d.com/Packages/com.unity.cinemachine@latest
- https://docs.unity3d.com/Manual/class-SpriteAtlas.html
