using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestMenuItem : MonoBehaviour
{
[MenuItem("Window/MyPreview")]
static void MyPreview()
{
TestPreview testPreview= EditorWindow.GetWindow<TestPreview>("我的预览");
testPreview.Show();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class TestPreview : EditorWindow
{
private Object obj;
private Object lastObj;
private Editor previewObj;
private void OnGUI()
{
obj = EditorGUILayout.ObjectField(obj, typeof(Object), false);
if(obj != null && obj != lastObj)
{
previewObj = Editor.CreateEditor(obj);
lastObj = obj;
}
if(previewObj != null && previewObj.HasPreviewGUI())
{
//绘制预览信息
previewObj.OnPreviewGUI(GUILayoutUtility.GetRect(400, 400), EditorStyles.label);
}
}
}