UnityEditor.TextureInspector.RenderStaticPreview C# (CSharp) Method

RenderStaticPreview() public method

public RenderStaticPreview ( string assetPath, Object subAssets, int width, int height ) : Texture2D
assetPath string
subAssets Object
width int
height int
return UnityEngine.Texture2D
        public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
        {
            Texture2D textured2;
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return null;
            }
            Texture target = base.target as Texture;
            if (this.IsCubemap())
            {
                return this.m_CubemapPreview.RenderStaticPreview(target, width, height);
            }
            TextureImporter atPath = AssetImporter.GetAtPath(assetPath) as TextureImporter;
            if ((atPath != null) && (atPath.spriteImportMode == SpriteImportMode.Polygon))
            {
                Sprite sprite = subAssets[0] as Sprite;
                if (sprite != null)
                {
                    return SpriteInspector.BuildPreviewTexture(width, height, sprite, null, true);
                }
            }
            PreviewHelpers.AdjustWidthAndHeightForStaticPreview(target.width, target.height, ref width, ref height);
            RenderTexture active = RenderTexture.active;
            Rect rawViewportRect = ShaderUtil.rawViewportRect;
            bool flag = !TextureUtil.GetLinearSampled(target);
            RenderTexture dest = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, !flag ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB);
            Material materialForSpecialTexture = EditorGUI.GetMaterialForSpecialTexture(target);
            GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
            if (materialForSpecialTexture != null)
            {
                if (Unsupported.IsDeveloperBuild())
                {
                    materialForSpecialTexture = new Material(materialForSpecialTexture);
                }
                Graphics.Blit(target, dest, materialForSpecialTexture);
            }
            else
            {
                Graphics.Blit(target, dest);
            }
            GL.sRGBWrite = false;
            RenderTexture.active = dest;
            Texture2D textured3 = base.target as Texture2D;
            if ((textured3 != null) && textured3.alphaIsTransparency)
            {
                textured2 = new Texture2D(width, height, TextureFormat.RGBA32, false);
            }
            else
            {
                textured2 = new Texture2D(width, height, TextureFormat.RGB24, false);
            }
            textured2.ReadPixels(new Rect(0f, 0f, (float) width, (float) height), 0, 0);
            textured2.Apply();
            RenderTexture.ReleaseTemporary(dest);
            EditorGUIUtility.SetRenderTextureNoViewport(active);
            ShaderUtil.rawViewportRect = rawViewportRect;
            if ((materialForSpecialTexture != null) && Unsupported.IsDeveloperBuild())
            {
                Object.DestroyImmediate(materialForSpecialTexture);
            }
            return textured2;
        }