public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }

            Texture texture = target as Texture;

            if (IsCubemap())
            {
                return(m_CubemapPreview.RenderStaticPreview(texture, width, height));
            }

            TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            if (textureImporter != null && textureImporter.textureType == TextureImporterType.Sprite && textureImporter.spriteImportMode == SpriteImportMode.Polygon)
            {
                // If the texture importer is a Sprite of primitive, use the sprite inspector for generating preview/icon.
                if (subAssets.Length > 0)
                {
                    Sprite sprite = subAssets[0] as Sprite;
                    if (sprite)
                    {
                        return(SpriteInspector.BuildPreviewTexture(width, height, sprite, null, true));
                    }
                }
                else
                {
                    return(null);
                }
            }

            PreviewHelpers.AdjustWidthAndHeightForStaticPreview(texture.width, texture.height, ref width, ref height);

            RenderTexture savedRT       = RenderTexture.active;
            Rect          savedViewport = ShaderUtil.rawViewportRect;

            RenderTexture tmp = RenderTexture.GetTemporary(
                width, height,
                0,
                SystemInfo.GetGraphicsFormat(DefaultFormat.LDR));
            Material mat = EditorGUI.GetMaterialForSpecialTexture(texture, null, QualitySettings.activeColorSpace == ColorSpace.Linear, false);

            if (mat != null)
            {
                Graphics.Blit(texture, tmp, mat);
            }
            else
            {
                Graphics.Blit(texture, tmp);
            }

            RenderTexture.active = tmp;
            Texture2D copy;
            Texture2D tex2d = target as Texture2D;

            if (tex2d != null && tex2d.alphaIsTransparency)
            {
                copy = new Texture2D(width, height, TextureFormat.RGBA32, false);
            }
            else
            {
                copy = new Texture2D(width, height, TextureFormat.RGB24, false);
            }
            copy.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            copy.Apply();
            RenderTexture.ReleaseTemporary(tmp);

            EditorGUIUtility.SetRenderTextureNoViewport(savedRT);
            ShaderUtil.rawViewportRect = savedViewport;

            return(copy);
        }
Пример #2
0
        public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }
            Texture texture = this.target as Texture;

            if (this.IsCubemap())
            {
                return(this.m_CubemapPreview.RenderStaticPreview(texture, width, height));
            }
            TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            if (textureImporter != null && textureImporter.spriteImportMode == SpriteImportMode.Polygon)
            {
                Sprite sprite = subAssets[0] as Sprite;
                if (sprite)
                {
                    return(SpriteInspector.BuildPreviewTexture(width, height, sprite, null, true));
                }
            }
            PreviewHelpers.AdjustWidthAndHeightForStaticPreview(texture.width, texture.height, ref width, ref height);
            RenderTexture active          = RenderTexture.active;
            Rect          rawViewportRect = ShaderUtil.rawViewportRect;
            bool          flag            = !TextureUtil.GetLinearSampled(texture);
            RenderTexture temporary       = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, (!flag) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB);
            Material      material        = EditorGUI.GetMaterialForSpecialTexture(texture);

            GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
            if (material)
            {
                if (Unsupported.IsDeveloperBuild())
                {
                    material = new Material(material);
                }
                Graphics.Blit(texture, temporary, material);
            }
            else
            {
                Graphics.Blit(texture, temporary);
            }
            GL.sRGBWrite         = false;
            RenderTexture.active = temporary;
            Texture2D texture2D = this.target as Texture2D;
            Texture2D texture2D2;

            if (texture2D != null && texture2D.alphaIsTransparency)
            {
                texture2D2 = new Texture2D(width, height, TextureFormat.ARGB32, false);
            }
            else
            {
                texture2D2 = new Texture2D(width, height, TextureFormat.RGB24, false);
            }
            texture2D2.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
            texture2D2.Apply();
            RenderTexture.ReleaseTemporary(temporary);
            EditorGUIUtility.SetRenderTextureNoViewport(active);
            ShaderUtil.rawViewportRect = rawViewportRect;
            if (material && Unsupported.IsDeveloperBuild())
            {
                UnityEngine.Object.DestroyImmediate(material);
            }
            return(texture2D2);
        }
