-
-
Save KensukeSakakibara/6987fd6a7c707db7a0596f703276f3a4 to your computer and use it in GitHub Desktop.
Screen recording utility.
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; | |
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