cocos_scaffold_audio_controller
Generate a TypeScript singleton audio manager for Cocos Creator games to handle background music and sound effects with cross-fading, volume persistence, and automatic component setup.
Instructions
Generate AudioController.ts — singleton BGM + SFX manager.
Runtime API::
AudioController.I.playBGM(clipName) // cross-fades if switching tracks
AudioController.I.stopBGM()
AudioController.I.playSFX(clipName) // overlaps via playOneShot
AudioController.I.setBGMVolume(v) // 0..1, persists
AudioController.I.setSFXVolume(v)Inspector: @property bgmClips: AudioClip[] — keyed by clip .name for playBGM lookup. @property sfxClips: AudioClip[] — same convention. @property bgmFadeDuration — tween cross-fade seconds; 0 = hard cut.
Auto-attaches two cc.AudioSource components to its own node
(looping BGM source + non-loop SFX source) via addComponent in
onLoad — no manual Inspector wiring needed. Volumes persist to
localStorage under 'cocos-mcp-audio' with swallowed write
failures (private browsing, WeChat mini-game).
Idempotent: playBGM('already-playing') is a no-op.
Unknown clip names: silently skipped (avoid crashing on stale
references to clips the designer removed).
Returns {path, rel_path, uuid_standard, uuid_compressed}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_path | Yes | ||
| rel_path | No | AudioController.ts |