AGENT SKILL

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/OnDisable per reuse, NOT Awake/Start. Put re-init in OnEnable, cleanup in OnDisable — not Start/OnDestroy.
  • Coroutines stop when the MB disables; restart in OnEnable if needed. Never StartCoroutine on 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 OnDisable runs on return — do destroy-like cleanup there, not in OnDestroy (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) or SetAutoKill(true) to bind lifetime; do not leak infinite-loop tweens on pooled UI.
  • DOTween.Kill(target) in OnDisable for pooled views.

VContainer / DI

  • Inject via constructor or [Inject] method; injection completes after Awake, around Start/entry-point. Do not use injected refs in Awake.
  • IStartable/ITickable/IAsyncStartable via RegisterEntryPoint; register in the right LifetimeScope. Mismatched scope = null inject or duplicate.
  • Do not new a 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 AsyncOperationHandle to release later; releasing the asset while an instance is live can break it. Check .Status before using .Result.

Async / UniTask

  • Pass a CancellationToken; use this.destroyCancellationToken (or a CancellationTokenSource tied to OnDisable/OnDestroy) so awaits stop on teardown.
  • Never async void except 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 in Update or per-item layout loops. Cache references. Batch canvas updates.

Performance (per-frame)

  • Hot path: no allocations, no GetComponent per frame, no Camera.main per frame, no boxing. Pool transient objects. Profile before/after non-trivial work.

Output (handoff)

  1. Unity classic analysis (lifecycle/data-flow/root cause)
  2. Implementation plan (existing patterns reused — no duplication)
  3. Changed files + one-line purpose
  4. Validation steps (lifecycle, leak, alloc, release/kill checks)

04 同仓库更多 Skills

dyCuong03
dyCuong03/unity-agent-team

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.

★ 8
dyCuong03
dyCuong03/unity-agent-team

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.

★ 8
dyCuong03
dyCuong03/unity-agent-team

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.

律师与法务
★ 8
dyCuong03
dyCuong03/unity-agent-team

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.

★ 8
dyCuong03
dyCuong03/unity-agent-team

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.

★ 8
dyCuong03
dyCuong03/unity-agent-team

valid_skill

A complete, well-formed test fixture skill for SkillHub validation testing. Covers basic task routing and code review for Unity projects.

代码审查测试与质量
★ 8