Last active
August 29, 2015 14:17
-
-
Save griv/313edf139609443a40c1 to your computer and use it in GitHub Desktop.
Renders Unity Camera.main to png images.
This file contains 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 UnityEngine; | |
using System.Collections; | |
using System; | |
public class SaveFrames : MonoBehaviour { | |
public bool saveFrames = false; | |
public bool saveFrameHotKey = false; | |
public string folderPrefix = "frames_out"; | |
public int frameRate = 25; | |
public int frameSizeMultiplier = 1; | |
private string nowTime; | |
private string fullFolderName; | |
void Start() { | |
nowTime = String.Format("{0:yyyyMMdd_HHmmss}", DateTime.Now); | |
fullFolderName = String.Format("{0}_{1}", folderPrefix, nowTime); | |
Time.captureFramerate = frameRate; | |
System.IO.Directory.CreateDirectory(fullFolderName); | |
} | |
void LateUpdate() { | |
if (saveFrames || (saveFrameHotKey && Input.GetKey(KeyCode.S))) { | |
string name = String.Format("{0}/frame_{1:D04}.png", fullFolderName, Time.frameCount); | |
Application.CaptureScreenshot(name, frameSizeMultiplier); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment