Files
nexus/wiki/sources/unity-editor-tool-developer.md
2026-05-03 05:42:12 +08:00

5.5 KiB
Raw Blame History

title, type, tags, date
title type tags date
Unity Editor Tool Developer source
2026-04-26

Source File

Summary用中文描述

  • 核心主题Unity Editor 扩展开发专家 Agent——通过 EditorWindow、PropertyDrawer、AssetPostprocessor、Build Validation 等自动化工具,减少团队手动操作时间、提前拦截错误
  • 问题域:游戏项目 Editor 自动化工作流、美术/策划/程序团队的日常效率提升、构建前质量门控
  • 方法/机制Editor-only 代码规范(Editor 文件夹 / #if UNITY_EDITOR / asmdef 隔离)→ 工具原型验证 → 量产化(含 Undo/ProgressBar/持久化)→ Build Validation 集成
  • 结论/价值:提供完整的 Unity Editor 工具开发规范,包括 4 类核心 APIEditorWindow/PropertyDrawer/AssetPostprocessor/IPreprocessBuildWithReport的代码模板与质量标准

Key Claims用中文描述

  • 所有 Editor 脚本必须位于 Editor 文件夹或使用 #if UNITY_EDITOR 守卫——Editor API 调用进入运行时程序集会导致构建失败
  • AssetPostprocessor 必须幂等:同一资源导入两次必须产生相同结果
  • PropertyDrawer.OnGUI 必须调用 EditorGUI.BeginProperty / EndProperty,否则 Prefab Override UI 将无法正常工作
  • EditorWindow 工具必须通过 [SerializeField]EditorPrefs 持久化状态,否则 Domain Reload 后状态丢失
  • 任何修改 inspector 显示对象的操作必须先调用 Undo.RecordObject,否则操作无法撤销,属于用户敌对行为
  • 耗时超过 0.5 秒的操作必须显示 EditorUtility.DisplayProgressBar,否则 UI 会冻结

Key Quotes

"Every EditorWindow tool must persist state across domain reloads using [SerializeField] on the window class or EditorPrefs" — Domain Reload 状态持久化规范 "Tools must show progress via EditorUtility.DisplayProgressBar for any operation taking > 0.5 seconds" — 长操作 UX 标准 "AssetPostprocessor must be idempotent: importing the same asset twice must produce the same result" — 导入处理器幂等性要求 "PropertyDrawer's OnGUI must call EditorGUI.BeginProperty / EndProperty to support prefab override UI correctly" — Prefab Override 支持规范 "Log actionable messages (Debug.LogWarning) when postprocessor overrides a setting — silent overrides confuse artists" — 静默覆盖之害

Key Concepts

  • EditorWindowUnity Editor 扩展窗口基类,通过 [MenuItem] 注册菜单入口,可创建工具窗口、审计面板、检查器等 UI
  • PropertyDrawer:自定义 Inspector 属性绘制器,通过 CustomPropertyDrawer 特性关联 Serializable 类型,提供更友好的编辑器编辑体验
  • AssetPostprocessor:资源导入前置/后置处理器,在每次资源导入时自动触发,用于强制命名规范、导入设置和预算验证
  • CustomEditor:自定义 Inspector 面板,通过 [CustomEditor(typeof(MyComponent))] 替代默认组件检查器
  • AssemblyDefinition.asmdefAssembly Definition 文件,通过引 references 强制编辑器程序集与运行时程序集的编译时隔离
  • Undo.RecordObjectUnityEditor.Undo API在修改对象前调用使操作可撤销——不可撤销的编辑器操作属于用户敌对行为
  • BuildValidationIPreprocessBuildWithReport构建前验证接口在打包前运行质量门控检查失败时抛出 BuildFailedException
  • ScriptableBuildPipelineUnity 可脚本化构建管线,替代传统构建流程,支持自定义构建任务(资产剥离/着色器变体/CDN 缓存失效)
  • UI ToolkitUIElementsUnity 新一代编辑器 UI 系统,基于 USS + VisualElement提供响应式、可样式化的编辑器 UI替代 IMGUI

Key Entities

  • UnityEditorToolDeveloperUnity Editor 工具开发专家 Agent 自引用——"自动化痴迷、DX 优先、流水线第一、默默不可或缺"

Connections

Contradictions

  • UnrealTechnicalArtist 关于 Editor 扩展方案:
    • 冲突点Unity 使用 PropertyDrawer / CustomEditor / EditorWindow 方案Unreal 使用 Details Panel Customization / EditorUtility / SWidget 方案
    • 当前观点Unity Editor Tool Developer 认为 PropertyDrawer + AssetPostprocessor 组合可覆盖 90% 的编辑器自动化场景
    • 对方观点Unreal Technical Artist 更偏好编辑器蓝图/编辑器模块化方案而非手写 C++
    • 说明:两者均为各自平台的最佳实践,冲突源于引擎架构差异而非绝对优劣