Skip to content

Instantly share code, notes, and snippets.

@KensukeSakakibara
Forked from keijiro/ScreenRecorder.cs
Last active May 1, 2019 06:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KensukeSakakibara/6987fd6a7c707db7a0596f703276f3a4 to your computer and use it in GitHub Desktop.
Save KensukeSakakibara/6987fd6a7c707db7a0596f703276f3a4 to your computer and use it in GitHub Desktop.
Screen recording utility.
using UnityEngine;
using System.Collections;
public class ScreenRecorder : MonoBehaviour
{
public int framerate = 30;
public int superSize;
public bool autoRecord;
int frameCount;
bool recording;
void Start ()
{
if (autoRecord) StartRecording ();
}
void StartRecording ()
{
System.IO.Directory.CreateDirectory ("Capture");
Time.captureFramerate = framerate;
frameCount = -1;
recording = true;
}
void Update ()
{
if (recording)
{
if (Input.GetMouseButtonDown (0))
{
recording = false;
enabled = false;
}
else
{
if (frameCount > 0)
{
var name = "Capture/frame" + frameCount.ToString ("0000") + ".png";
ScreenCapture.CaptureScreenshot (name, superSize);
}
frameCount++;
if (frameCount > 0 && frameCount % 60 == 0)
{
Debug.Log ((frameCount / 60).ToString() + " seconds elapsed.");
}
}
}
}
void OnGUI ()
{
if (!recording && GUI.Button (new Rect (0, 0, 200, 50), "Start Recording"))
{
StartRecording ();
Debug.Log ("Click Game View to stop recording.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment