unity-classic
Non-DOTS "Unity classic" skill covering MonoBehaviour, UI Toolkit, UGUI, VContainer, Addressables, pooling, DOTween, async/UniTask, and per-frame performance. Loaded exclusively by the unity-dev (non-DOTS) lane. Does NOT cover ECS/DOTS — use unity-dots-best-practices for entities and systems.
- License 许可
- MIT
- 最近更新
- 2026-07-25
- Stars
- ★ 8
- Forks
- 0
01 前言 Front Matter
- name
- unity-classic
- metadata
- { "tier": 1, "source": "https://docs.unity3d.com/Manual/", "version": "Unity 6 (6000.0)" }
- use-when
- Load for unity-dev lane when triage classifies domain as Unity (not DOTS or Hybrid). Load for MonoBehaviour lifecycle, UI system, Addressables, pooling, or DOTween tasks.
- platforms
- [ "claude-code", "codex", "copilot", "cursor", "windsurf" ]
- description
- Non-DOTS "Unity classic" skill covering MonoBehaviour, UI Toolkit, UGUI, VContainer, Addressables, pooling, DOTween, async/UniTask, and per-frame performance. Loaded exclusively by the unity-dev (non-DOTS) lane. Does NOT cover ECS/DOTS — use unity-dots-best-practices for entities and systems.
- do-not-use-when
- Do not load for unity-dots-dev lane. Do not load when task involves ISystem, IJobEntity, ECB, NativeContainers, or any ECS API. Do not load for tester, verifier, or architect roles.
- task-categories
- [ "gameplay", "ui", "animation", "audio", "implementation", "classic-unity" ]
03 SKILL.md 正文
Unity Classic (Non-DOTS) Skill
The non-DOTS lane: GameObject + MonoBehaviour runtime, UI, gameplay glue,
DI, asset loading, tweening, pooling, async. If the task is ISystem/Jobs/Burst/
Entities, it belongs to unity-dots-dev, not here.
Root-cause first: for a bug, trace the lifecycle / data flow / event wiring and fix the real cause. No null-guard or timer band-aid without proving the cause. Match existing project patterns; do not add a parallel service/controller/model.
MonoBehaviour lifecycle (the #1 bug source)
Awake→ references/self-init only.OnEnable→ subscribe events / register.Start→ cross-object init (others' Awake done).OnDisable→ unsubscribe everything subscribed in OnEnable.OnDestroy→ final teardown.- Every
+=needs a matching-=. Static / long-lived publisher + instance subscriber that never unsubscribes = leak + ghost callbacks after destroy. - Pooled objects fire
OnEnable/OnDisableper reuse, NOTAwake/Start. Put re-init inOnEnable, cleanup inOnDisable— not Start/OnDestroy. - Coroutines stop when the MB disables; restart in
OnEnableif needed. NeverStartCoroutineon a disabled/inactive object.
Pooling
- Reset full state on
Get/spawn (transform, callbacks, tween handles, timers). - On
Return/despawn: kill tweens, cancel async, unsubscribe, stop coroutines. - A pooled object's
OnDisableruns on return — do destroy-like cleanup there, not inOnDestroy(which may never run for pooled objects).
DOTween
- Cache the
Tween/Sequence;tween.Kill()on disable/return/destroy before starting a new one — orphan tweens mutate recycled objects. SetLink(gameObject)orSetAutoKill(true)to bind lifetime; do not leak infinite-loop tweens on pooled UI.DOTween.Kill(target)inOnDisablefor pooled views.
VContainer / DI
- Inject via constructor or
[Inject]method; injection completes afterAwake, aroundStart/entry-point. Do not use injected refs inAwake. IStartable/ITickable/IAsyncStartableviaRegisterEntryPoint; register in the rightLifetimeScope. Mismatched scope = null inject or duplicate.- Do not
newa service that the container owns — resolve it.
Addressables
Addressables.LoadAssetAsync↔Release(handle).InstantiateAsync↔ReleaseInstance(go). Mixing them leaks. Release exactly once per load.- Hold the
AsyncOperationHandleto release later; releasing the asset while an instance is live can break it. Check.Statusbefore using.Result.
Async / UniTask
- Pass a
CancellationToken; usethis.destroyCancellationToken(or aCancellationTokenSourcetied to OnDisable/OnDestroy) so awaits stop on teardown. - Never
async voidexcept top-level event handlers; catch there. - Cancel in-flight loads/animations on disable to avoid acting on a dead object.
UI
- Bind once; guard against double-subscribe on re-show. Unbind on hide.
- No
GetComponent/Find/LINQ/string.Format/allocations inUpdateor per-item layout loops. Cache references. Batch canvas updates.
Performance (per-frame)
- Hot path: no allocations, no
GetComponentper frame, noCamera.mainper frame, no boxing. Pool transient objects. Profile before/after non-trivial work.
Output (handoff)
- Unity classic analysis (lifecycle/data-flow/root cause)
- Implementation plan (existing patterns reused — no duplication)
- Changed files + one-line purpose
- Validation steps (lifecycle, leak, alloc, release/kill checks)
04 同仓库更多 Skills
dots-update-groups
How to choose the right ECS system group and ordering so per-frame and per-fixed-step work is deterministic and never races its own readers. Covers InitializationSystemGroup / SimulationSystemGroup / PresentationSystemGroup / FixedStepSimulationSystemGroup / VariableRateSimulationSystemGroup, UpdateBefore / UpdateAfter peer ordering, OrderFirst / OrderLast group-boundary placement, RateManager, and the cross-group ordering trap. Use when adding an ISystem, fixing "value visible one frame late" bugs, or coupling simulation to a fixed timestep.
dots-transform-patterns
The Entities 1.x transform model — LocalTransform (writable input) vs LocalToWorld (system-owned matrix), Parent/Child hierarchy, reparenting cost, uniform vs non-uniform scale (PostTransformMatrix), and when to opt out with custom transform systems. Use when designing parent/child hierarchies, runtime reparenting (mount/dismount/socket), or choosing transform components at the Baker boundary.
dots-singleton-patterns
Model cross-system shared configuration and game state as a single-entity component with a strict single-writer contract. Covers RequireForUpdate gating, SystemAPI.GetSingleton / GetSingletonRW / HasSingleton / TryGetSingleton, bake-time vs runtime-created vs ECB-system singletons, the "exactly one entity" runtime invariant, and the single-writer rule. Use when designing frame-stable global config, shared mutable state, or any component intended to exist on exactly one entity.
dots-hybrid-bridge
The one-way bridge between DOTS-owned runtime state and Unity-owned presentation. Covers UnityObjectRef for managed asset refs in components, the DOTS-writes / Unity-reads ownership rule, when to use managed IComponentData vs UnityObjectRef vs CompanionComponent, baker-bridge vs runtime-bridge, and SubScene boundary rules. Use when an entity must reference Unity assets (Mesh, Material, AudioClip, ScriptableObject), a MonoBehaviour view must read entity state, or input/UI must trigger ECS work.
dots-event-driven-ecs
Model one-frame events and external requests in ECS without dual ownership, polling, or persistent state leaks. Covers request-tag pattern with ECB, enableable command components (no structural change), event buffers (IBufferElementData), explicit consumer ownership, one-frame latency rules, and the banned C# event / UnityEvent / static bus anti-patterns. Use when input/UI/network must trigger ECS work, when a one-frame signal fans out to N consumers (damage, hit, collision), or when state changes must be processed exactly once.
valid_skill
A complete, well-formed test fixture skill for SkillHub validation testing. Covers basic task routing and code review for Unity projects.