Inspector视图拓展
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Camera))]//指定针对哪个组件
public class TestInspector : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();//原生的Inspector面板
if(GUILayout.Button("test1"))
{
Debug.Log("test1");
Camera camera = this.target as Camera;
if(camera != null)
{
camera.depth ++;
}
}
}
}
Inspector Context菜单拓展
拓展目标:右键组件的…、
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestInspectorContext : MonoBehaviour
{
[MenuItem("CONTEXT/Transform/SetPosition")]
static void Setposition(MenuCommand command)
{
Transform transform = command.context as Transform;
if(transform != null)
{
transform.position += Vector3.one;
}
}
}