public void NextElement <TType>(out TType widget) where TType : VisualElement, IOnGUIHandler, new() { Type typeFromHandle = typeof(TType); widget = (TType)((object)null); if (this.m_CurrentViewState.childIndex >= this.m_CurrentContainer.childrenCount) { TType arg_51_1; if ((arg_51_1 = this.m_ElementPool.TryReuse <TType>()) == null) { arg_51_1 = Activator.CreateInstance <TType>(); } widget = arg_51_1; this.m_CurrentContainer.AddChild(widget); } else { VisualElement childAt = this.m_CurrentContainer.GetChildAt(this.m_CurrentViewState.childIndex); if (childAt.GetType() == typeFromHandle) { widget = (childAt as TType); } else { IOnGUIHandler onGUIHandler = childAt as IOnGUIHandler; if (onGUIHandler != null && onGUIHandler.id == 0 && !(onGUIHandler is VisualContainer)) { this.m_CurrentContainer.RemoveChildAt(this.m_CurrentViewState.childIndex); this.m_ElementPool.Trash(onGUIHandler); this.NextElement <TType>(out widget); return; } TType arg_11E_1; if ((arg_11E_1 = this.m_ElementPool.TryReuse <TType>()) == null) { arg_11E_1 = Activator.CreateInstance <TType>(); } widget = arg_11E_1; this.m_CurrentContainer.InsertChild(this.m_CurrentViewState.childIndex, widget); } } Debug.Assert(widget != null); this.m_CurrentViewState = new VisualTreeBuilder.ViewState(this.m_CurrentViewState.childIndex + 1); }
private void RecycleDescendants(VisualContainer parent, int startAtIndex) { while (parent.childrenCount > startAtIndex) { VisualElement childAt = parent.GetChildAt(startAtIndex); VisualContainer visualContainer = childAt as VisualContainer; if (visualContainer != null) { this.RecycleDescendants(visualContainer, 0); } IOnGUIHandler onGUIHandler = childAt as IOnGUIHandler; if (onGUIHandler != null) { this.m_ElementPool.Trash(onGUIHandler); parent.RemoveChild(childAt); } else { startAtIndex++; } } }