Version: 2022.3
言語: 日本語

説明

ここに独自のエディターの GUI を実装します


Use OnGUI to draw all the controls of your window.

// A simple script that saves frames from the Game view when in Play mode.
//
// You can put the frames together later to create a video.
// The frames are saved in the project, at the same level of the project hierarchy as the Assets folder.

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")] static void Init() { SimpleRecorder window = (SimpleRecorder)EditorWindow.GetWindow(typeof(SimpleRecorder)); }

void OnGUI() { fileName = EditorGUILayout.TextField("File Name:", fileName);

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

void Update() { if (recording) { if (EditorApplication.isPlaying && !EditorApplication.isPaused) { RecordImages(); Repaint(); } else status = "Waiting for Editor to Play"; } }

void RecordImages() { if (lastFrameTime < Time.time + (1 / 24f)) // 24fps { status = "Captured frame " + capturedFrame; ScreenCapture.CaptureScreenshot(fileName + " " + capturedFrame + ".png"); capturedFrame++; lastFrameTime = Time.time; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961