Объявление
public static void DrawPreviewTexture(Rect position, Texture image, Material mat = null, ScaleMode scaleMode = ScaleMode.StretchToFill, float imageAspect = 0, float mipLevel = -1, Rendering.ColorWriteMask colorWriteMask = ColorWriteMask.All, float exposure = 0);Параметры
position | Прямоугольник на экране, чтобы нарисовать текстуру внутри. |
image | Текстура для отображения. |
mat | Материал, который будет использоваться при рисовании текстуры. |
scaleMode | Как масштабировать изображение, если его соотношение сторон не соответствует соотношению сторон, которое нужно отрисовать. |
imageAspect | Соотношение сторон, используемое для исходного изображения. Если 0 (по умолчанию), используется соотношение сторон изображения. |
mipLevel | Мип-уровень для семпла. Если отрицательный, текстура сэмплируется нормально. Устанавливает свойство _Mip материала. |
colorWriteMask | Указывает, какие цветовые компоненты изображения будут записаны. Устанавливает свойство _ColorMask материала. |
exposure | Определяет экспозицию текстуры. Устанавливает свойство _Exposure материала. |
Описание
Рисует текстуру внутри прямоугольника.
Если значение mat равно null (по умолчанию), соответствующий материал будет выбран для карты освещения RGBM или doubleLDR или карты нормалей. в противном случае будет выбран резервный материал для блитинга.

// Загружаем текстуру, отображаем текстуру, отображаем ее альфа-канал и
// показать превью перевернутой текстуры
using UnityEditor;
using UnityEngine;
class EditorGUITextures : EditorWindow
{
Texture2D texture;
Texture2D invertedTexture;
bool showInverted = false;
[MenuItem("Examples/Texture Previewer")]
static void Init()
{
var window = GetWindow("Texture Previewer");
window.position = new Rect(0, 0, 400, 200);
window.Show();
}
void OnGUI()
{
texture = (Texture2D)EditorGUI.ObjectField(new Rect(3, 3, 200, 20),
"Add a Texture:",
texture,
typeof(Texture2D));
if (GUI.Button(new Rect(208, 3, position.width - 210, 20), "Process Inverted"))
{
if (invertedTexture)
DestroyImmediate(invertedTexture);
//Copy the new texture
invertedTexture = new Texture2D(texture.width,
texture.height,
texture.format,
(texture.mipmapCount != 0));
for (int m = 0; m < texture.mipmapCount; m++)
invertedTexture.SetPixels(texture.GetPixels(m), m);
InvertColors();
showInverted = true;
}
if (texture)
{
EditorGUI.PrefixLabel(new Rect(25, 45, 100, 15), 0, new GUIContent("Preview:"));
EditorGUI.DrawPreviewTexture(new Rect(25, 60, 100, 100), texture);
EditorGUI.PrefixLabel(new Rect(150, 45, 100, 15), 0, new GUIContent("Alpha:"));
EditorGUI.DrawTextureAlpha(new Rect(150, 60, 100, 100), texture);
EditorGUI.PrefixLabel(new Rect(275, 45, 100, 15), 0, new GUIContent("Inverted:"));
if (showInverted)
EditorGUI.DrawPreviewTexture(new Rect(275, 60, 100, 100), invertedTexture);
if (GUI.Button(new Rect(3, position.height - 25, position.width - 6, 20), "Clear texture"))
{
texture = EditorGUIUtility.whiteTexture;
showInverted = false;
}
}
else
{
EditorGUI.PrefixLabel(
new Rect(3, position.height - 25, position.width - 6, 20),
0,
new GUIContent("No texture found"));
}
}
void InvertColors()
{
for (int m = 0; m < invertedTexture.mipmapCount; m++)
{
Color[] c = invertedTexture.GetPixels(m);
for (int i = 0; i < c.Length; i++)
{
c[i].r = 1 - c[i].r;
c[i].g = 1 - c[i].g;
c[i].b = 1 - c[i].b;
}
invertedTexture.SetPixels(c, m);
}
invertedTexture.Apply();
}
}