如何将EditorWindow的大小调整为20的高度?

时间:2018-09-23 21:36:58

标签: c# unity3d

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor.IMGUI.Controls;
using UnityEditor.SceneManagement;


    public class Prefab : EditorWindow
    {
        private bool stop;
        private bool minimizeToZero;
        private static Prefab editor;
        private static int width = 300;
        private static int height = 100;
        private static int x = 0;
        private static int y = 0;

        [MenuItem("Window/Test")]
        static void ShowEditor()
        {


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

            editor = EditorWindow.GetWindow<Prefab>();

            editor.position = new Rect(x, y, width, height);
            //editor.minSize = new Vector2(width, height);
            editor.maxSize = new Vector2(width, height);

            editor.Init();
        }
    }

然后在OnGUI中添加一些标签,然后检查窗口大小和位置是否已更改:

void OnGUI()
        {
            GUILayout.Label("Testing now");
            minimizeToZero = GUILayout.Toggle(minimizeToZero, "Minimize To Zero");
            stop = GUILayout.Toggle(stop, "Stop");
            GUILayout.Space(10);

            if(minimizeToZero)
            {
                editor = null;
                Prefab editor1 = (PrefabReplace)EditorWindow.GetWindow(typeof(Prefab), true, "My Empty Window");
                x = (Screen.currentResolution.width / 2);
                y = (Screen.currentResolution.height * 4 );// - height - height / 2);
                width = 300;
                height = 20;
                editor1.position = new Rect(x, 0, width, height);

            }
            else
            {
                editor = EditorWindow.GetWindow<Prefab>();
                x = (Screen.currentResolution.width - width) / 2;
                y = (Screen.currentResolution.height - height) / 2;
                width = 300;
                height = 100;
                editor.position = new Rect(x, y, width, height);
            }
        }

当我最小化窗口时,在OnGUI内部,我希望它移动到中间宽度的顶部高度。宽度300高度20

但是它没有改变。我想我不能将窗口大小更改为小于标签内的东西。因此,我尝试创建一个新的空白窗口进行测试,尝试使用editor = null,然后尝试使用editor1,但是什么也没有。它没有创建新的空窗口,也没有调整其大小。

主要目标不是创建一个新的空窗口,而是以某种方式调整窗口大小和移动窗口。可以移动,但调整大小后无法将高度设为20。

0 个答案:

没有答案