public Vector2 CalcSize (GUIContent content);

描述

计算某些内容的大小(使用该样式呈现时)。

该函数不考虑自动换行。要进行自动换行, 您需要确定分配的宽度,然后调用 CalcHeight 计算 执行自动换行后的高度。

// Example for the GUIStyle.CalcSize

using UnityEngine;

public class CalcSizeExample : MonoBehaviour { string s;

void Start() { s = "A string for GUIContent()"; }

void OnGUI() { GUIContent content = new GUIContent(s);

GUIStyle style = GUI.skin.box; style.alignment = TextAnchor.MiddleCenter;

// Compute how large the button needs to be. Vector2 size = style.CalcSize(content);

// make the Box double sized GUI.Box(new Rect(10.0f, 10.0f, 2.0f * size.x, 2.0f * size.y), s); } }