Last active
January 26, 2022 05:01
-
-
Save keijiro/7429201 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"; | |
Application.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
Application.CaptureScreenshot is already removed since unity 2017.
To use ScreenCapture.CaptureScreenshot is good.
https://gist.github.com/KensukeSakakibara/6987fd6a7c707db7a0596f703276f3a4