-
-
Save ktpttd/df5be103b99aad5d98df19bc0b9f2c5e to your computer and use it in GitHub Desktop.
Revisions
-
krzys-h renamed this gist
Jun 17, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ using UnityEngine; using UnityEditor; public class SaveScreenshotToFile { [MenuItem("Custom/Render Camera to file")] public static void RenderCameraToFile() { -
krzys-h revised this gist
Jun 17, 2022 . 1 changed file with 33 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ using UnityEngine; using UnityEditor; public class RenderCameraToFile { [MenuItem("Custom/Render Camera to file")] public static void RenderCameraToFile() { Camera camera = Selection.activeGameObject.GetComponent<Camera>(); RenderTexture rt = new RenderTexture(2560, 1440, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); RenderTexture oldRT = camera.targetTexture; camera.targetTexture = rt; camera.Render(); camera.targetTexture = oldRT; RenderTexture.active = rt; Texture2D tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); RenderTexture.active = null; byte[] bytes = tex.EncodeToPNG(); string path = "Assets/screenshot.png"; System.IO.File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path); Debug.Log("Saved to " + path); } [MenuItem("Custom/Render Camera to file", true)] public static bool RenderCameraToFileValidation() { return Selection.activeGameObject != null && Selection.activeGameObject.GetComponent<Camera>() != null; } } -
krzys-h created this gist
Jan 20, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ using UnityEngine; using UnityEditor; public class SaveRenderTextureToFile { [MenuItem("Assets/Save RenderTexture to file")] public static void SaveRTToFile() { RenderTexture rt = Selection.activeObject as RenderTexture; RenderTexture.active = rt; Texture2D tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); RenderTexture.active = null; byte[] bytes; bytes = tex.EncodeToPNG(); string path = AssetDatabase.GetAssetPath(rt) + ".png"; System.IO.File.WriteAllBytes(path, bytes); AssetDatabase.ImportAsset(path); Debug.Log("Saved to " + path); } [MenuItem("Assets/Save RenderTexture to file", true)] public static bool SaveRTToFileValidation() { return Selection.activeObject is RenderTexture; } }