将 EditorWindow 显示为浮动实用程序窗口。
当实用程序窗口失去焦点时,它仍然位于新活动窗口的顶部。这意味着,
Unity 编辑器永远不会隐藏 EditorWindow.ShowUtility 窗口。但是,该窗口不能
停靠到编辑器。
实用程序窗口将始终位于正常 Unity 窗口前方。该窗口会
在用户从 Unity 切换到其他应用程序时隐藏起来。
**注意**:在使用此函数显示窗口之前,无需使用 EditorWindow.GetWindow。
// Simple script that randomizes the rotation of the selected GameObjects. using UnityEditor; using UnityEngine; using UnityEngine.UIElements; public class RandomizeInSelectionShowUtility : EditorWindow { System.Random random = new System.Random(); public float rotationAmount; public string selected = ""; [MenuItem("Examples/Randomize Objects")] static void Init() { RandomizeInSelectionShowUtility window = EditorWindow.GetWindow<RandomizeInSelectionShowUtility>(true, "Randomize Objects"); window.ShowUtility(); } void CreateGUI() { var label = new Label("Selected an object and click Randomize!"); rootVisualElement.Add(label); var buttonRandomize = new Button(); buttonRandomize.text = "Randomize!"; buttonRandomize.clicked += () => RandomizeSelected(); rootVisualElement.Add(buttonRandomize); } void RandomizeSelected() { foreach (var transform in Selection.transforms) { Quaternion rotation = Random.rotation; rotationAmount = (float)random.NextDouble(); transform.localRotation = Quaternion.Slerp(transform.localRotation, rotation, rotationAmount); } } }