CameraCapture.cs 1.02 KB
using UnityEngine;
using System;
using System.Threading;

public class CameraCapture : MonoBehaviour
{
	public static bool capture = false;

	// The folder we place all screenshots inside.
	// If the folder exists we will append numbers to create an empty folder.
	public string folder = "ScreenCaptures";
	public static int frameRate = 30;
	public int sizeMultiplier = 1;
	//string[] strArg;
	public static int frameNumber = 0;

	void Start()
	{
		string[] strArg = Environment.GetCommandLineArgs();

		if (strArg.Length >= 2)
			folder = strArg[1];

		// Create the folder
		folder = Application.persistentDataPath + "/" + folder;
		System.IO.Directory.CreateDirectory(folder);
		Debug.Log("ScreenCaptures to " + folder);

		if (strArg.Length >= 4)
			frameRate = int.Parse(strArg[3]);
		
		Time.captureFramerate = frameRate;
	}

	void Update()
	{
		if (capture)
		{
			var name = string.Format("{0}/frame_{1}.png", folder, frameNumber++); // Time.frameCount);
			Application.CaptureScreenshot(name, sizeMultiplier);
		}
	}

} // class