CameraCapture.cs 1.38 KB
	/*************************************************
 * @Author: Icaro Magalhaes
 *************************************************/
using UnityEngine;
using System;
using System.Threading;

public class CameraCapture : MonoBehaviour{
	
	// The folder we place all screenshots inside.
	// If the folder exists we will append numbers to create an empty folder.
	public string folder;
	public int frameRate = 30;
	public int sizeMultiplier = 1;
	string[] strArg;
	bool beginning = true;
	
	void Start( ){
		Debug.Log ("Folders can be found inside "+Application.persistentDataPath);
		strArg = Environment.GetCommandLineArgs();
		folder = strArg[1];

		/*if( strArg.Length == 4 ) frameRate = int.Parse(strArg[3]);*/

		Debug.Log ("Folders can be found inside "+Application.persistentDataPath);

		// Set the playback framerate!
		// (real time doesn't influence time anymore)
		Time.captureFramerate = frameRate;
		
		// Find a folder that doesn't exist yet by appending numbers!
		//realFolder = folder;

		// Create the folder
		System.IO.Directory.CreateDirectory(Application.persistentDataPath+"/"+folder);
		folder = Application.persistentDataPath+"/"+folder;
	} // Start

	void Update( ){
		if (beginning) {
			beginning = false;
			Thread.Sleep(500);
		}
		else {
			var name = string.Format("{0}/frame_{1}.png", folder, Time.frameCount);
			Application.CaptureScreenshot(name, sizeMultiplier);
		}
	}
} // class