Пример #3
0
        public static Texture2D BuildPreviewTexture(int width, int height, Sprite sprite, Material spriteRendererMaterial, bool isPolygon)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }
            float     num           = sprite.rect.width;
            float     num2          = sprite.rect.height;
            Texture2D spriteTexture = SpriteUtility.GetSpriteTexture(sprite, false);

            if (!isPolygon)
            {
                PreviewHelpers.AdjustWidthAndHeightForStaticPreview((int)num, (int)num2, ref width, ref height);
            }
            SavedRenderTargetState state = new SavedRenderTargetState();
            RenderTexture          temp  = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default);

            RenderTexture.active = temp;
            GL.sRGBWrite         = QualitySettings.activeColorSpace == ColorSpace.Linear;
            GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
            Texture texture = null;
            Vector4 vector  = new Vector4(0f, 0f, 0f, 0f);
            bool    flag    = false;
            bool    flag2   = false;

            if (spriteRendererMaterial != null)
            {
                flag  = spriteRendererMaterial.HasProperty("_MainTex");
                flag2 = spriteRendererMaterial.HasProperty("_MainTex_TexelSize");
            }
            Material material = null;

            if (spriteRendererMaterial != null)
            {
                if (flag)
                {
                    texture = spriteRendererMaterial.GetTexture("_MainTex");
                    spriteRendererMaterial.SetTexture("_MainTex", spriteTexture);
                }
                if (flag2)
                {
                    vector = spriteRendererMaterial.GetVector("_MainTex_TexelSize");
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", TextureUtil.GetTexelSizeVector(spriteTexture));
                }
                spriteRendererMaterial.SetPass(0);
            }
            else
            {
                material = new Material(Shader.Find("Hidden/BlitCopy"))
                {
                    mainTexture       = spriteTexture,
                    mainTextureScale  = Vector2.one,
                    mainTextureOffset = Vector2.zero
                };
                material.SetPass(0);
            }
            float num3 = sprite.rect.width / sprite.bounds.size.x;

            Vector2[] vertices  = sprite.vertices;
            Vector2[] uv        = sprite.uv;
            ushort[]  triangles = sprite.triangles;
            Vector2   pivot     = sprite.pivot;

            GL.PushMatrix();
            GL.LoadOrtho();
            GL.Color(new Color(1f, 1f, 1f, 1f));
            GL.Begin(4);
            for (int i = 0; i < sprite.triangles.Length; i++)
            {
                ushort  index   = triangles[i];
                Vector2 vector3 = vertices[index];
                Vector2 vector4 = uv[index];
                GL.TexCoord(new Vector3(vector4.x, vector4.y, 0f));
                GL.Vertex3(((vector3.x * num3) + pivot.x) / num, ((vector3.y * num3) + pivot.y) / num2, 0f);
            }
            GL.End();
            GL.PopMatrix();
            GL.sRGBWrite = false;
            if (spriteRendererMaterial != null)
            {
                if (flag)
                {
                    spriteRendererMaterial.SetTexture("_MainTex", texture);
                }
                if (flag2)
                {
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", vector);
                }
            }
            Texture2D textured2 = new Texture2D(width, height, TextureFormat.ARGB32, false)
            {
                hideFlags = HideFlags.HideAndDontSave
            };

            textured2.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
            textured2.Apply();
            RenderTexture.ReleaseTemporary(temp);
            state.Restore();
            if (material != null)
            {
                Object.DestroyImmediate(material);
            }
            return(textured2);
        }
