Version: 2021.3

GUILayout.FlexibleSpace

切换到手册
public static void FlexibleSpace ();

描述

插入灵活的空白元素。

灵活的空白元素将占用布局中的任何剩余空间。

注意:这将覆盖 GUILayout.ExpandWidthGUILayout.ExpandHeight

\ GUILayout 区域中灵活的空白元素。

using UnityEngine;

public class ExampleScript : MonoBehaviour { float sliderValue = 1.0f;

void OnGUI() { // Wrap everything in the designated GUI Area GUILayout.BeginArea(new Rect(0, 0, 200, 60)); // Begin the singular Horizontal Group GUILayout.BeginHorizontal(); // Place a Button normally GUILayout.RepeatButton("A button with\ntwo lines"); // Place a space between the button and the vertical area // so it fits the whole area GUILayout.FlexibleSpace(); // Arrange two more Controls vertically beside the Button GUILayout.BeginVertical(); GUILayout.Box("Value:" + Mathf.Round(sliderValue)); sliderValue = GUILayout.HorizontalSlider(sliderValue, 0.0f, 10f);

// End the Groups and Area GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndArea(); } }