архитектура для текстурного атласа
This commit is contained in:
1 parent
162ead8eeb
commit
f84e9a79f1
77 files changed
+14053
-1
No files matched your search
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user