GUILayout.MaxWidth 最大宽度

static function MaxWidth (MaxWidth : float) : GUILayoutOption

Description描述

Option passed to a control to specify a maximum width.

传递给控件指定一个最大宽度的选项。

GUILayout.MaxWidth 最大宽度

Maximum allowed width for a window.
用于窗口允许的最大宽度。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	private Rect windowRect = new Rect(10, 10, 100, 100);
	private bool scaling = false;
	void OnGUI() {
		windowRect = GUILayout.Window(0, windowRect, ScalingWindow, "resizeable", GUILayout.MinWidth(80), GUILayout.MaxWidth(200));
	}
	void ScalingWindow(int windowID) {
		GUILayout.Box("", GUILayout.Width(20), GUILayout.Height(20));
		if (Event.current.type == EventType.MouseUp)
			scaling = false;
		else
			if (Event.current.type == EventType.MouseDown && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
				scaling = true;

		if (scaling)
			windowRect = new Rect(windowRect.x, windowRect.y, windowRect.width + Event.current.delta.x, windowRect.height + Event.current.delta.y);

	}
}
// Draws a window you can resize between 80px and 200px width
// Just click the box inside the window and move your mouse
//绘制一个窗口你可以在80px~200px宽度之间调整大小,仅在窗口中box上点击拖动鼠标
private var windowRect : Rect = Rect (10, 10, 100, 100);
private var scaling : boolean = false;

function OnGUI () {
	windowRect = GUILayout.Window (0, windowRect, ScalingWindow, "resizeable",
	GUILayout.MinWidth(80), GUILayout.MaxWidth(200));
}

function ScalingWindow (windowID : int) {
	GUILayout.Box("", GUILayout.Width(20), GUILayout.Height(20));
	if (Event.current.type == EventType.MouseUp) {
		scaling = false;
	}
	else if (Event.current.type == EventType.MouseDown &&
	GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) {
		scaling = true;
	}

	if (scaling) {
		windowRect = Rect (windowRect.x, windowRect.y,
		windowRect.width + Event.current.delta.x, windowRect.height + Event.current.delta.y);
	}
}
最后修改:2011年6月14日 Tuesday 15:02

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。