UnityEditor.PreviewRenderUtility.EndStaticPreview C# (CSharp) Method

EndStaticPreview() public method

public EndStaticPreview ( ) : Texture2D
return UnityEngine.Texture2D
        public Texture2D EndStaticPreview()
        {
            RenderTexture dest = RenderTexture.GetTemporary((int) this.m_TargetRect.width, (int) this.m_TargetRect.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
            GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;
            Graphics.Blit(this.m_RenderTexture, dest);
            GL.sRGBWrite = false;
            RenderTexture.active = dest;
            Texture2D textured = new Texture2D((int) this.m_TargetRect.width, (int) this.m_TargetRect.height, TextureFormat.RGB24, false, true);
            textured.ReadPixels(new Rect(0f, 0f, this.m_TargetRect.width, this.m_TargetRect.height), 0, 0);
            textured.Apply();
            RenderTexture.ReleaseTemporary(dest);
            this.m_SavedState.Restore();
            return textured;
        }

Usage Example

示例#1
0
        public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
        {
            AudioClip clip = target as AudioClip;

            AssetImporter importer      = AssetImporter.GetAtPath(assetPath);
            AudioImporter audioImporter = importer as AudioImporter;

            if (audioImporter == null || !ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }

            if (m_PreviewUtility == null)
            {
                m_PreviewUtility = new PreviewRenderUtility();
            }

            m_PreviewUtility.BeginStaticPreview(new Rect(0, 0, width, height));

            // We're drawing into an offscreen here which will have a resolution defined by EditorGUIUtility.pixelsPerPoint. This is different from the DoRenderPreview call below where we draw directly to the screen, so we need to take
            // the higher resolution into account when drawing into the offscreen, otherwise only the upper-left quarter of the preview texture will be drawn.
            DoRenderPreview(clip, audioImporter, new Rect(0.05f * width * EditorGUIUtility.pixelsPerPoint, 0.05f * width * EditorGUIUtility.pixelsPerPoint, 1.9f * width * EditorGUIUtility.pixelsPerPoint, 1.9f * height * EditorGUIUtility.pixelsPerPoint), 1.0f);

            return(m_PreviewUtility.EndStaticPreview());
        }
All Usage Examples Of UnityEditor.PreviewRenderUtility::EndStaticPreview