Created
April 26, 2014 19:09
-
-
Save keiranlovett/11328319 to your computer and use it in GitHub Desktop.
Unity: Recorder
This file contains hidden or 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 UnityEditor; | |
public class Recorder : EditorWindow { | |
string myString = "FileNameHere"; | |
string status = "Idle"; | |
string recordButton = "Record"; | |
int state = 0; | |
int fps = 24; | |
int[] fpsOptions = new int[] {12,24,30,60}; | |
string[] disOptions = new string[] {"12","24","30","60"}; | |
float lastFrameTime = 0.0f; | |
int imageIncrement = 0; | |
bool recordVideo = false; | |
// Add menu named "My Window" to the Window menu | |
[MenuItem ("Window/Recorder")] | |
static void Init () { | |
// Get existing open window or if none, make a new one: | |
Recorder window = (Recorder)EditorWindow.GetWindow (typeof (Recorder)); | |
window.Show (); | |
} | |
void OnGUI () { | |
GUILayout.Label ("Recorder", EditorStyles.boldLabel); | |
myString = EditorGUILayout.TextField ("File Name:", myString); | |
fps = EditorGUILayout.IntPopup(fps, disOptions, fpsOptions); | |
if(state == 0) { // idle | |
if(GUILayout.Button(recordButton)) | |
{ | |
imageIncrement = 0; | |
recordVideo = true; | |
recordButton = "Stop"; | |
state = 1; | |
} | |
} | |
if(state == 1) { // recording | |
if(GUILayout.Button(recordButton)) | |
{ | |
status = "Idle"; | |
recordButton = "Record"; | |
recordVideo = false; | |
state = 0; | |
} | |
} | |
GUILayout.Label (status, EditorStyles.boldLabel); | |
//myString = EditorGUILayout.TextField ("Text Field", myString); | |
//groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled); | |
//myBool = EditorGUILayout.Toggle ("Toggle", myBool); | |
//myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3); | |
//EditorGUILayout.EndToggleGroup (); | |
} | |
void Update () { | |
if (recordVideo == true && EditorApplication.isPlaying){ | |
RecordImages(); | |
Repaint(); | |
} else if (recordVideo == true && !EditorApplication.isPlaying) { | |
status = "Waiting for Editor to Play"; | |
} | |
} | |
void RecordImages() | |
{ | |
if(lastFrameTime < Time.time + (1/fps)) { | |
status = "Recording In Progress: Image_"+myString+ "_" + imageIncrement; | |
Application.CaptureScreenshot(myString + "_" + imageIncrement + ".png",4); | |
imageIncrement++; | |
lastFrameTime = Time.time; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment