public override void OnInspectorGUI() { this.IsReadableGUI(); EditorGUI.BeginChangeCheck(); this.TextureSettingsGUI(); if (EditorGUI.EndChangeCheck()) { UnityEngine.Object[] targets = base.targets; for (int i = 0; i < targets.Length; i++) { AssetImporter assetImporter = (AssetImporter)targets[i]; Texture tex = AssetDatabase.LoadMainAssetAtPath(assetImporter.assetPath) as Texture; if (this.m_FilterMode.intValue != -1) { TextureUtil.SetFilterModeNoDirty(tex, (FilterMode)this.m_FilterMode.intValue); } if ((this.m_WrapU.intValue != -1 || this.m_WrapV.intValue != -1 || this.m_WrapW.intValue != -1) && !this.m_WrapU.hasMultipleDifferentValues && !this.m_WrapV.hasMultipleDifferentValues && !this.m_WrapW.hasMultipleDifferentValues) { TextureUtil.SetWrapModeNoDirty(tex, (TextureWrapMode)this.m_WrapU.intValue, (TextureWrapMode)this.m_WrapV.intValue, (TextureWrapMode)this.m_WrapW.intValue); } } SceneView.RepaintAll(); } GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.FlexibleSpace(); base.ApplyRevertGUI(); GUILayout.EndHorizontal(); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (!SystemInfo.supports2DArrayTextures) { if (Event.current.type == EventType.Repaint) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "2D texture array preview not supported"); } return; } Texture2DArray t = (Texture2DArray)target; Rect scrubberRect = r; scrubberRect.height = kScrubberHeight; r.yMin += kScrubberHeight + kScrubberMargin; DoSliceScrubber(scrubberRect, t); if (Event.current.type == EventType.Repaint) { InitPreview(); m_Material.mainTexture = t; // If multiple objects are selected, we might be using a slice level before the maximum int effectiveSlice = Mathf.Clamp(m_Slice, 0, t.depth - 1); m_Material.SetInt("_SliceIndex", effectiveSlice); m_Material.SetInt("_AlphaOnly", showAlpha ? 1 : 0); int texWidth = Mathf.Max(t.width, 1); int texHeight = Mathf.Max(t.height, 1); float effectiveMipLevel = GetMipLevelForRendering(); float zoomLevel = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1); Rect wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel); PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); FilterMode oldFilter = t.filterMode; TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point); EditorGUI.DrawPreviewTexture(wantedRect, t, m_Material, ScaleMode.StretchToFill, 0, effectiveMipLevel); TextureUtil.SetFilterModeNoDirty(t, oldFilter); m_Pos = PreviewGUI.EndScrollView(); if (effectiveSlice != 0 || (int)effectiveMipLevel != 0) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 30), "Slice " + effectiveSlice + "\nMip " + effectiveMipLevel); } } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (m_Dimension.intValue == (int)UnityEngine.Rendering.TextureDimension.Tex2DArray) { if (!SystemInfo.supports2DArrayTextures) { if (Event.current.type == EventType.Repaint) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "2D texture array preview not supported"); } return; } RenderTexture rt = (RenderTexture)target; if (Event.current.type == EventType.Repaint) { InitPreview(); m_Material.mainTexture = rt; // If multiple objects are selected, we might be using a slice level before the maximum int effectiveSlice = Mathf.Clamp(m_Slice, 0, rt.volumeDepth - 1); m_Material.SetInt(s_ShaderSliceIndex, effectiveSlice); m_Material.SetInt(s_ShaderToSrgb, QualitySettings.activeColorSpace == ColorSpace.Linear ? 1 : 0); int texWidth = Mathf.Max(rt.width, 1); int texHeight = Mathf.Max(rt.height, 1); float zoomLevel = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1); Rect wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel); PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); FilterMode oldFilter = rt.filterMode; TextureUtil.SetFilterModeNoDirty(rt, FilterMode.Point); EditorGUI.DrawPreviewTexture(wantedRect, rt, m_Material, ScaleMode.StretchToFill, 0, mipLevel); TextureUtil.SetFilterModeNoDirty(rt, oldFilter); m_Pos = PreviewGUI.EndScrollView(); if (effectiveSlice != 0 || (int)mipLevel != 0) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 30), "Slice " + effectiveSlice + "\nMip " + mipLevel); } } } else { base.OnPreviewGUI(r, background); } }
public void OnPreviewGUI(Texture t, Rect r, GUIStyle background, float exposure, TextureInspector.PreviewMode previewMode, float mipLevel) { if (t == null) { return; } if (!SystemInfo.supports2DArrayTextures) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40), "2D texture array preview not supported"); return; } InitPreviewMaterialIfNeeded(); m_Material.mainTexture = t; int effectiveSlice = GetEffectiveSlice(t); m_Material.SetFloat(s_ShaderSliceIndex, (float)effectiveSlice); m_Material.SetFloat(s_ShaderToSrgb, QualitySettings.activeColorSpace == ColorSpace.Linear ? 1.0f : 0.0f); m_Material.SetFloat(s_ShaderIsNormalMap, TextureInspector.IsNormalMap(t) ? 1.0f : 0.0f); SetShaderColorMask(previewMode); int texWidth = Mathf.Max(t.width, 1); int texHeight = Mathf.Max(t.height, 1); float effectiveMipLevel = GetMipLevelForRendering(t, mipLevel); float zoomLevel = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1); Rect wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel); PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); FilterMode oldFilter = t.filterMode; TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point); EditorGUI.DrawPreviewTexture(wantedRect, t, m_Material, ScaleMode.StretchToFill, 0, effectiveMipLevel, UnityEngine.Rendering.ColorWriteMask.All, exposure); TextureUtil.SetFilterModeNoDirty(t, oldFilter); m_Pos = PreviewGUI.EndScrollView(); if (effectiveSlice != 0 || (int)effectiveMipLevel != 0) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y + 10, r.width, 30), "Slice " + effectiveSlice + "\nMip " + effectiveMipLevel); } }
protected void DrawTexture() { int num = Mathf.Max(this.m_Texture.width, 1); float num2 = Mathf.Min(this.m_MipLevel, (float)(TextureUtil.CountMipmaps(this.m_Texture) - 1)); float mipMapBias = this.m_Texture.mipMapBias; TextureUtil.SetMipMapBiasNoDirty(this.m_Texture, num2 - this.Log2(((float)num) / this.m_TextureRect.width)); UnityEngine.FilterMode filterMode = this.m_Texture.filterMode; TextureUtil.SetFilterModeNoDirty(this.m_Texture, UnityEngine.FilterMode.Point); if (this.m_ShowAlpha) { EditorGUI.DrawTextureAlpha(this.m_TextureRect, this.m_Texture); } else { EditorGUI.DrawTextureTransparent(this.m_TextureRect, this.m_Texture); } TextureUtil.SetMipMapBiasNoDirty(this.m_Texture, mipMapBias); TextureUtil.SetFilterModeNoDirty(this.m_Texture, filterMode); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(m_IsReadable, Styles.readWrite); EditorGUILayout.PropertyField(m_sRGBTexture, Styles.sRGBTexture); EditorGUI.BeginChangeCheck(); TextureSettingsGUI(); if (EditorGUI.EndChangeCheck()) { // copy pasted from TextureImporterInspector.TextureSettingsGUI() foreach (AssetImporter importer in targets) { Texture tex = AssetDatabase.LoadMainAssetAtPath(importer.assetPath) as Texture; if (tex != null) { if (m_FilterMode.intValue != -1) { TextureUtil.SetFilterModeNoDirty(tex, (FilterMode)m_FilterMode.intValue); } if ((m_WrapU.intValue != -1 || m_WrapV.intValue != -1 || m_WrapW.intValue != -1) && !m_WrapU.hasMultipleDifferentValues && !m_WrapV.hasMultipleDifferentValues && !m_WrapW.hasMultipleDifferentValues) { TextureUtil.SetWrapModeNoDirty(tex, (TextureWrapMode)m_WrapU.intValue, (TextureWrapMode)m_WrapV.intValue, (TextureWrapMode)m_WrapW.intValue); } } } SceneView.RepaintAll(); } EditorGUILayout.PropertyField(m_StreamingMipmaps, Styles.streamingMipmaps); if (m_StreamingMipmaps.boolValue && !m_StreamingMipmaps.hasMultipleDifferentValues) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_StreamingMipmapsPriority, Styles.streamingMipmapsPriority); EditorGUI.indentLevel--; } serializedObject.ApplyModifiedProperties(); ApplyRevertGUI(); }
// wrap/filter/aniso editors will change serialized object // but in case of textures we need an extra step to ApplySettings (so rendering uses new values) // alas we cant have good things: it will be PITA to make sure we always call that after applying changes to serialized object // meaning that we need to work without relying on it, hence we do similar to TextureImporter: // use TextureUtil methods to update texture settings from current values of serialized property // another possibility would be to do it separately for wrap/filter/aniso // alas for wrapmode i dont see how it can be done clearly and leaving it out seems a bit weird protected void ApplySettingsToTextures() { bool anisoDiffer = m_Aniso.hasMultipleDifferentValues, filterDiffer = m_FilterMode.hasMultipleDifferentValues; bool wrapDiffer = m_WrapU.hasMultipleDifferentValues || m_WrapV.hasMultipleDifferentValues || m_WrapW.hasMultipleDifferentValues; foreach (Texture tex in targets) { if (!anisoDiffer) { TextureUtil.SetAnisoLevelNoDirty(tex, m_Aniso.intValue); } if (!filterDiffer) { TextureUtil.SetFilterModeNoDirty(tex, (FilterMode)m_FilterMode.intValue); } if (!wrapDiffer) { TextureUtil.SetWrapModeNoDirty(tex, (TextureWrapMode)m_WrapU.intValue, (TextureWrapMode)m_WrapV.intValue, (TextureWrapMode)m_WrapW.intValue); } } }
// wrap/filter/aniso editors will change serialized object // but in case of textures we need an extra step to ApplySettings (so rendering uses new values) // alas we cant have good things: it will be PITA to make sure we always call that after applying changes to serialized object // meaning that we need to work without relying on it, hence we do similar to TextureImporter: // use TextureUtil methods to update texture settings from current values of serialized property // another possibility would be to do it separately for wrap/filter/aniso // alas for wrapmode i dont see how it can be done clearly and leaving it out seems a bit weird protected void ApplySettingsToTextures() { bool anisoDiffer = m_Aniso.hasMultipleDifferentValues, filterDiffer = m_FilterMode.hasMultipleDifferentValues; bool wrapDiffer = m_WrapU.hasMultipleDifferentValues || m_WrapV.hasMultipleDifferentValues || m_WrapW.hasMultipleDifferentValues; foreach (Texture tex in targets) { if (m_Aniso.intValue != -1 && !anisoDiffer) { TextureUtil.SetAnisoLevelNoDirty(tex, m_Aniso.intValue); } if (m_FilterMode.intValue != -1 && !filterDiffer) { TextureUtil.SetFilterModeNoDirty(tex, (FilterMode)m_FilterMode.intValue); } // NB i am not sure if it is *possible* to have -1 in there and if it make sense to pass -1 to SetWrapModeNoDirty // NB but this is how TextureImporter checks things and who am i to argue if ((m_WrapU.intValue != -1 || m_WrapV.intValue != -1 || m_WrapW.intValue != -1) && !wrapDiffer) { TextureUtil.SetWrapModeNoDirty(tex, (TextureWrapMode)m_WrapU.intValue, (TextureWrapMode)m_WrapV.intValue, (TextureWrapMode)m_WrapW.intValue); } } }
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); } } } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } Texture target = base.target as Texture; RenderTexture texture2 = target as RenderTexture; if (texture2 != null) { if (!SystemInfo.SupportsRenderTextureFormat(texture2.format)) { return; } texture2.Create(); } if (this.IsCubemap()) { this.m_CubemapPreview.OnPreviewGUI(target, r, background); } else { int num = Mathf.Max(target.width, 1); int num2 = Mathf.Max(target.height, 1); float mipLevelForRendering = this.GetMipLevelForRendering(); float num4 = Mathf.Min(Mathf.Min((float)(r.width / ((float)num)), (float)(r.height / ((float)num2))), 1f); Rect viewRect = new Rect(r.x, r.y, num * num4, num2 * num4); PreviewGUI.BeginScrollView(r, this.m_Pos, viewRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); float mipMapBias = target.mipMapBias; TextureUtil.SetMipMapBiasNoDirty(target, mipLevelForRendering - this.Log2(((float)num) / viewRect.width)); UnityEngine.FilterMode filterMode = target.filterMode; TextureUtil.SetFilterModeNoDirty(target, UnityEngine.FilterMode.Point); if (this.m_ShowAlpha) { EditorGUI.DrawTextureAlpha(viewRect, target); } else { Texture2D textured = target as Texture2D; if ((textured != null) && textured.alphaIsTransparency) { EditorGUI.DrawTextureTransparent(viewRect, target); } else { EditorGUI.DrawPreviewTexture(viewRect, target); } } if ((viewRect.width > 32f) && (viewRect.height > 32f)) { TextureImporter atPath = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(target)) as TextureImporter; SpriteMetaData[] spritesheet = atPath?.spritesheet; if ((spritesheet != null) && (atPath.spriteImportMode == SpriteImportMode.Multiple)) { Rect outScreenRect = new Rect(); Rect outSourceRect = new Rect(); GUI.CalculateScaledTextureRects(viewRect, ScaleMode.StretchToFill, ((float)target.width) / ((float)target.height), ref outScreenRect, ref outSourceRect); int width = target.width; int height = target.height; atPath.GetWidthAndHeight(ref width, ref height); float num8 = ((float)target.width) / ((float)width); HandleUtility.ApplyWireMaterial(); GL.PushMatrix(); GL.MultMatrix(Handles.matrix); GL.Begin(1); GL.Color(new Color(1f, 1f, 1f, 0.5f)); foreach (SpriteMetaData data in spritesheet) { Rect rect = data.rect; Rect rect5 = new Rect { xMin = outScreenRect.xMin + (outScreenRect.width * ((rect.xMin / ((float)target.width)) * num8)), xMax = outScreenRect.xMin + (outScreenRect.width * ((rect.xMax / ((float)target.width)) * num8)), yMin = outScreenRect.yMin + (outScreenRect.height * (1f - ((rect.yMin / ((float)target.height)) * num8))), yMax = outScreenRect.yMin + (outScreenRect.height * (1f - ((rect.yMax / ((float)target.height)) * num8))) }; this.DrawRect(rect5); } GL.End(); GL.PopMatrix(); } } TextureUtil.SetMipMapBiasNoDirty(target, mipMapBias); TextureUtil.SetFilterModeNoDirty(target, filterMode); this.m_Pos = PreviewGUI.EndScrollView(); if (mipLevelForRendering != 0f) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + mipLevelForRendering); } } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } // show texture Texture t = target as Texture; if (t == null) // texture might be gone by now, in case this code is used for floating texture preview { return; } // Render target must be created before we can display it (case 491797) RenderTexture rt = t as RenderTexture; if (rt != null) { if (!SystemInfo.IsFormatSupported(rt.graphicsFormat, FormatUsage.Render)) { return; // can't do this RT format } rt.Create(); } if (IsCubemap()) { m_CubemapPreview.OnPreviewGUI(t, r, background); return; } // target can report zero sizes in some cases just after a parameter change; // guard against that. int texWidth = Mathf.Max(t.width, 1); int texHeight = Mathf.Max(t.height, 1); float mipLevel = GetMipLevelForRendering(); float zoomLevel = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1); Rect wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel); PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb"); FilterMode oldFilter = t.filterMode; TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point); Texture2D t2d = t as Texture2D; ColorWriteMask colorWriteMask = ColorWriteMask.All; switch (m_PreviewMode) { case PreviewMode.R: colorWriteMask = ColorWriteMask.Red | ColorWriteMask.Alpha; break; case PreviewMode.G: colorWriteMask = ColorWriteMask.Green | ColorWriteMask.Alpha; break; case PreviewMode.B: colorWriteMask = ColorWriteMask.Blue | ColorWriteMask.Alpha; break; } if (m_PreviewMode == PreviewMode.A) { EditorGUI.DrawTextureAlpha(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel); } else { if (t2d != null && t2d.alphaIsTransparency) { EditorGUI.DrawTextureTransparent(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask); } else { EditorGUI.DrawPreviewTexture(wantedRect, t, null, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask); } } // TODO: Less hacky way to prevent sprite rects to not appear in smaller previews like icons. if ((wantedRect.width > 32 && wantedRect.height > 32) && Event.current.type == EventType.Repaint) { string path = AssetDatabase.GetAssetPath(t); TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter; SpriteMetaData[] spritesheet = textureImporter != null ? textureImporter.spritesheet : null; if (spritesheet != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple) { Rect screenRect = new Rect(); Rect sourceRect = new Rect(); GUI.CalculateScaledTextureRects(wantedRect, ScaleMode.StretchToFill, (float)t.width / (float)t.height, ref screenRect, ref sourceRect); int origWidth = t.width; int origHeight = t.height; textureImporter.GetWidthAndHeight(ref origWidth, ref origHeight); float definitionScale = (float)t.width / (float)origWidth; HandleUtility.ApplyWireMaterial(); GL.PushMatrix(); GL.MultMatrix(Handles.matrix); GL.Begin(GL.LINES); GL.Color(new Color(1f, 1f, 1f, 0.5f)); foreach (SpriteMetaData sprite in spritesheet) { Rect spriteRect = sprite.rect; Rect spriteScreenRect = new Rect(); spriteScreenRect.xMin = screenRect.xMin + screenRect.width * (spriteRect.xMin / t.width * definitionScale); spriteScreenRect.xMax = screenRect.xMin + screenRect.width * (spriteRect.xMax / t.width * definitionScale); spriteScreenRect.yMin = screenRect.yMin + screenRect.height * (1f - spriteRect.yMin / t.height * definitionScale); spriteScreenRect.yMax = screenRect.yMin + screenRect.height * (1f - spriteRect.yMax / t.height * definitionScale); DrawRect(spriteScreenRect); } GL.End(); GL.PopMatrix(); } } TextureUtil.SetFilterModeNoDirty(t, oldFilter); m_Pos = PreviewGUI.EndScrollView(); if (mipLevel != 0) { EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20), "Mip " + mipLevel); } }
public override void OnPreviewGUI(Rect r, GUIStyle background) { if (Event.current.type == EventType.Repaint) { background.Draw(r, false, false, false, false); } Texture target = this.target as Texture; RenderTexture renderTexture = target as RenderTexture; if ((UnityEngine.Object)renderTexture != (UnityEngine.Object)null) { if (!SystemInfo.SupportsRenderTextureFormat(renderTexture.format)) { return; } renderTexture.Create(); } if (this.IsCubemap()) { this.m_CubemapPreview.OnPreviewGUI(target, r, background); } else { int num1 = Mathf.Max(target.width, 1); int num2 = Mathf.Max(target.height, 1); float levelForRendering = this.GetMipLevelForRendering(); float num3 = Mathf.Min(Mathf.Min(r.width / (float)num1, r.height / (float)num2), 1f); Rect rect1 = new Rect(r.x, r.y, (float)num1 * num3, (float)num2 * num3); PreviewGUI.BeginScrollView(r, this.m_Pos, rect1, (GUIStyle)"PreHorizontalScrollbar", (GUIStyle)"PreHorizontalScrollbarThumb"); float mipMapBias = target.mipMapBias; TextureUtil.SetMipMapBiasNoDirty(target, levelForRendering - this.Log2((float)num1 / rect1.width)); UnityEngine.FilterMode filterMode = target.filterMode; TextureUtil.SetFilterModeNoDirty(target, UnityEngine.FilterMode.Point); if (this.m_ShowAlpha) { EditorGUI.DrawTextureAlpha(rect1, target); } else { Texture2D texture2D = target as Texture2D; if ((UnityEngine.Object)texture2D != (UnityEngine.Object)null && texture2D.alphaIsTransparency) { EditorGUI.DrawTextureTransparent(rect1, target); } else { EditorGUI.DrawPreviewTexture(rect1, target); } } if ((double)rect1.width > 32.0 && (double)rect1.height > 32.0) { TextureImporter atPath = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath((UnityEngine.Object)target)) as TextureImporter; SpriteMetaData[] spriteMetaDataArray = !((UnityEngine.Object)atPath != (UnityEngine.Object)null) ? (SpriteMetaData[])null : atPath.spritesheet; if (spriteMetaDataArray != null && atPath.spriteImportMode == SpriteImportMode.Multiple) { Rect outScreenRect = new Rect(); Rect outSourceRect = new Rect(); GUI.CalculateScaledTextureRects(rect1, ScaleMode.StretchToFill, (float)target.width / (float)target.height, ref outScreenRect, ref outSourceRect); int width = target.width; int height = target.height; atPath.GetWidthAndHeight(ref width, ref height); float num4 = (float)target.width / (float)width; HandleUtility.ApplyWireMaterial(); GL.PushMatrix(); GL.MultMatrix(Handles.matrix); GL.Begin(1); GL.Color(new Color(1f, 1f, 1f, 0.5f)); foreach (SpriteMetaData spriteMetaData in spriteMetaDataArray) { Rect rect2 = spriteMetaData.rect; this.DrawRect(new Rect() { xMin = outScreenRect.xMin + outScreenRect.width * (rect2.xMin / (float)target.width * num4), xMax = outScreenRect.xMin + outScreenRect.width * (rect2.xMax / (float)target.width * num4), yMin = outScreenRect.yMin + outScreenRect.height * (float)(1.0 - (double)rect2.yMin / (double)target.height * (double)num4), yMax = outScreenRect.yMin + outScreenRect.height * (float)(1.0 - (double)rect2.yMax / (double)target.height * (double)num4) }); } GL.End(); GL.PopMatrix(); } } TextureUtil.SetMipMapBiasNoDirty(target, mipMapBias); TextureUtil.SetFilterModeNoDirty(target, filterMode); this.m_Pos = PreviewGUI.EndScrollView(); if ((double)levelForRendering == 0.0) { return; } EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + (object)levelForRendering); } }