반응형






using UnityEngine; using UnityEditor;

public class SimpleRecorder : EditorWindow { string fileName = "FileName";

string status = "Idle"; string recordButton = "Record"; bool recording = false; float lastFrameTime = 0.0f; int capturedFrame = 0;

[MenuItem ("Example/Simple Recorder")]         //상단 메뉴 툴바에 Example 서브 메뉴로 Simple Recorder 메뉴가 생김 static void Init () { SimpleRecorder window = (SimpleRecorder)EditorWindow.GetWindow(typeof(SimpleRecorder)); }

void OnGUI () { fileName = EditorGUILayout.TextField ("File Name:", fileName);//File Name 레벨 과 파일명 얻어옴

if(GUILayout.Button(recordButton)) {                           //Record 버튼 생성 및 이벤트 가져옴

if(recording) { //recording status = "Idle..."; recordButton = "Record"; recording = false; } else { // idle capturedFrame = 0; recordButton = "Stop"; recording = true; } } EditorGUILayout.LabelField ("Status: ", status);             //Status: 라벨 추가 }

void Update () { if (recording) { if (EditorApplication.isPlaying && !EditorApplication.isPaused){ RecordImages(); Repaint();                                //에디터 custom window 에 변경 사항이 생길경우 다시 그려주는 작업 } else status = "Waiting for Editor to Play"; } }

void RecordImages() { if(lastFrameTime < Time.time + (1/24f)) { // 24fps status = "Captured frame " + capturedFrame; Application.CaptureScreenshot(fileName + " " + capturedFrame + ".png");        //현재 실행화면 캡쳐 capturedFrame++; lastFrameTime = Time.time; } } }

https://docs.unity3d.com/ScriptReference/EditorWindow.OnGUI.html

반응형

+ Recent posts