要将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);
}
private void OnGUI()
{
// 在这里绘制窗口的内容
}
}
这样,当打开该EditorWindow时,它将在屏幕中心显示。希望这个答案对你有帮助!如果你想了解更多关于Unity的开发和云计算的知识,可以参考腾讯云的云游戏解决方案:腾讯云游戏解决方案。
领取专属 10元无门槛券
手把手带您无忧上云