Пример #4
0
        public static Texture2D BuildPreviewTexture(Sprite sprite, Material spriteRendererMaterial, bool isPolygon, int width, int height, Color color, Matrix4x4 transform)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture || sprite == null)
            {
                return(null);
            }

            var spriteWidth  = sprite.rect.width;
            var spriteHeight = sprite.rect.height;

            Texture2D texture = UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(sprite, false);

            // only adjust the preview texture size if the sprite is not in polygon mode.
            // In polygon mode, we are looking at a 4x4 texture will detailed mesh. It's better to maximize the display of it.
            if (!isPolygon)
            {
                // Try to have a minimum of 64 pixels for width and height, unless requested width and height is smaller
                var minWidth  = Mathf.Min(64, width);
                var minHeight = Mathf.Min(64, height);

                PreviewHelpers.AdjustWidthAndHeightForStaticPreview((int)spriteWidth, (int)spriteHeight, ref width, ref height);

                // Set minimum size for width and height to prevent small previews for small sprites
                width  = Mathf.Max(minWidth, width);
                height = Mathf.Max(minHeight, height);
            }

            SavedRenderTargetState savedRTState = new SavedRenderTargetState();

            RenderTexture tmp = RenderTexture.GetTemporary(
                width,
                height,
                0,
                SystemInfo.GetGraphicsFormat(DefaultFormat.LDR));

            RenderTexture.active = tmp;

            GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));

            Texture _oldTexture      = null;
            Vector4 _oldTexelSize    = new Vector4(0, 0, 0, 0);
            bool    _matHasTexture   = false;
            bool    _matHasTexelSize = false;

            if (spriteRendererMaterial != null)
            {
                _matHasTexture   = spriteRendererMaterial.HasProperty("_MainTex");
                _matHasTexelSize = spriteRendererMaterial.HasProperty("_MainTex_TexelSize");
            }

            bool hasColors = sprite.HasVertexAttribute(VertexAttribute.Color);

            Material copyMaterial = null;

            if (spriteRendererMaterial != null)
            {
                if (_matHasTexture)
                {
                    _oldTexture = spriteRendererMaterial.GetTexture("_MainTex");
                    spriteRendererMaterial.SetTexture("_MainTex", texture);
                }

                if (_matHasTexelSize)
                {
                    _oldTexelSize = spriteRendererMaterial.GetVector("_MainTex_TexelSize");
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", TextureUtil.GetTexelSizeVector(texture));
                }

                spriteRendererMaterial.SetPass(0);
            }
            else
            {
                if (hasColors || texture == null)
                {
                    SpriteUtility.previewSpriteDefaultMaterial.SetPass(0);
                }
                else if (texture != null)
                {
                    copyMaterial                   = new Material(Shader.Find("Hidden/BlitCopy"));
                    copyMaterial.mainTexture       = texture;
                    copyMaterial.mainTextureScale  = Vector2.one;
                    copyMaterial.mainTextureOffset = Vector2.zero;
                    copyMaterial.SetPass(0);
                }
            }

            float pixelsToUnits = sprite.rect.width / sprite.bounds.size.x;

            Vector2[] vertices  = sprite.vertices;
            Vector2[] uvs       = Sprites.SpriteUtility.GetSpriteUVs(sprite, false);
            ushort[]  triangles = sprite.triangles;
            Vector2   pivot     = sprite.pivot;

            NativeSlice <Color32>?colors = null;

            if (hasColors)
            {
                colors = sprite.GetVertexAttribute <Color32>(VertexAttribute.Color);
            }

            GL.PushMatrix();
            GL.LoadOrtho();
            GL.Begin(GL.TRIANGLES);
            for (int i = 0; i < triangles.Length; ++i)
            {
                ushort  index  = triangles[i];
                Vector3 vertex = vertices[index];
                vertex = transform.MultiplyPoint(vertex);
                Vector2 uv = uvs[index];
                GL.Color(colors != null ? colors.Value[index] * color : color);
                GL.TexCoord(new Vector3(uv.x, uv.y, 0));
                GL.Vertex3((vertex.x * pixelsToUnits + pivot.x) / spriteWidth, (vertex.y * pixelsToUnits + pivot.y) / spriteHeight, 0);
            }
            GL.End();
            GL.PopMatrix();

            if (spriteRendererMaterial != null)
            {
                if (_matHasTexture)
                {
                    spriteRendererMaterial.SetTexture("_MainTex", _oldTexture);
                }
                if (_matHasTexelSize)
                {
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", _oldTexelSize);
                }
            }

            var tmp2 = RenderTexture.GetTemporary(width, height, 0, GraphicsFormat.R8G8B8A8_UNorm);

            Graphics.Blit(tmp, tmp2, EditorGUIUtility.GUITextureBlit2SRGBMaterial);

            RenderTexture.active = tmp2;

            Texture2D copy = new Texture2D(width, height, TextureFormat.RGBA32, false);

            copy.hideFlags  = HideFlags.HideAndDontSave;
            copy.filterMode = texture != null ? texture.filterMode : FilterMode.Point;
            copy.anisoLevel = texture != null ? texture.anisoLevel : 0;
            copy.wrapMode   = texture != null ? texture.wrapMode : TextureWrapMode.Clamp;
            copy.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            copy.Apply();
            RenderTexture.ReleaseTemporary(tmp);
            RenderTexture.ReleaseTemporary(tmp2);

            savedRTState.Restore();

            if (copyMaterial != null)
            {
                DestroyImmediate(copyMaterial);
            }

            return(copy);
        }
