Hi,
Is it possible to override the texture preview in the inspector? I’ve tried the normal method of a custom editor to no avail.
Thanks,
ng93
Hi,
Is it possible to override the texture preview in the inspector? I’ve tried the normal method of a custom editor to no avail.
Thanks,
ng93
We use a class derived from ObjectPreview, something similar to this (replace TextAsset with Texture2D):
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
[CustomPreview(typeof(TextAsset))]
public class MyPreviewClass : ObjectPreview
{
public override bool HasPreviewGUI ()
{
return AssetDatabase.GetAssetPath(target).EndsWith(".bytes");
}
public override void OnPreviewGUI (Rect r, GUIStyle background)
{
// TODO: implementation
}
}
Thanks, turns out I wasn’t overriding HasPreviewGUI(). For anyone that stumbles across this thread, this code should work:
using UnityEditor;
using UnityEngine;
namespace TextureInspector
{
[CanEditMultipleObjects]
[CustomEditor(typeof(Texture2D))]
class TextureInspector : Editor
{
public override bool HasPreviewGUI()
{
return true;
}
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
base.OnPreviewGUI(r, background);
GUI.DrawTexture(r, target as Texture2D, ScaleMode.ScaleToFit);
}
}
}