EndLayoutGroup: BeginLayoutGroup must be called first. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
时间: 2024-04-12 19:32:13 浏览: 251
根据你提供的错误信息,这个错误通常发生在使用Unity的GUI系统时,调用了不正确的布局组函数顺序。在使用GUILayout或GUI布局函数时,确保正确地按照BeginLayoutGroup和EndLayoutGroup的顺序进行调用。
以下是一个示例,展示了正确的GUILayout布局组函数的调用顺序:
```csharp
using UnityEngine;
using UnityEditor;
public class MyWindow : EditorWindow
{
private bool showButton = true;
[MenuItem("Window/My Window")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(MyWindow));
}
private void OnGUI()
{
EditorGUILayout.BeginVertical();
GUILayout.Label("My Window");
EditorGUILayout.BeginHorizontal();
GUILayout.Label("Toggle Button:");
showButton = GUILayout.Toggle(showButton, "Show");
EditorGUILayout.EndHorizontal();
if (showButton)
{
EditorGUILayout.BeginVertical(GUI.skin.box);
GUILayout.Button("Button 1");
GUILayout.Button("Button 2");
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndVertical();
}
}
```
请确保在GUILayout或GUI布局函数中正确地使用BeginLayoutGroup和EndLayoutGroup,并按照正确的顺序进行调用。如果你在代码中的其他地方使用了类似的布局函数,请检查是否存在类似的调用顺序错误。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)