I am getting the error "Operation is not valid due to the current state of the object System.Collections.Stack.Peek ()" while building and animating a GUI accordion for smooth moviment using scrollview. What could be happening?
Thanks in advance.
Here is the Code:
void OnGUI()
{
GUISkin skin = GUI.skin;
GUI.skin = sknScrollbar;
if (this.Display)
{
GUILayout.BeginArea(this.rtComponentPosition);
vtScroll = GUILayout.BeginScrollView(vtScroll, GUILayout.Height(Screen.height - rtComponentPosition.yMin), GUILayout.Width(this.rtComponentPosition.width));
ListChilds(root.childs);
GUILayout.EndScrollView();
GUILayout.EndArea();
}
GUI.skin = skin;
}
void ListChilds(IList<Item> childs)
{
foreach (Item item in childs)
{
item.scrollHeight = getScrollSize(item);
if (item.Nome == "PINTAR" || item.Nome == "DECORAR")
{
accordionSize = 29;
}
else
accordionSize = 25;
if (item.Nome == currentItem)
{
GUILayout.BeginScrollView(new Vector2(), GUILayout.Height(accordionHeight));
if (item.isOpened && !item.closening && accordionHeight < accordionSize * (1 + item.childs.Count))
{
accordionHeight += 2;
}
if (item.closening == true && accordionHeight > 29)
{
accordionHeight -= 2;
}
if (item.closening == true && accordionHeight <= 29)
{
item.isOpened = false;
item.closening = false;
}
}
if (GUILayout.Button(item.Nome, item.style))
{
if (item.isOpened == false)
{
item.isOpened = true;
}
else
{
item.closening = true;
}
item.SetClick();
}
if ((item.childs != null) && (item.isOpened))
ListChilds(item.childs);
if (item.Nome == currentItem)
{
GUILayout.EndScrollView();
}
}