Пример #5
0
        public static Texture2D BuildPreviewTexture(int width, int height, Sprite sprite, Material spriteRendererMaterial, bool isPolygon)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return((Texture2D)null);
            }
            float     width1        = sprite.rect.width;
            float     height1       = sprite.rect.height;
            Texture2D spriteTexture = UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(sprite, false);

            if (!isPolygon)
            {
                PreviewHelpers.AdjustWidthAndHeightForStaticPreview((int)width1, (int)height1, ref width, ref height);
            }
            SavedRenderTargetState renderTargetState = new SavedRenderTargetState();
            RenderTexture          temporary         = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default);

            RenderTexture.active = temporary;
            GL.sRGBWrite         = QualitySettings.activeColorSpace == ColorSpace.Linear;
            GL.Clear(true, true, new Color(0.0f, 0.0f, 0.0f, 0.0f));
            Texture texture = (Texture)null;
            Vector4 vector  = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
            bool    flag1   = false;
            bool    flag2   = false;

            if ((Object)spriteRendererMaterial != (Object)null)
            {
                flag1 = spriteRendererMaterial.HasProperty("_MainTex");
                flag2 = spriteRendererMaterial.HasProperty("_MainTex_TexelSize");
            }
            Material material = (Material)null;

            if ((Object)spriteRendererMaterial != (Object)null)
            {
                if (flag1)
                {
                    texture = spriteRendererMaterial.GetTexture("_MainTex");
                    spriteRendererMaterial.SetTexture("_MainTex", (Texture)spriteTexture);
                }
                if (flag2)
                {
                    vector = spriteRendererMaterial.GetVector("_MainTex_TexelSize");
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", TextureUtil.GetTexelSizeVector((Texture)spriteTexture));
                }
                spriteRendererMaterial.SetPass(0);
            }
            else
            {
                material                   = new Material(Shader.Find("Hidden/BlitCopy"));
                material.mainTexture       = (Texture)spriteTexture;
                material.mainTextureScale  = Vector2.one;
                material.mainTextureOffset = Vector2.zero;
                material.SetPass(0);
            }
            float num1 = sprite.rect.width / sprite.bounds.size.x;

            Vector2[] vertices  = sprite.vertices;
            Vector2[] uv        = sprite.uv;
            ushort[]  triangles = sprite.triangles;
            Vector2   pivot     = sprite.pivot;

            GL.PushMatrix();
            GL.LoadOrtho();
            GL.Color(new Color(1f, 1f, 1f, 1f));
            GL.Begin(4);
            for (int index = 0; index < triangles.Length; ++index)
            {
                ushort  num2      = triangles[index];
                Vector2 vector2_1 = vertices[(int)num2];
                Vector2 vector2_2 = uv[(int)num2];
                GL.TexCoord(new Vector3(vector2_2.x, vector2_2.y, 0.0f));
                GL.Vertex3((vector2_1.x * num1 + pivot.x) / width1, (vector2_1.y * num1 + pivot.y) / height1, 0.0f);
            }
            GL.End();
            GL.PopMatrix();
            GL.sRGBWrite = false;
            if ((Object)spriteRendererMaterial != (Object)null)
            {
                if (flag1)
                {
                    spriteRendererMaterial.SetTexture("_MainTex", texture);
                }
                if (flag2)
                {
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", vector);
                }
            }
            Texture2D texture2D = new Texture2D(width, height, TextureFormat.ARGB32, false);

            texture2D.hideFlags = HideFlags.HideAndDontSave;
            texture2D.ReadPixels(new Rect(0.0f, 0.0f, (float)width, (float)height), 0, 0);
            texture2D.Apply();
            RenderTexture.ReleaseTemporary(temporary);
            renderTargetState.Restore();
            if ((Object)material != (Object)null)
            {
                Object.DestroyImmediate((Object)material);
            }
            return(texture2D);
        }
