Skip to content

Instantly share code, notes, and snippets.

@griv
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save griv/313edf139609443a40c1 to your computer and use it in GitHub Desktop.
Save griv/313edf139609443a40c1 to your computer and use it in GitHub Desktop.
Renders Unity Camera.main to png images.
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