Unity Editor编辑器拓展
Editor GUI
InspectorGUI
Screen Size
- Screen.width // 当前InspectorGUI大小,并不是SceneView大小
- Screen.height
属性变化
- DrawDefaultInspector() // Editor更方便的检测方法
- BeginChangeCheck() // 检测属性UI值变化
- EndChangeCheck() // 若有改变则为true
- OnValidate() // Mono属性变化时调用,用来限定属性
1
2
3
4
5
6
7public override void OnInspectorGUI()
{
if (DrawDefaultInspector())
{
terrainMesh.CreateTerrain();
}
}1
2
3
4
5
6
7
8
9
10public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();
base.OnInspectorGUI();
if (EditorGUI.EndChangeCheck())
{
terrainMesh.CreateTerrain();
}
}
Attribute
- SerializeField
- HideInInspector
- MenuItem // 自定义编辑器菜单
- CustomEditor // 自定义对象属性GUI
- ExecuteInEditMode
- RequireComponent
- ImageEffectAllowedInSceneView
Shortcut
- EditorTool
- ToolManager.SetActiveTool(EditorTools.EditorTool tool)
1
2
3
4
5
6using UnityEditor.ShortcutManagement;
[Shortcut("Activate Paint Tool", typeof(SceneView), KeyCode.U)]
static void Shortcut()
{
ToolManager.SetActiveTool<EditorTools>();
}
Shader GUI || Material Editor
- Unity 为自己脚本增加材质编辑面板 MaterialEditor
- Unity3D研究院之材质Shader通用面板
1
2
3MaterialEditor matEditor = Editor.CreateEditor(material) as MaterialEditor;
if (matEditor != null)
matEditor.PropertiesGUI();
CustomEditor || CustomPropertyDrawer
- CustomPropertyDrawer
UIElements
Undo
- make a scene dirty when modifying
- Undo.RecordObject(obj, “history info”)
Reference
- 雨松Mono - Unity3D拓展编辑器
- Unity3D研究院编辑器之获取粒子准确数量
- Unity3D研究院之获取FrameDebugger每帧颜色数据
- 获取系统所有EditorStyles
- Unity ScrollView拖不动
- 坑爹的GUILayoutUtility.GetRect()和GUILayout.BeginArea()
Tool | 工具类
EditorUtility
- RevealInFinder // 打开文件夹
- OpenFilePanel
- OpenFolderPanel
- OpenFilePanelWithFilters
EditorGUIUtility
- PingObject //浏览、选中资产
- Selection.activeObject = data
AssetDatabase
- LoadAssetAtPath
- AssetPathToGUID
- Contains
- CopyAsset
- CreateAsset
- ExtractAsset
- ImportAsset
- FindAssets
- GetAssetPath
- CreateFolder
- ExportPackage
PrefabUtility
- CreatePrefab
- CreateEmptyPrefab
Project Setting
- UnityEngine.QualitySettings
- renderPipeline
- UnityEngine.Rendering.GraphicsSettings
- renderPipelineAsset
- UnityEditor.EditorSettings
- UnityEditor.PlayerSettings
- UnityEditor.EditorBuildSettings
- UnityEditor.BuildPipeline //build game
Unity技巧
- 方法属性加Button
- Unity小窍门100条!!!(上)
- FormerlySerializedAs()
- 重命名显示
- RuntimeInitializeOnLoadMethod
- [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
- 无需创建空物体就能执行代码
- 在运行游戏(Play)就会立即执行该函数,而不需要继承MonoBehavior并挂接在物体身上。
- [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
Unity Editor编辑器拓展
https://automask.github.io/wild/2021/10/26/log/P_Unity_Editor/