Inspector视图拓展

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. [CustomEditor(typeof(Camera))]//指定针对哪个组件
  6. public class TestInspector : Editor
  7. {
  8. public override void OnInspectorGUI()
  9. {
  10. base.OnInspectorGUI();//原生的Inspector面板
  11. if(GUILayout.Button("test1"))
  12. {
  13. Debug.Log("test1");
  14. Camera camera = this.target as Camera;
  15. if(camera != null)
  16. {
  17. camera.depth ++;
  18. }
  19. }
  20. }
  21. }

Inspector Context菜单拓展

拓展目标:右键组件的…、
image.png

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. public class TestInspectorContext : MonoBehaviour
  6. {
  7. [MenuItem("CONTEXT/Transform/SetPosition")]
  8. static void Setposition(MenuCommand command)
  9. {
  10. Transform transform = command.context as Transform;
  11. if(transform != null)
  12. {
  13. transform.position += Vector3.one;
  14. }
  15. }
  16. }