C# 更新OnGUI上的水平滚动视图

C# 更新OnGUI上的水平滚动视图,c#,unity3d,C#,Unity3d,我想做的事情是,当我单击onGUI按钮时,滚动视图viewRect y轴同时增加。这意味着,我想更新水平滚动视图。但是,我的代码不起作用。我该怎么办 private void OnGUI() { int subPartsSpacing=0; 浮动间距=30; 浮动x=7+间距; 浮动y=68; 浮动滚动视图_y=236; HumanBodyPart mainBodyPart=bodyVisualizer.BodyData.Body.SubParts[0]; List nextPartsToRen

我想做的事情是,当我单击onGUI按钮时,滚动视图viewRect y轴同时增加。这意味着,我想更新水平滚动视图。但是,我的代码不起作用。我该怎么办

private void OnGUI()
{
int subPartsSpacing=0;
浮动间距=30;
浮动x=7+间距;
浮动y=68;
浮动滚动视图_y=236;
HumanBodyPart mainBodyPart=bodyVisualizer.BodyData.Body.SubParts[0];
List nextPartsToRender=新列表(新HumanBodyPart[]{mainBodyPart});
而(nextPartsToRender.Count>0)
{
HumanBodyPart currentPart=nextPartsToRender[0];
下一个partstorender.RemoveAt(0);
scrollPosition=GUI.BeginScrollView(新Rect(7,68236426),scrollPosition,新Rect(7,68500,scrollview_y));
标签(新的Rect(currentPart.DrawDepth*间距+x+子部分间距,y,200,20),currentPart.EnglishTitle);
如果(currentPart.SubParts.Count!=0)
{
if(GUI.按钮(新矩形(x-间距+currentPart.DrawDepth*间距+子部分间距,y,20,20),“+”)
{
如果(!currentPart.IsExpanded)
{
currentPart.IsExpanded=true;
子部分间距+=20;
}
其他的
currentPart.IsExpanded=false;
}
如果(currentPart.IsExpanded)
{
//我猜是错的部分。。。
scrollview_y+=20*currentPart.SubParts.Count;
//
nextPartsToRender.InsertRange(0,currentPart.SubParts);
}
}
y+=间距;
}
//结束上面开始的滚动视图。
EndScrollView();
}

GUI错误:推送的GUI剪辑比弹出的多。确保它们是平衡的)

缩小到你正在做的重要事情

while (/*...*/)
{
    // ...
    scrollPosition = GUI.BeginScrollView(/*...*/);
    // ...
}
GUI.EndScrollView();
因此,在循环之后,可能会多次调用
BeginScrollView
,但只有一次调用
EndScrollView

因此,要么将它移动到
while
循环中,这样每次
BeginScrollView
调用都会调用它

while (/*...*/)
{
    // ...
    scrollPosition = GUI.BeginScrollView(/*...*/);
    // ...
    GUI.EndScrollView();
}
当然,也可以根据你们的需要将两者都搬出去

scrollPosition = GUI.BeginScrollView(/*...*/);
while (/*...*/)
{
    // ...
}
GUI.EndScrollView();

缩小到你正在做的重要事情

while (/*...*/)
{
    // ...
    scrollPosition = GUI.BeginScrollView(/*...*/);
    // ...
}
GUI.EndScrollView();
因此,在循环之后,可能会多次调用
BeginScrollView
,但只有一次调用
EndScrollView

因此,要么将它移动到
while
循环中,这样每次
BeginScrollView
调用都会调用它

while (/*...*/)
{
    // ...
    scrollPosition = GUI.BeginScrollView(/*...*/);
    // ...
    GUI.EndScrollView();
}
当然,也可以根据你们的需要将两者都搬出去

scrollPosition = GUI.BeginScrollView(/*...*/);
while (/*...*/)
{
    // ...
}
GUI.EndScrollView();

GUI已经贬值很久了(在编辑器之外),为什么不想使用UGUI scrollview?GUI已经贬值很久了(在编辑器之外),为什么不想使用UGUI scrollview?