unity-project-architecture
БесплатноБез исполняемых скриптовНе проверенUse when writing or restructuring Unity C# code - assembly definitions and dependency direction, small components with cached references, ScriptableObjects…
от makifbaysal★ 123 звезды на GitHubОб этом скилле
Unity Project Architecture
Overview
Unity makes it easy to put everything in one MonoBehaviour that finds its collaborators with FindObjectOfType and a static Instance. That works for a jam and collapses after a few months: nothing is testable, compile times grow, and scene order decides behaviour. Structure the project as assemblies with a dependency direction, plain C# for rules, thin components for engine glue, and data in assets.
Core principle: Rules in plain C# assemblies, components as adapters, data in ScriptableObjects, dependencies passed in. The repository's existing layout and DI choice win.
Assemblies and direction
Game.Core (noEngineReferences: rules, math, state machines, save DTOs)
↑
Game.Runtime (MonoBehaviours, ScriptableObjects, adapters; references Core)
↑
Game.UI (views and presenters; references Runtime/Core, never the reverse)
Game.Editor (includePlatforms: Editor; tools, validators)
Tests.EditMode / Tests.PlayMode (test assemblies; see unity-testing)
{
"name": "Game.Core",
"rootNamespace": "Game.Core",
"references": [],
"noEngineReferences": true,
"autoReferenced": false
}
- An assembly per layer keeps compile times down and makes a wrong-way reference a compile error instead of a review comment.
Game.CorewithnoEngineReferences: truecan be compiled and tested by plaindotnet testwhen the editor is missing (testable-game-logic).- Gameplay never references UI; UI observes gameplay through events.
Components
// ❌ lookups every frame, public mutable fields, rules inside the component
public class Enemy : MonoBehaviour {
public int hp = 100;
void Update() {
var player = GameObject.Find("Player");
if (Vector3.Distance(transform.position, player.transform.position) < 5) GetComponent<Animator>().SetTrigger("Attack");
}
}
// ✅ cached references, serialized private fields, rule delegated to plain C#
[RequireComponent(typeof(Animator))]
public sealed class EnemyView : MonoBehaviour {
static readonly int AttackHash = Animator.StringToHash("Attack");
[SerializeField] EnemyDefinition definition;
Animator _animator; EnemyBrain _brain; ITargetProvider _targets;
public void Construct(ITargetProvider targets) => _targets = targets;
void Awake() { _animator = GetComponent<Animator>(); _brain = new EnemyBrain(definition.AttackRange); }
void Update() {
if (_brain.ShouldAttack(transform.position, _targets.PlayerPosition)) _animator.SetTrigger(AttackHash);
}
}
[SerializeField] privateover public fields; public API through properties and methods.Awakeinitialises the object itself;OnEnable/Startwire up to others;OnDisableunsubscribes everythingOnEnablesubscribed.[RequireComponent]for hard dependencies on the same GameObject;TryGetComponentinstead ofGetComponent+ null check.- Physics in
FixedUpdatethrough the Rigidbody API (MovePosition,AddForce,linearVelocity), nevertransform.positionon a dynamic body.
Data and events in ScriptableObjects
- Definitions (weapons, enemies, levels) are ScriptableObjects (data-driven-gameplay-design); runtime state is a separate object built from them. Changes made to a ScriptableObject in Play mode persist in the editor — never write gameplay state into one.
- Event channels (
GameEvent : ScriptableObjectwithRaise()and listeners) decouple scenes, but keep them few and named for what happened (PlayerDied), not what should happen.
Dependencies, not singletons
- Use the repository's container if it has one (VContainer, Zenject/Extenject): register services in a
LifetimeScope/installer and inject via constructor (plain classes) or[Inject]method (components). - Without one: a bootstrap scene or composition root creates services and passes them in (
Construct(...)as above). - No new
static Instancefor gameplay state. Engine-wide stateless helpers are fine as static classes.
Input, assets, async
- Input System, not the legacy
Inputclass — actions from the.inputactionsasset, rebinding and device glyphs (game-input-and-accessibility). A project still on the legacy Input Manager stays on it unless the task migrates it. - Addressables for content loaded at runtime (game-asset-pipeline); no new content in
Resources/. EveryLoadAssetAsynchandle is released. - Async:
Awaitable(Unity 6) or UniTask where the repo uses it; cancel withdestroyCancellationTokenso a destroyed object's continuation does not run.async voidonly for event handlers, with try/catch.
Serialization safety
- Renaming a serialized field loses its data in every scene and prefab unless you add
[FormerlySerializedAs("oldName")]. - Polymorphic serialized fields need
[SerializeReference]; plain[SerializeField]slices to the base type. - Keep Asset Serialization on Force Text so scenes and prefabs diff and merge (UnityYAMLMer
Установить unity-project-architecture в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл unity-project-architecture?
Use when writing or restructuring Unity C# code - assembly definitions and dependency direction, small components with cached references, ScriptableObjects for data and events, DI instead of singletons, Input System, Addressables, serialization safety and Unity 6 API changes.
Как установить скилл unity-project-architecture?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл unity-project-architecture запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic