繁体   English   中英

如何将EditorWindow设置在屏幕中央?

[英]How can I set EditorWindow to be in the center of the screen?

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Prefab : EditorWindow
{
    [SerializeField] private GameObject prefab;
    List<Transform> transformSelection = new List<Transform>();
    int transformsCount = 0;

    [MenuItem("Tools/Prefab")]
    static void CreatePrefab()
    {
        EditorWindow.GetWindow<Prefab>();
        //GetWindow<Prefab>().position = new Rect(980, 380, 322, 278);
        GetWindow<Prefab>().position = new Rect(Screen.width / 2, Screen.height / 2, 322, 278);
    }

这会将窗口按宽度居中放置,但位于屏幕顶部。

编辑器窗口

我不确定宽度是否在中间。 但是高度在最上面。

白色的大矩形是窗口。

工作解决方案:

    int width = 322;
    int height = 278;
    int x = (Screen.currentResolution.width - width) / 2;
    int y = (Screen.currentResolution.height - height) / 2;

    GetWindow<Prefab>().position = new Rect(x, y, width, height);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM