Version: 2020.1
public void ShowUtility ();

描述

将 EditorWindow 显示为浮动实用程序窗口。

当实用程序窗口失去焦点时,它仍然位于新活动窗口的顶部。这意味着, Unity 编辑器永远不会隐藏 EditorWindow.ShowUtility 窗口。但是,该窗口不能 停靠到编辑器。

实用程序窗口将始终位于正常 Unity 窗口前方。该窗口会 在用户从 Unity 切换到其他应用程序时隐藏起来。

注意:在使用此函数显示窗口之前,无需使用 EditorWindow.GetWindow

\ 允许您随机设置选定对象的旋转的浮动窗口实用程序。

using UnityEditor;
using UnityEngine;
using System.Collections;

// Simple script that randomizes the rotation of the selected GameObjects. // It also lists which objects are currently selected.

public class RandomizeInSelection : EditorWindow { public float rotationAmount = 0.33f; public string selected = "";

[MenuItem("Example/Randomize Children In Selection")] static void RandomizeWindow() { RandomizeInSelection window = ScriptableObject.CreateInstance(typeof(RandomizeInSelection)) as RandomizeInSelection; window.ShowUtility(); }

void RandomizeSelected() { foreach (var transform in Selection.transforms) { Quaternion rotation = Random.rotation; transform.localRotation = Quaternion.Slerp(transform.localRotation, rotation, rotationAmount); } }

void OnGUI() { foreach (var t in Selection.transforms) { selected += t.name + " "; }

EditorGUILayout.LabelField("Selected Object:", selected); selected = "";

if (GUILayout.Button("Randomize!")) RandomizeSelected();

if (GUILayout.Button("Close")) Close(); }

void OnInspectorUpdate() { Repaint(); } }