Пример #6
0
        public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }

            Texture texture = target as Texture;

            GraphicsFormat format = texture.graphicsFormat;

            if (!(GraphicsFormatUtility.IsIEEE754Format(format) || GraphicsFormatUtility.IsNormFormat(format)))
            {
                // Can't generate correct previews for non-float/norm formats. On Metal and Vulkan this even causes validation errors.
                return(null);
            }

            if (IsCubemap())
            {
                return(m_CubemapPreview.RenderStaticPreview(texture, width, height, GetExposureValueForTexture(texture)));
            }

            if (IsTexture3D())
            {
                return(m_Texture3DPreview.RenderStaticPreview(texture, width, height));
            }

            TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;

            if (textureImporter != null && textureImporter.textureType == TextureImporterType.Sprite && textureImporter.spriteImportMode == SpriteImportMode.Polygon)
            {
                // If the texture importer is a Sprite of primitive, use the sprite inspector for generating preview/icon.
                if (subAssets.Length > 0)
                {
                    Sprite sprite = subAssets[0] as Sprite;
                    if (sprite)
                    {
                        return(SpriteInspector.BuildPreviewTexture(sprite, null, true));
                    }
                }
                else
                {
                    return(null);
                }
            }

            PreviewHelpers.AdjustWidthAndHeightForStaticPreview(texture.width, texture.height, ref width, ref height);

            RenderTexture savedRT       = RenderTexture.active;
            Rect          savedViewport = ShaderUtil.rawViewportRect;

            var rt = texture as RenderTexture;

            if (rt != null)
            {
                rt.Create(); // Ensure RT is created. Otherwise the first attempted Blit will end up binding a dummy 2D Texture where it expects a 2D Texture Array. (validation errors observed on Vulkan/Metal)
            }

            RenderTexture tmp = RenderTexture.GetTemporary(
                width, height,
                0,
                SystemInfo.GetGraphicsFormat(DefaultFormat.LDR));
            Material mat = EditorGUI.GetMaterialForSpecialTexture(texture, null, QualitySettings.activeColorSpace == ColorSpace.Linear, false);

            if (mat != null)
            {
                Graphics.Blit(texture, tmp, mat);
            }
            else
            {
                Graphics.Blit(texture, tmp);
            }

            RenderTexture.active = tmp;
            Texture2D copy;
            Texture2D tex2d = target as Texture2D;

            if (tex2d != null && tex2d.alphaIsTransparency)
            {
                copy = new Texture2D(width, height, TextureFormat.RGBA32, false);
            }
            else
            {
                copy = new Texture2D(width, height, TextureFormat.RGB24, false);
            }
            copy.ReadPixels(new Rect(0, 0, width, height), 0, 0);
            copy.Apply();
            RenderTexture.ReleaseTemporary(tmp);

            EditorGUIUtility.SetRenderTextureNoViewport(savedRT);
            ShaderUtil.rawViewportRect = savedViewport;

            return(copy);
        }
