Editor图片预览

using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(MyDate))]


public class MyDateEditor : Editor {


    MyDate mtarget;


     void OnEnable()
    {
        mtarget = target as MyDate;
    }




    //自定义预览窗口
    public override void OnPreviewGUI(Rect r, GUIStyle background)
    {
        //显示出一张该类型的图片集
        GUI.Box(r, mtarget.texture);
        
    }




   //该类型是否有预览窗口
    public override bool HasPreviewGUI()
    {
        //return base.HasPreviewGUI();
        return true;
    }


    public override GUIContent GetPreviewTitle()
    {
        return  new GUIContent("图片标题");
    }


 

}





using UnityEngine;
using System.Collections;


public class MyDate : MonoBehaviour {
    public Texture texture;
   



}

把MyDate.cs拖到物体上即可

你可能感兴趣的:(Editor图片预览)