SetMipMapBiasNoDirty() private method

private SetMipMapBiasNoDirty ( Texture tex, float bias ) : void
tex UnityEngine.Texture
bias float
return void
示例#1
0
        protected void DrawTexture()
        {
            int   num        = Mathf.Max(this.m_Texture.width, 1);
            float num2       = Mathf.Min(this.m_MipLevel, (float)(TextureUtil.GetMipmapCount(this.m_Texture) - 1));
            float mipMapBias = this.m_Texture.mipMapBias;

            TextureUtil.SetMipMapBiasNoDirty(this.m_Texture, num2 - this.Log2((float)num / this.m_TextureRect.width));
            FilterMode filterMode = this.m_Texture.filterMode;

            TextureUtil.SetFilterModeNoDirty(this.m_Texture, FilterMode.Point);
            if (this.m_ShowAlpha)
            {
                if (this.m_TextureAlphaOverride != null)
                {
                    EditorGUI.DrawTextureTransparent(this.m_TextureRect, this.m_TextureAlphaOverride);
                }
                else
                {
                    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 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);
                }
            }
        }
示例#3
0
        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        = 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);
            }
        }