public override void OnPreviewSettings()
{
if (IsCubemap())
{
m_CubemapPreview.OnPreviewSettings(targets);
return;
}
if (IsTexture2DArray() && !SystemInfo.supports2DArrayTextures)
{
return;
}
if (s_Styles == null)
{
s_Styles = new Styles();
}
// TextureInspector code is reused for RenderTexture and Cubemap inspectors.
// Make sure we can handle the situation where target is just a Texture and
// not a Texture2D. It's also used for large popups for mini texture fields,
// and while it's being shown the actual texture object might disappear --
// make sure to handle null targets.
Texture tex = target as Texture;
bool alphaOnly = false;
bool hasAlpha = true;
int mipCount = 1;
if (target is Texture2D)
{
alphaOnly = true;
hasAlpha = false;
}
foreach (Texture t in targets)
{
if (t == null) // texture might have disappeared while we're showing this in a preview popup
{
continue;
}
TextureFormat format = 0;
bool checkFormat = false;
if (t is Texture2D)
{
format = (t as Texture2D).format;
checkFormat = true;
}
if (checkFormat)
{
if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
{
alphaOnly = false;
}
if (TextureUtil.HasAlphaTextureFormat(format))
{
TextureUsageMode mode = TextureUtil.GetUsageMode(t);
if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha
{
hasAlpha = true;
}
}
}
mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t));
}
List <PreviewMode> previewCandidates = new List <PreviewMode>(5);
previewCandidates.Add(PreviewMode.RGB);
previewCandidates.Add(PreviewMode.R);
previewCandidates.Add(PreviewMode.G);
previewCandidates.Add(PreviewMode.B);
previewCandidates.Add(PreviewMode.A);
if (alphaOnly)
{
previewCandidates.Clear();
previewCandidates.Add(PreviewMode.A);
m_PreviewMode = PreviewMode.A;
}
else if (!hasAlpha)
{
previewCandidates.Remove(PreviewMode.A);
}
if (previewCandidates.Count > 1 && tex != null && !IsNormalMap(tex))
{
int selectedIndex = previewCandidates.IndexOf(m_PreviewMode);
if (selectedIndex == -1)
{
selectedIndex = 0;
}
if (previewCandidates.Contains(PreviewMode.RGB))
{
m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.RGB, s_Styles.previewButtonContents[0], s_Styles.toolbarButton)
? PreviewMode.RGB
: m_PreviewMode;
}
if (previewCandidates.Contains(PreviewMode.R))
{
m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.R, s_Styles.previewButtonContents[1], s_Styles.toolbarButton)
? PreviewMode.R
: m_PreviewMode;
}
if (previewCandidates.Contains(PreviewMode.G))
{
m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.G, s_Styles.previewButtonContents[2], s_Styles.toolbarButton)
? PreviewMode.G
: m_PreviewMode;
}
if (previewCandidates.Contains(PreviewMode.B))
{
m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.B, s_Styles.previewButtonContents[3], s_Styles.toolbarButton)
? PreviewMode.B
: m_PreviewMode;
}
if (previewCandidates.Contains(PreviewMode.A))
{
m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.A, s_Styles.previewButtonContents[4], s_Styles.toolbarButton)
? PreviewMode.A
: m_PreviewMode;
}
}
if (mipCount > 1)
{
GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel);
GUI.changed = false;
m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.MaxWidth(64)));
//For now, we don't have mipmaps smaller than the tile size when using VT.
if (EditorGUI.UseVTMaterial(tex))
{
int numMipsOfTile = (int)Mathf.Log(VirtualTexturing.EditorHelpers.tileSize, 2) + 1;
m_MipLevel = Mathf.Min(m_MipLevel, Mathf.Max(mipCount - numMipsOfTile, 0));
}
GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel);
}
}