CustomEditor命令
当我们需要为一个组件添加自己自定义的编辑器内容时,需要用到这个特性:CustomEditor,语法如下:
1、public CustomEditor(Type inspectedType);
2、public CustomEditor(Type inspectedType, bool editorForChildClasses); bool editorForChildClasses可以让我们定义此编辑器内容在子类中是否有效,默认为false;
代码示例:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TileObject))]
public class TileEditor : Editor
{
protected bool m_editMode = false;
protected TileObject m_tileObject;
void OnEnable()
{
m_tileObject = (TileObject)target;
}
public void OnSceneGUI()
{
if (m_editMode)
{
HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
m_tileObject.m_debug = true;
if (m_tileObject.m_dataID != 3)
{
Event e