1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5. public class TestMenuItem : MonoBehaviour
    6. {
    7. [MenuItem("Window/MyPreview")]
    8. static void MyPreview()
    9. {
    10. TestPreview testPreview= EditorWindow.GetWindow<TestPreview>("我的预览");
    11. testPreview.Show();
    12. }
    13. }
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5. public class TestPreview : EditorWindow
    6. {
    7. private Object obj;
    8. private Object lastObj;
    9. private Editor previewObj;
    10. private void OnGUI()
    11. {
    12. obj = EditorGUILayout.ObjectField(obj, typeof(Object), false);
    13. if(obj != null && obj != lastObj)
    14. {
    15. previewObj = Editor.CreateEditor(obj);
    16. lastObj = obj;
    17. }
    18. if(previewObj != null && previewObj.HasPreviewGUI())
    19. {
    20. //绘制预览信息
    21. previewObj.OnPreviewGUI(GUILayoutUtility.GetRect(400, 400), EditorStyles.label);
    22. }
    23. }
    24. }

    image.pngimage.png