返回介绍

GUIStyle.CalcSize 计算大小

发布于 2019-12-18 15:37:48 字数 3629 浏览 1176 评论 0 收藏 0

JavaScript => public function CalcSize(content: GUIContent): Vector2;
C# => public Vector2 CalcSize(GUIContent content);

Parameters 参数

Description 描述

Calculate the size of a some content if it is rendered with this style.

计算该样式渲染的一些内容的大小。

This function does not take wordwrapping into account. To do that, you need to determine the allocated width and then call CalcHeight to figure out the wordwrapped height.

这个函数不考虑自动换行。为此,以需要确定以分配宽度,然后调用CalcHeight去计算已换行的高度。

JavaScript:

// Simple custom editor that when any SimpleExampleScript
	// is detected in the inspector, it shows it as an IntSlider
	// and a GUILayouted bar.
 
	@CustomEditor(SimpleExampleScript)
	class CustomEditorExample extends Editor {
 
		function OnInspectorGUI() {
			// Get the place of the next available position in the script
			target.damage = EditorGUILayout.IntSlider("Damage:",target.damage,1,100);
			ProgressBar (target.damage / 100.0, "Damage");
 
			target.armor = EditorGUILayout.IntSlider("Armor:",target.armor,1,100);
			ProgressBar (target.armor / 100.0, "Armor");
 
		}
 
		// Custom GUILayout progress bar.
		function ProgressBar (value : float, label : String) {
			var size : Vector2 = GUI.skin.GetStyle("ProgressBarText").CalcSize(GUIContent(label));
			var rect : Rect = GUILayoutUtility.GetRect (size.x, Mathf.Max(size.y));
			rect = Rect(rect.x + 4, rect.y, rect.width -8, rect.height);
			EditorGUI.ProgressBar (rect, value, label);
			EditorGUILayout.Space();
		}
	}

And the script attached to this editor script:

JavaScript:

// SimpleExampleScript.js
	// This is not an editor script.
 
	var armor : int = 75;
	var damage : int = 25;

C#:

	// Simple custom editor that when any SimpleExampleScript
	// is detected in the inspector, it shows it as an IntSlider
	// and a GUILayouted bar.
 
	@CustomEditor(SimpleExampleScript)
	class CustomEditorExample extends Editor {
 
		function OnInspectorGUI() {
			// Get the place of the next available position in the script
			target.damage = EditorGUILayout.IntSlider("Damage:",target.damage,1,100);
			ProgressBar (target.damage / 100.0, "Damage");
 
			target.armor = EditorGUILayout.IntSlider("Armor:",target.armor,1,100);
			ProgressBar (target.armor / 100.0, "Armor");
 
		}
 
		// Custom GUILayout progress bar.
		function ProgressBar (value : float, label : String) {
			var size : Vector2 = GUI.skin.GetStyle("ProgressBarText").CalcSize(GUIContent(label));
			var rect : Rect = GUILayoutUtility.GetRect (size.x, Mathf.Max(size.y));
			rect = Rect(rect.x + 4, rect.y, rect.width -8, rect.height);
			EditorGUI.ProgressBar (rect, value, label);
			EditorGUILayout.Space();
		}
	}

And the script attached to this editor script:

C#:

// SimpleExampleScript.js
	// This is not an editor script.
 
	var armor : int = 75;
	var damage : int = 25;

guistyle

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文