void RebuildContent() { var contentRect = Content.rectTransform; int childCount = contentRect.childCount; int childIndex = 0; int itemIndex = 0; int itemCount = items.Count; selectedItem = null; while (childIndex < childCount && itemIndex < itemCount) { var child = contentRect.GetChild(childIndex); var itemView = child.GetComponent <TreeItemView>(); itemView.Item(items[itemIndex], itemIndex); ++childIndex; ++itemIndex; } while (childIndex < childCount) { var go = contentRect.GetChild(childIndex++).gameObject; Destroy(go); } while (itemIndex < itemCount) { Content .Add <TreeItemView>() .Item(items[itemIndex], itemIndex) .OnStateChanged((int i, bool o) => onStateChanged.Invoke(i, o)) .OnClick((int i) => onClick.Invoke(i)) .FlexibleLayout(true, false) .Finish(); ++itemIndex; } }
public TreeView SelectItem(int index) { var contentRect = Content.rectTransform; int childCount = contentRect.childCount; if (selectedItem != null) { selectedItem.OnDeselect(); } if (index >= 0 && index < childCount) { var child = contentRect.GetChild(index); selectedItem = child.GetComponent <TreeItemView>(); selectedItem.OnSelect(); } return(this); }