要将EditorWindow设置为屏幕中心,可以按照以下步骤进行操作:
int screenWidth = Screen.width; int screenHeight = Screen.height;
int windowWidth = 400; // 窗口的宽度 int windowHeight = 300; // 窗口的高度 int windowX = (screenWidth - windowWidth) / 2; // 窗口的X坐标 int windowY = (screenHeight - windowHeight) / 2; // 窗口的Y坐标 this.position = new Rect(windowX, windowY, windowWidth, windowHeight);
using UnityEditor; using UnityEngine; public class MyEditorWindow : EditorWindow [MenuItem("Window/My Editor Window")] public static void ShowWindow() EditorWindow.GetWindow(typeof(MyEditorWindow)); private void OnEnable() int screenWidth = Screen.width; int screenHeight = Screen.height; int windowWidth = 400; // 窗口的宽度 int windowHeight = 300; // 窗口的高度 int windowX = (screenWidth - windowWidth) / 2; // 窗口的X坐标 int windowY = (screenHeight - windowHeight) / 2; // 窗口的Y坐标 this.position = new Rect(windowX, windowY, windowWidth, windowHeight);