版本: Unity 6 (6000.0)
语言英语
  • C#

EditorWindow.OnGUI()

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交的内容,但我们确实阅读了用户提出的每项更改建议,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您的更改建议无法提交。请在几分钟后 <a>重试</a>。感谢您花时间帮助我们提高 Unity 文档的质量。

关闭

取消

描述

在此实现您自己的编辑器 GUI。


使用 OnGUI 绘制窗口的所有控件。

// 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; } } }