- Home /
Question by
Lina.Inverse · Dec 05, 2011 at 10:49 PM ·
rendertextureeditorwindowscreenshotgizmos
How can i make Screenshots with Gizmos?
Hello Guys,
i found a script here to take a HiResScreenshots from the Camera as a RenderTexture. This works fine in Editor-Mode too. I changed the script from a MonoBehaviour to a standard class, to use this as a GUILayout.Button-Function.
My problem is i need the Gizmos in the Screenshot! Unity allows you to show/hide the Gizmos in the Game-View via "Gizmos"-toggle button. How can i modify the script to render Gizmos to the RenderTexture, too?
using UnityEngine;
using System.Collections;
public class HiResScreenShots {
private int resWidth = 4096;
private int resHeight = 4096;
private string screenshotPath = Application.dataPath;
private string screenshotNamePrefix = "screen";
private UnityEngine.Camera cameraObject = null;
public HiResScreenShots(int _width, int _height, UnityEngine.Camera _cameraObject, string _screenshotPath, string _screenshotNamePrefix) {
this.resWidth = _width;
this.resHeight = _height;
this.cameraObject = _cameraObject;
this.screenshotPath = _screenshotPath;
this.screenshotNamePrefix = _screenshotNamePrefix;
}
private static string ScreenshotName(string screenshotPath, string screenshotNamePrefix, int width, int height) {
return string.Format("{0}/{1}_{2}x{3}_{4}.png",
screenshotPath,
screenshotNamePrefix,
width, height,
System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
}
public void TakeScreenshot()
{
if (cameraObject != null) {
RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
cameraObject.targetTexture = rt;
Texture2D screenshot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);
cameraObject.Render();
RenderTexture.active = rt;
screenshot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
cameraObject.targetTexture = null;
RenderTexture.active = null;
byte[] bytes = screenshot.EncodeToPNG();
string filename = ScreenshotName(screenshotPath, screenshotNamePrefix, resWidth, resHeight);
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("HiResScreenShot: Took screenshot to: {0}", filename));
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Screenshot in Webplayer with Antialiasing 0 Answers
Problem with screenshot on render texture 0 Answers
Using Handles in EditorWindow 0 Answers
Capture Screenshots in a Row 0 Answers
[Solved] Take a Screenshot from game and use it immediately in UI 1 Answer