public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (Event.current.type == EventType.Repaint)
{
background.Draw(r, false, false, false, false);
}
Texture texture = base.target as Texture;
if (!(texture == null))
{
RenderTexture renderTexture = texture as RenderTexture;
if (renderTexture != null)
{
if (!SystemInfo.SupportsRenderTextureFormat(renderTexture.format))
{
return;
}
renderTexture.Create();
}
if (this.IsCubemap())
{
this.m_CubemapPreview.OnPreviewGUI(texture, r, background);
}
else
{
int num = Mathf.Max(texture.width, 1);
int num2 = Mathf.Max(texture.height, 1);
float mipLevelForRendering = this.GetMipLevelForRendering();
float num3 = Mathf.Min(Mathf.Min(r.width / (float)num, r.height / (float)num2), 1f);
Rect rect = new Rect(r.x, r.y, (float)num * num3, (float)num2 * num3);
PreviewGUI.BeginScrollView(r, this.m_Pos, rect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
float mipMapBias = texture.mipMapBias;
TextureUtil.SetMipMapBiasNoDirty(texture, mipLevelForRendering - this.Log2((float)num / rect.width));
FilterMode filterMode = texture.filterMode;
TextureUtil.SetFilterModeNoDirty(texture, FilterMode.Point);
if (this.m_ShowAlpha)
{
EditorGUI.DrawTextureAlpha(rect, texture);
}
else
{
Texture2D texture2D = texture as Texture2D;
if (texture2D != null && texture2D.alphaIsTransparency)
{
EditorGUI.DrawTextureTransparent(rect, texture);
}
else
{
EditorGUI.DrawPreviewTexture(rect, texture);
}
}
if (rect.width > 32f && rect.height > 32f)
{
string assetPath = AssetDatabase.GetAssetPath(texture);
TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
SpriteMetaData[] array = (!(textureImporter != null)) ? null : textureImporter.spritesheet;
if (array != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple)
{
Rect rect2 = default(Rect);
Rect rect3 = default(Rect);
GUI.CalculateScaledTextureRects(rect, ScaleMode.StretchToFill, (float)texture.width / (float)texture.height, ref rect2, ref rect3);
int width = texture.width;
int height = texture.height;
textureImporter.GetWidthAndHeight(ref width, ref height);
float num4 = (float)texture.width / (float)width;
HandleUtility.ApplyWireMaterial();
GL.PushMatrix();
GL.MultMatrix(Handles.matrix);
GL.Begin(1);
GL.Color(new Color(1f, 1f, 1f, 0.5f));
SpriteMetaData[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
SpriteMetaData spriteMetaData = array2[i];
Rect rect4 = spriteMetaData.rect;
this.DrawRect(new Rect
{
xMin = rect2.xMin + rect2.width * (rect4.xMin / (float)texture.width * num4),
xMax = rect2.xMin + rect2.width * (rect4.xMax / (float)texture.width * num4),
yMin = rect2.yMin + rect2.height * (1f - rect4.yMin / (float)texture.height * num4),
yMax = rect2.yMin + rect2.height * (1f - rect4.yMax / (float)texture.height * num4)
});
}
GL.End();
GL.PopMatrix();
}
}
TextureUtil.SetMipMapBiasNoDirty(texture, mipMapBias);
TextureUtil.SetFilterModeNoDirty(texture, filterMode);
this.m_Pos = PreviewGUI.EndScrollView();
if (mipLevelForRendering != 0f)
{
EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + mipLevelForRendering);
}
}
}
}