unity-script
C# script CRUD and analysis — create, read, replace, append, search, rename, move, delete Unity scripts and surface compile feedback / Domain Reload state. Triggers: script, C# code, csharp, MonoBehaviour, ScriptableObject, Editor, EditorWindow, namespace, class, create script, read script, write code, edit script, replace text, find in scripts, regex search, rename script, move script, append code, delete script, batch create, compile feedback, compile errors, Domain Reload, code generation, code template, script_create, script_create_batch, script_replace, script_append, script_read, script_rename, script_move, script_delete, script_get_compile_feedback, 脚本, C# 代码, 创建脚本, 批量创建, 读取脚本, 修改脚本, 替换脚本, 查找替换, 搜索脚本, 重命名脚本, 移动脚本, 追加代码, 删除脚本, 编写代码, 生成脚本, 代码模板, 编译反馈, 编译错误, 域重载, 重编译.
- License 许可
- MIT
- 最近更新
- 2026-07-25
- Stars
- ★ 8
- Forks
- 0
01 前言 Front Matter
- name
- unity-script
- metadata
- { "tier": 2, "source": "https://github.com/Besty0728/Unity-Skills", "version": "1.9.2" }
- use-when
- Load when the task requires: C# script CRUD and analysis — create, read, replace, append, search, rename, move, delete Unity scripts and surface compile feedback / Domain Reload state. Unity Editor must be running with the unity-skills REST server reachable at http://localhost:8090.
- platforms
- [ "unity-editor", "claude-code" ]
- description
- C# script CRUD and analysis — create, read, replace, append, search, rename, move, delete Unity scripts and surface compile feedback / Domain Reload state. Triggers: script, C# code, csharp, MonoBehaviour, ScriptableObject, Editor, EditorWindow, namespace, class, create script, read script, write code, edit script, replace text, find in scripts, regex search, rename script, move script, append code, delete script, batch create, compile feedback, compile errors, Domain Reload, code generation, code template, script_create, script_create_batch, script_replace, script_append, script_read, script_rename, script_move, script_delete, script_get_compile_feedback, 脚本, C# 代码, 创建脚本, 批量创建, 读取脚本, 修改脚本, 替换脚本, 查找替换, 搜索脚本, 重命名脚本, 移动脚本, 追加代码, 删除脚本, 编写代码, 生成脚本, 代码模板, 编译反馈, 编译错误, 域重载, 重编译.
- do-not-use-when
- Do not load when Unity Editor is not running locally. Do not load when unity-skills REST server is unreachable at http://localhost:8090.
- task-categories
- [ "scripting", "editor-automation" ]
03 SKILL.md 正文
Unity Script Skills
BATCH-FIRST: Use
script_create_batchwhen creating 2+ scripts. DESIGN-FIRST: Before creating gameplay scripts, actively consider coupling, performance, and maintainability. In an existing project, load../project-scout/SKILL.mdfirst. If the user is asking for architecture or refactoring advice, load../architecture/SKILL.mdand then../patterns/SKILL.md,../async/SKILL.md,../inspector/SKILL.md,../performance/SKILL.md,../script-roles/SKILL.md,../scene-contracts/SKILL.md,../testability/SKILL.md, or../scriptdesign/SKILL.mdas needed.
Operating Mode
- Approval(默认): 只读类 skill(
script_read/script_list/script_find_in_file/script_get_info/script_get_compile_feedback,标SkillMode.SemiAuto)直接执行;写型 skill(script_create/script_create_batch/script_replace/script_append/script_rename/script_move/script_delete,默认SkillMode.FullAuto)需用户 grant,grant 后服务端一步执行返结果。 - Auto / Bypass: 直接执行。
- 本模块含 Delete / Reload 类高危 skill:
script_create/script_create_batch/script_replace/script_append/script_delete会触发 Domain Reload(且多标RiskLevel=high),script_delete同时是 Delete 操作 —— 这些 skill 在 Approval / Auto 下被IsForbiddenInSemi自动拦截,仅 Bypass 或 Allowlist 命中可执行。
DO NOT (common hallucinations):
script_edit/script_updatedo not exist → usescript_replacefor find-and-replacescript_writedoes not exist → usescript_create(new file) orscript_replace(modify existing)scriptNameparameter must NOT include.csextension- Templates only accept: MonoBehaviour, ScriptableObject, Editor, EditorWindow
Routing:
- To modify existing script content →
script_replace(find/replace) orscript_append(add lines) - To read script →
script_read - To check compile errors →
script_get_compile_feedback - To analyze script API → use
perceptionmodule'sscript_analyze
Skills Overview
| Single Object | Batch Version | Use Batch When |
|---|---|---|
script_create |
script_create_batch |
Creating 2+ scripts |
No batch needed:
script_read- Read script contentscript_delete- Delete scriptscript_find_in_file- Search in scriptsscript_append- Append content to scriptscript_get_compile_feedback- Check compile errors for one script after Unity finishes compilingcreate_script()inscripts/unity_skills.pynow waits for Unity to come back once and refreshes compile feedback automatically after script creation.
Skills
script_create
Create a C# script from template.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
scriptName |
string | Yes | - | Script class name |
folder |
string | No | "Assets/Scripts" | Save folder |
template |
string | No | "MonoBehaviour" | Template type |
namespaceName |
string | No | null | Optional namespace |
Templates: MonoBehaviour, ScriptableObject, Editor, EditorWindow
Returns: {success, status, path, jobId, className, namespaceName, designReminder, serverAvailability?}
Poll the returned jobId (or call script_get_compile_feedback) to obtain compile diagnostics — they are not embedded in the synchronous response. serverAvailability carries the transient-unavailable hint when Unity is about to reload the script domain.
script_create_batch
Create multiple scripts in one call.
Returns: {success, totalItems, successCount, failCount, results: [{success, path, className}], compilation?}
Before batch creation, decide whether each script should be:
- a thin
MonoBehaviourbridge - a
ScriptableObjectconfiguration asset - or a plain C# domain/service class generated from a custom template
unity_skills.call_skill("script_create_batch", items=[
{"scriptName": "PlayerController", "folder": "Assets/Scripts/Player", "template": "MonoBehaviour"},
{"scriptName": "EnemyAI", "folder": "Assets/Scripts/Enemy", "template": "MonoBehaviour"},
{"scriptName": "GameSettings", "folder": "Assets/Scripts/Data", "template": "ScriptableObject"}
])
script_read
Read script content.
| Parameter | Type | Required | Description |
|---|---|---|---|
scriptPath |
string | Yes | Script asset path |
Returns: {path, lines, content}
script_delete
Delete a script.
| Parameter | Type | Required | Description |
|---|---|---|---|
scriptPath |
string | Yes | Script to delete |
Returns: {success, status, deleted, jobId, serverAvailability?}
script_find_in_file
Search for patterns in scripts.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
pattern |
string | Yes | - | Search pattern |
folder |
string | No | "Assets" | Search folder |
isRegex |
bool | No | false | Use regex |
limit |
int | No | 50 | Max results |
Returns: {pattern, matchCount, matches: [{file, line, content}]}
script_append
Append content to a script.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
scriptPath |
string | Yes | - | Script path |
content |
string | Yes | - | Content to append |
atLine |
int | No | end | Line number to insert at |
script_get_compile_feedback
Get compile diagnostics related to one script.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
scriptPath |
string | Yes | - | Script path |
limit |
int | No | 20 | Max diagnostics |
Example: Efficient Script Setup
import unity_skills
# BAD: 3 API calls + 3 Domain Reloads
unity_skills.call_skill("script_create", scriptName="PlayerController", folder="Assets/Scripts/Player")
# Wait for Domain Reload...
unity_skills.call_skill("script_create", scriptName="EnemyAI", folder="Assets/Scripts/Enemy")
# Wait for Domain Reload...
unity_skills.call_skill("script_create", scriptName="GameManager", folder="Assets/Scripts/Core")
# Wait for Domain Reload...
# GOOD: 1 API call + 1 Domain Reload
unity_skills.call_skill("script_create_batch", items=[
{"scriptName": "PlayerController", "folder": "Assets/Scripts/Player"},
{"scriptName": "EnemyAI", "folder": "Assets/Scripts/Enemy"},
{"scriptName": "GameManager", "folder": "Assets/Scripts/Core"}
])
# Wait for Domain Reload once...
Important: Domain Reload And Compile Feedback
After creating or editing scripts, Unity triggers a Domain Reload (recompilation). Use the returned compilation field first. If isCompiling=true, wait for Unity to finish and then call script_get_compile_feedback.
import time
result = unity_skills.call_skill("script_create", scriptName="MyScript")
time.sleep(5) # Wait for Unity to recompile if result["compilation"]["isCompiling"] is true
feedback = unity_skills.call_skill("script_get_compile_feedback", scriptPath=result["path"])
unity_skills.call_skill("component_add", name="Player", componentType="MyScript")
Best Practices
- Use meaningful script names matching class name
- Organize scripts in logical folders
- Before creating gameplay code, decide the class role first: MonoBehaviour, ScriptableObject, or plain C# helper/service
- Actively reduce coupling: prefer explicit dependencies, small responsibilities, and event-driven notifications over hidden globals
- Actively consider performance: avoid unnecessary
Update, repeatedFind, reflection in hot paths, and avoidable allocations - Actively consider maintainability: clear naming, explicit ownership, Inspector-friendly fields, and simple module boundaries
- Avoid giant boilerplate/template dumps. Start from the smallest structure that solves the current need
- Do not default to UniTask or a global event bus unless the project context justifies them
- Avoid cryptic abbreviations in class, field, and method names unless they are already a project convention
- Use templates for correct base class
- Wait for compilation after creating scripts
- After script edits, call
script_get_compile_feedbackand fix reported errors - Use regex search for complex patterns
- Use batch creation to minimize Domain Reloads
Additional Skills
script_replace
Find and replace content in a script file.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
scriptPath |
string | Yes | - | Script asset path |
find |
string | Yes | - | Text or pattern to find |
replace |
string | Yes | - | Replacement text |
isRegex |
bool | No | false | Use regex matching |
checkCompile |
bool | No | true | Check compilation after replace |
diagnosticLimit |
int | No | 20 | Max compile diagnostics |
Returns: { success, status, path, jobId, replacements, serverAvailability? }
script_list
List C# script files in the project.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
folder |
string | No | "Assets" | Folder to search in |
filter |
string | No | null | Filter string for path matching |
limit |
int | No | 100 | Max results |
Returns: { count, scripts: [{ path, name }] }
script_get_info
Get script info (class name, base class, methods).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
scriptPath |
string | Yes | - | Script asset path |
Returns: { path, className, baseClass, namespaceName, isMonoBehaviour, publicMethods, publicFields }
script_rename
Rename a script file.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
scriptPath |
string | Yes | - | Script asset path |
newName |
string | Yes | - | New script name (without extension) |
checkCompile |
bool | No | true | Check compilation after rename |
diagnosticLimit |
int | No | 20 | Max compile diagnostics |
Returns: { success, status, path, jobId, oldPath, newName, serverAvailability? }
script_move
Move a script to a new folder.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
scriptPath |
string | Yes | - | Script asset path |
newFolder |
string | Yes | - | Destination folder. Must already exist. |
checkCompile |
bool | No | true | Check compilation after move |
diagnosticLimit |
int | No | 20 | Max compile diagnostics |
Returns: { success, status, path, jobId, oldPath, newPath, serverAvailability? }
Exact Signatures
Exact names, parameters, defaults, and returns are defined by GET /skills/schema or unity_skills.get_skill_schema(), not by this file.
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.