Version: 2022.2

GroupScope

class in UnityEngine

切换到手册

描述

用于管理 BeginGroup/EndGroup 的可处置的 Helper 类。

BeginGroup 在构造时调用,EndGroup 在处置实例时调用。 当您开始组时,将设置 GUI 控件的坐标系 - (0,0) 为组的左上角。所有控件都被裁剪到组中。 组可以嵌套 - 当组嵌套时,子项将裁剪到其父项。

当在屏幕上移动一组 GUI 元素时,这非常有用。一个常见的用例是设计适合特定屏幕尺寸的菜单,然后将 GUI 放置在较大显示屏的中心位置。

using UnityEngine;

public class Example : MonoBehaviour { void OnGUI() { // Constrain all drawing to be within a 800x600 pixel area centered on the screen. using (var groupScope = new GUI.GroupScope(new Rect(Screen.width / 2 - 400, Screen.height / 2 - 300, 800, 600))) { // Draw a box in the new coordinate space defined by the BeginGroup. // Notice how (0,0) has now been moved on-screen. GUI.Box(new Rect(0, 0, 800, 600), "This box is now centered! - here you would put your main menu"); } // The group is now ended. } }

构造函数

GUI.GroupScope创建一个新的 GroupScope 并开始相应的组。