Agent Skills
› Besty0728/Unity-Skills
› unity-async
unity-async
GitHub为Unity异步编程与生命周期管理提供策略建议。指导用户在Update、协程、UniTask及定时器间进行合理选择,强调事件驱动优先、明确生命周期所有权及资源清理,避免滥用Update和过度依赖UniTask,确保代码简洁且易于维护。
触发场景
询问Unity异步代码写法
纠结使用协程还是UniTask
需要调度定时器或处理取消清理
讨论Unity生命周期管理
安装
npx skills add Besty0728/Unity-Skills --skill unity-async -g -y
SKILL.md
Frontmatter
{
"name": "unity-async",
"description": "Advises on Unity async and lifecycle strategy — choosing among Update, coroutines, UniTask, and timers, plus cleanup and cancellation. Use when deciding how to write async code, choosing between coroutine and UniTask, scheduling timers, or handling cancellation and cleanup, even if the user just asks \"异步怎么写\" or \"用协程还是UniTask\". 为 Unity 异步与生命周期策略提供建议(在 Update、协程、UniTask、定时器间取舍,以及清理与取消);当用户要决定异步代码怎么写、在协程与 UniTask 间选择、调度定时器或处理取消与清理时使用。"
}
Unity Async Strategy
Use this skill when the user is deciding how runtime work should be scheduled or cleaned up.
Guardrails
Mode: Documentation only — no REST skills to gate; load freely under any operating mode (Approval / Auto / Bypass).
- Do not recommend
UniTaskjust because it looks more advanced than coroutine. - Prefer the simplest scheduling model that fits the use case.
Decision Ladder
- First ask whether the task needs per-frame work at all.
- If not, prefer events, callbacks, or explicit method calls.
- If a short Unity-bound sequence is needed, prefer coroutine.
- Recommend
UniTaskonly when:- the project already uses it, or
- the user explicitly wants it and accepts the dependency.
- Use
Updateonly for true continuous simulation, polling, or input loops that cannot be event-driven.
Specific Guidance
- Avoid many unrelated
Updatemethods if a more event-driven flow works. - Cache references used in hot paths.
- Always define lifecycle ownership:
- who starts the work
- who cancels or stops it
- when it is cleaned up
- In
MonoBehaviour, preferOnEnable/OnDisable/OnDestroyfor subscribe-unsubscribe symmetry. - Use
IDisposablemainly for pure C# lifetimes, temporary subscriptions, or scope-based cleanup helpers, not as a cargo-cult replacement for Unity lifecycle methods.
Output Format
- Recommended scheduling model
- Why it fits
- Lifecycle / cancellation owner
- Hot-path risks
- Why the heavier alternative is unnecessary, if applicable
版本历史
- ec9f870 当前 2026-07-05 14:39


