Created
January 17, 2019 07:52
-
-
Save zxzsaga/6f7e67984930c7008fb4ed82d55759c1 to your computer and use it in GitHub Desktop.
RenderTexture output PNG.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.IO; | |
| using UnityEngine; | |
| using UnityEditor; | |
| public static class RenderTexture2PNGUtility { | |
| [MenuItem("Assets/RenderTexture2PNG", true)] | |
| private static bool RenderTexture2PNGValidation() { | |
| return Selection.activeObject is RenderTexture; | |
| } | |
| /// <summary> | |
| /// 将 RenderTexture 输出为 PNG | |
| /// </summary> | |
| [MenuItem("Assets/RenderTexture2PNG")] | |
| public static void RenderTexture2PNG() { | |
| RenderTexture rt = (RenderTexture)Selection.activeObject; | |
| string pngOutPath = "Assets/out.png"; | |
| var tex = new Texture2D(rt.width, rt.height); | |
| RenderTexture.active = rt; | |
| tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); | |
| tex.Apply(); | |
| File.WriteAllBytes(pngOutPath, tex.EncodeToPNG()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment