47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using UnityEngine;
|
||
using UnityEditor; // Обязательная библиотека для редактора
|
||
|
||
// Говорим Unity, что этот скрипт меняет инспектор для файлов AtlasStyleSO
|
||
[CustomEditor(typeof(AtlasStyleSO))]
|
||
public class AtlasStyleSOEditor : Editor
|
||
{
|
||
// Эта функция включает то самое окно превью внизу
|
||
public override bool HasPreviewGUI()
|
||
{
|
||
return true;
|
||
}
|
||
|
||
// Название вкладки превью
|
||
public override GUIContent GetPreviewTitle()
|
||
{
|
||
return new GUIContent("Atlas Preview");
|
||
}
|
||
|
||
// Здесь мы рисуем саму картинку
|
||
public override void OnPreviewGUI(Rect r, GUIStyle background)
|
||
{
|
||
// Получаем доступ к нашему ScriptableObject
|
||
AtlasStyleSO style = (AtlasStyleSO)target;
|
||
|
||
if (style.previewAtlas == null)
|
||
{
|
||
// Если текстуру не назначили, пишем подсказку
|
||
GUIStyle textStyle = new GUIStyle() { alignment = TextAnchor.MiddleCenter };
|
||
textStyle.normal.textColor = Color.gray;
|
||
GUI.Label(r, "Assign Preview Atlas to see preview", textStyle);
|
||
return;
|
||
}
|
||
|
||
// Превращаем наш Vector4 (Tiling/Offset) в квадрат (Rect) для отрисовки.
|
||
// В Unity Rect принимает (Offset X, Offset Y, Tiling X, Tiling Y)
|
||
Rect texCoords = new Rect(
|
||
style.atlasRect.z,
|
||
style.atlasRect.w,
|
||
style.atlasRect.x,
|
||
style.atlasRect.y
|
||
);
|
||
|
||
// Рисуем текстуру с применением координат!
|
||
GUI.DrawTextureWithTexCoords(r, style.previewAtlas, texCoords);
|
||
}
|
||
} |