Пример #7
0
        private static Texture2D BuildPreviewTexture(int width, int height, Sprite sprite, Material spriteRendererMaterial)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }
            float     width2        = sprite.rect.width;
            float     height2       = sprite.rect.height;
            Texture2D spriteTexture = UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(sprite, false);

            PreviewHelpers.AdjustWidthAndHeightForStaticPreview((int)width2, (int)height2, ref width, ref height);
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(true);
            SavedRenderTargetState savedRenderTargetState = new SavedRenderTargetState();
            RenderTexture          temporary = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default);

            RenderTexture.active = temporary;
            GL.sRGBWrite         = (QualitySettings.activeColorSpace == ColorSpace.Linear);
            GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
            Texture texture = null;
            Vector4 vector  = new Vector4(0f, 0f, 0f, 0f);
            bool    flag    = false;
            bool    flag2   = false;

            if (spriteRendererMaterial != null)
            {
                flag  = spriteRendererMaterial.HasProperty("_MainTex");
                flag2 = spriteRendererMaterial.HasProperty("_MainTex_TexelSize");
            }
            Material material = null;

            if (spriteRendererMaterial != null)
            {
                if (flag)
                {
                    texture = spriteRendererMaterial.GetTexture("_MainTex");
                    spriteRendererMaterial.SetTexture("_MainTex", spriteTexture);
                }
                if (flag2)
                {
                    vector = spriteRendererMaterial.GetVector("_MainTex_TexelSize");
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", TextureUtil.GetTexelSizeVector(spriteTexture));
                }
                spriteRendererMaterial.SetPass(0);
            }
            else
            {
                material             = new Material(Shader.Find("Hidden/BlitCopy"));
                material.mainTexture = spriteTexture;
                material.SetPass(0);
            }
            float num = sprite.rect.width / sprite.bounds.size.x;

            Vector2[] vertices  = sprite.vertices;
            Vector2[] uv        = sprite.uv;
            ushort[]  triangles = sprite.triangles;
            Vector2   pivot     = sprite.pivot;

            GL.PushMatrix();
            GL.LoadOrtho();
            GL.Color(new Color(1f, 1f, 1f, 1f));
            GL.Begin(4);
            for (int i = 0; i < sprite.triangles.Length; i++)
            {
                ushort  num2    = triangles[i];
                Vector2 vector2 = vertices[(int)num2];
                Vector2 vector3 = uv[(int)num2];
                GL.TexCoord(new Vector3(vector3.x, vector3.y, 0f));
                GL.Vertex3((vector2.x * num + pivot.x) / width2, (vector2.y * num + pivot.y) / height2, 0f);
            }
            GL.End();
            GL.PopMatrix();
            GL.sRGBWrite = false;
            if (spriteRendererMaterial != null)
            {
                if (flag)
                {
                    spriteRendererMaterial.SetTexture("_MainTex", texture);
                }
                if (flag2)
                {
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", vector);
                }
            }
            Texture2D texture2D = new Texture2D(width, height, TextureFormat.ARGB32, false);

            texture2D.hideFlags = HideFlags.HideAndDontSave;
            texture2D.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
            texture2D.Apply();
            RenderTexture.ReleaseTemporary(temporary);
            savedRenderTargetState.Restore();
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(false);
            if (material != null)
            {
                UnityEngine.Object.DestroyImmediate(material);
            }
            return(texture2D);
        }