Guides Unity game development with C#: project structure, architecture patterns (Service Locator, Singleton), input system, and ScriptableObject events. Activates on Unity, C#, game development topics.
Ships in claude-skills-collection. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
| Cible | Version recommandée | Pipeline |
|---|---|---|
| Mobile 2D/3D | LTS actuelle (6.x) | URP |
| PC/Console AAA | LTS actuelle | HDRP |
| WebGL / prototypage | LTS actuelle | URP ou Built-in |
# Créer un projet URP via CLI (Unity Hub)
Unity -createProject MyGame -version 6000.0.47f1 -templateId com.unity.template.urp-blank
Assets/
_Project/
Art/
Audio/
Prefabs/
ScriptableObjects/
Scripts/
Core/ ← managers, state machine, services
Gameplay/ ← character, enemies, interactions
UI/
Utils/
Scenes/
Tests/
EditMode/
PlayMode/
Règle : pas de scripts dans le dossier racine Assets. Tout code va sous _Project/Scripts/.
Option A — Service Locator (simple, no dependency)
public static class ServiceLocator
{
private static readonly Dictionary<Type, object> _services = new();
public static void Register<T>(T service) => _services[typeof(T)] = service;
public static T Get<T>()
{
if (_services.TryGetValue(typeof(T), out var svc)) return (T)svc;
throw new Exception($"Service {typeof(T).Name} non enregistré.");
}
}
// Au démarrage
ServiceLocator.Register<IAudioService>(new AudioService());
// Usage
ServiceLocator.Get<IAudioService>().Play("sfx_jump");
Option B — Singleton (acceptable pour GameManager, uniquement)
public class GameManager : MonoBehaviour
{
public static GameManager Instance { get; private set; }
private void Awake()
{
if (Instance != null) { Destroy(gameObject); return; }
Instance = this;
DontDestroyOnLoad(gameObject);
}
}
Critère de choix : > 2 singletons → passer au Service Locator ou Zenject/VContainer.
// PlayerControls.inputactions → générer la classe C#
public class PlayerController : MonoBehaviour
{
private PlayerControls _controls;
private void Awake()
{
_controls = new PlayerControls();
_controls.Player.Jump.performed += _ => OnJump();
}
private void OnEnable() => _controls.Enable();
private void OnDisable() => _controls.Disable();
private void OnJump() { /* logique */ }
}
Ne jamais utiliser Input.GetKey dans un nouveau projet — l'ancien Input Manager n'est pas rebindable.
Canal d'événement découplé
[CreateAssetMenu(menuName = "Events/GameEvent")]
public class GameEvent : ScriptableObject
{
private readonly List<GameEventListener> _listeners = new();
public void Raise()
{
for (int i = _listeners.Count - 1; i >= 0; i--)
_listeners[i].OnEventRaised();
}
public void Register(GameEventListener l) => _listeners.Add(l);
public void Unregister(GameEventListener l) => _listeners.Remove(l);
}
Usage : playerDied.Raise() depuis le gameplay, UI écoute sans référence directe au player.
using UnityEngine.Pool;
public class BulletSpawner : MonoBehaviour
{
[SerializeField] private Bullet _prefab;
private IObjectPool<Bullet> _pool;
private void Awake()
{
_pool = new ObjectPool<Bullet>(
createFunc: () => Instantiate(_prefab),
actionOnGet: b => b.gameObject.SetActive(true),
actionOnRelease: b => b.gameObject.SetActive(false),
actionOnDestroy: b => Destroy(b.gameObject),
defaultCapacity: 20, maxSize: 100
);
}
public void Shoot() => _pool.Get().Init(_pool);
}
// MAL — recherche en Update, allocation string
void Update()
{
var rb = GetComponent<Rigidbody>(); // alloc à chaque frame
Debug.Log("pos: " + transform.position); // string concat
}
// BIEN — cache en Awake, pas d'alloc
private Rigidbody _rb;
void Awake() => _rb = GetComponent<Rigidbody>();
void Update()
{
// utilise _rb directement, pas d'alloc
}
Checklist performance par domaine :
new en Update, utiliser StringBuilder, List.Clear() plutôt que new ListFixedUpdate uniquement pour les forces, LayerMask pour filtrer les raycastsStopCoroutine à la destruction// Blend Tree : X = horizontal, Y = vertical
// Paramètres via hash (plus rapide que string)
private static readonly int SpeedX = Animator.StringToHash("SpeedX");
private static readonly int SpeedY = Animator.StringToHash("SpeedY");
private void Update()
{
_animator.SetFloat(SpeedX, _moveInput.x);
_animator.SetFloat(SpeedY, _moveInput.y);
}
Pour les tweens UI ou effets procéduraux, préférer DOTween (gratuit, zéro GC en mode Blendable) :
transform.DOMove(target, 0.5f).SetEase(Ease.OutBack);
// EditMode — test pur C#
[Test]
public void StatCalculator_AppliesMultiplier()
{
var stat = new Stat(baseValue: 10f);
stat.AddModifier(new StatModifier(0.5f, ModType.Percent));
Assert.AreEqual(15f, stat.Value, 0.001f);
}
// PlayMode — test avec MonoBehaviour
[UnityTest]
public IEnumerator PlayerDies_WhenHealthZero()
{
var go = new GameObject();
var player = go.AddComponent<PlayerHealth>();
player.TakeDamage(9999);
yield return null; // une frame
Assert.IsTrue(player.IsDead);
}
Lancer en CLI :
Unity -runTests -testPlatform EditMode -testResults results.xml -batchmode -projectPath .
// Chargement asynchrone d'un prefab
var handle = Addressables.LoadAssetAsync<GameObject>("Enemies/Boss");
await handle.Task;
Instantiate(handle.Result);
// Ne pas oublier de libérer
Addressables.Release(handle);
Paramètres de build recommandés (Player Settings) :
| Anti-pattern | Problème | Alternative |
|---|---|---|
GameObject.Find() en Update | Recherche O(n) à chaque frame | Cache en Awake / [SerializeField] |
Instantiate/Destroy fréquents | GC spikes, hitches | Object Pool (§6) |
| Singleton sur tout | Couplage fort, tests impossibles | Service Locator ou Injection |
SendMessage | Réflexion lente, pas de typage | Events typés ou UnityEvent |
| Coroutines sans référence | Fuite mémoire, double-start | Stocker Coroutine _c et vérifier null |
Resources.Load au runtime | Tous les assets chargés en RAM | Addressables |
string dans Animator.SetFloat | Allocation + lenteur | Animator.StringToHash (§8) |
com.unity.addressables via Package ManagerWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
unity, csharp, game-architecture, service-locator, input-system, scriptable-object
/claude-skills-collection:dev-unity-game-helperfrom claude-skills-collection
npx claudepluginhub vantaflow/claude-skills-collection --plugin claude-skills-collection348 skills in this plugin
/agent-a2a-protocol-guideGuide du protocole Agent-to-Agent (A2A) de Google pour l'interopérabilité entre agents IA — découverte, communication et collaboration inter-agents, avec exemples de code, critères de décision et pièges à éviter. Se déclenche avec "A2A", "agent-to-agent", "protocole A2A", "Google A2A", "interopérabilité agents". Also triggers on "agent-to-agent protocol", "agent interoperability", "connect two agents"./agent-agent-observabilityInstrumentation technique d'un agent IA — tracing distribué des appels LLM et outils, spans, métriques custom, corrélation de logs et dashboards de supervision. Pour les alertes et garde-fous de production, voir agent-monitoring-setup. Se déclenche avec "observabilité agent", "tracing agent", "LangSmith", "Langfuse", "OpenTelemetry agent", "spans LLM", "corréler les logs agent". Also triggers on "trace my agent", "LLM tracing", "agent spans"./agent-api-caller-subagentSous-agent spécialisé dans les appels API REST/GraphQL avec retry, auth et transformation de données. Se déclenche avec "sous-agent API", "API caller agent", "agent qui appelle une API", "REST agent", "HTTP agent", "API integration subagent", "external API agent". Also triggers on "subagent that calls an API", "API calling agent", "agent HTTP requests".Other plugins' skills for the same job