Unity Tips (#2)

使用 ContextMenu Attribute 不运行 Unity, 执行 MonoBehavior 函数 示例代码如下:

[ContextMenu("ResizeDialogueText")]
private void ResizeDialogueTextHeight()
{
	var height = dialogueText.preferredHeight;
	var size = dialogueBgRect.sizeDelta;
	size.y = height + 60f;
	dialogueBgRect.sizeDelta = size;

	var pos = dialogueText.transform.localPosition;
	pos.y = height + 30f;
	dialogueText.transform.localPosition = pos;
}

Diagram

–EOF–

王在京同学 /
Published under (CC) BY-NC-SA in categories Unity3d Tips  tagged with Unity3d