/// <summary> /// This method called for each data item during databinding operation /// You have to bind data item properties to ui elements in order to display them. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnItemDataBinding(object sender, TreeViewItemDataBindingArgs e) { GameObject dataItem = e.Item as GameObject; //TreeData dataItem = e.Item as TreeData; if (dataItem != null) { //We display dataItem.name using UI.Text Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = dataItem.name; //Load icon from resources Image icon = e.ItemPresenter.GetComponentsInChildren <Image>()[4]; icon.sprite = Resources.Load <Sprite>("cube"); //And specify whether data item has children(to display expander arrow if needed) foreach (string s in names) { if (dataItem.name.Equals(s)) { e.HasChildren = true; } } } }
/// <summary> /// This method called for each data item during databinding operation /// You have to bind data item properties to ui elements in order to display them. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnItemDataBinding(object sender, TreeViewItemDataBindingArgs e) { GameObject dataItem = e.Item as GameObject; if (dataItem != null) { //We display dataItem.name using UI.Text Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = dataItem.name; //Load icon from resources Image icon = e.ItemPresenter.GetComponentsInChildren <Image>()[4]; TreeView.SelectionChanged += OnSelectionChanged; icon.sprite = Resources.Load <Sprite>("cube"); //Load icon from resources Image icon2 = e.ItemPresenter.GetComponentsInChildren <Image>()[5]; icon2.sprite = Resources.Load <Sprite>("ExpandSelf"); //Load icon from resources Image icon3 = e.ItemPresenter.GetComponentsInChildren <Image>()[6]; icon3.sprite = Resources.Load <Sprite>("Expand"); //Load icon from resources Image icon4 = e.ItemPresenter.GetComponentsInChildren <Image>()[7]; icon4.sprite = Resources.Load <Sprite>("Hide"); //And specify whether data item has children (to display expander arrow if needed) if (dataItem.name != "TreeView") { e.HasChildren = dataItem.transform.childCount > 0; } } }
private void OnItemDataBinding(object sender, TreeViewItemDataBindingArgs e) { GameObject gameObject = e.Item as GameObject; if (!Object.op_Inequality((Object)gameObject, (Object)null)) { return; } ((Text)e.ItemPresenter.GetComponentInChildren <Text>(true)).set_text(((Object)gameObject).get_name()); ((Image)e.ItemPresenter.GetComponentsInChildren <Image>()[4]).set_sprite((Sprite)Resources.Load <Sprite>("cube")); if (!(((Object)gameObject).get_name() != "TreeView")) { return; } e.HasChildren = gameObject.get_transform().get_childCount() > 0; }