private void OnItemEndEdit(object sender, TreeViewItemDataBindingArgs e) { InputField inputField = e.EditorPresenter.GetComponentInChildren <InputField>(true); Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); ProjectItem projectItem = (ProjectItem)e.Item; string oldName = projectItem.Name; if (projectItem.Parent != null) { ProjectItem parentItem = projectItem.Parent; string newNameExt = inputField.text.Trim() + "." + projectItem.Ext; if (!string.IsNullOrEmpty(inputField.text.Trim()) && ProjectItem.IsValidName(inputField.text.Trim()) && !parentItem.Children.Any(p => p.NameExt == newNameExt)) { projectItem.Name = inputField.text.Trim(); } } if (Renamed != null) { Renamed(this, new ProjectTreeRenamedEventArgs(new[] { projectItem }, new[] { oldName })); } text.text = projectItem.Name; //Following code is required to unfocus inputfield if focused and release InputManager if (EventSystem.current != null && !EventSystem.current.alreadySelecting) { EventSystem.current.SetSelectedGameObject(null); } }
private void OnItemEndEdit(object sender, TreeViewItemDataBindingArgs e) { GameObject dataItem = e.Item as GameObject; if (dataItem != null) { InputField inputField = e.EditorPresenter.GetComponentInChildren <InputField>(true); if (!string.IsNullOrEmpty(inputField.text)) { dataItem.name = inputField.text; Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = dataItem.name; } else { inputField.text = dataItem.name; } } //Following code is required to unfocus inputfield if focused and release InputManager if (EventSystem.current != null && !EventSystem.current.alreadySelecting) { EventSystem.current.SetSelectedGameObject(null); } }
private void OnItemBeginEdit(object sender, TreeViewItemDataBindingArgs e) { ProjectItem item = e.Item as ProjectItem; if (item != null) { InputField inputField = e.EditorPresenter.GetComponentInChildren <InputField>(true); inputField.text = item.Name; inputField.ActivateInputField(); inputField.Select(); Image image = e.EditorPresenter.GetComponentInChildren <Image>(true); if (item.IsExposedFromEditor) { image.sprite = ExposedFolderIcon; } else { image.sprite = FolderIcon; } image.gameObject.SetActive(true); LayoutElement layout = inputField.GetComponent <LayoutElement>(); Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = item.Name; RectTransform rt = text.GetComponent <RectTransform>(); layout.preferredWidth = rt.rect.width; } }
private void OnItemBeginEdit(object sender, TreeViewItemDataBindingArgs e) { GameObject dataItem = e.Item as GameObject; if (dataItem != null) { InputField inputField = e.EditorPresenter.GetComponentInChildren <InputField>(true); inputField.text = dataItem.name; inputField.ActivateInputField(); inputField.Select(); LayoutElement layout = inputField.GetComponent <LayoutElement>(); Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = dataItem.name; RectTransform rt = text.GetComponent <RectTransform>(); layout.preferredWidth = rt.rect.width; } }
/// <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]; //icon.sprite = Resources.Load<Sprite>("cube"); //And specify whether data item has children (to display expander arrow if needed) if (dataItem.name != "TreeView" && dataItem.GetComponent <SyncedAsset>() == null) { e.HasChildren = dataItem.transform.childCount > 0; } } }
private void OnItemDataBinding(object sender, TreeViewItemDataBindingArgs e) { GameObject dataItem = e.Item as GameObject; if (dataItem != null) { Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = dataItem.name; if (dataItem.activeInHierarchy) { text.color = EnabledItemColor; } else { text.color = DisabledItemColor; } e.HasChildren = dataItem.GetComponent <ExposeToEditor>().ChildCount > 0; } }
/// <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; //LoadInternal 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) if (dataItem.name != "TreeView") { e.CanDrag = e.CanEdit = !Root.Contains(dataItem); e.HasChildren = Hierarchy.Lookup[dataItem].GetChildrenCount() > 0; } } }
private void OnItemDataBinding(object sender, TreeViewItemDataBindingArgs e) { ProjectItem item = e.Item as ProjectItem; if (item != null) { Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = item.Name; Image image = e.ItemPresenter.GetComponentInChildren <Image>(true); if (item.IsScene) { image.sprite = SceneIcon; } else { image.sprite = FolderIcon; } image.gameObject.SetActive(true); e.HasChildren = item.Children != null && item.Children.Count(projectItem => projectItem.IsFolder || projectItem.IsScene) > 0; } }
private void OnItemDataBinding(object sender, TreeViewItemDataBindingArgs e) { MyCustomData dataItem = e.Item as MyCustomData; if (dataItem != null) { //We display dataItem.name using UI.Text Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = dataItem.name; text.color = colorByLevel [dataItem.level]; text.fontSize = 60; text.raycastTarget = false; //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) if (dataItem.name != "TreeView") { e.HasChildren = dataItem.level < 3; } } }
private void OnItemDataBinding(object sender, TreeViewItemDataBindingArgs e) { ProjectItem item = e.Item as ProjectItem; if (item != null) { Text text = e.ItemPresenter.GetComponentInChildren <Text>(true); text.text = item.Name; Image image = e.ItemPresenter.GetComponentInChildren <Image>(true); if (item.IsExposedFromEditor) { image.sprite = ExposedFolderIcon; } else { image.sprite = FolderIcon; } image.gameObject.SetActive(true); e.CanEdit = !item.IsExposedFromEditor && item.Parent != null; e.CanDrag = !item.IsExposedFromEditor && item.Parent != null; e.HasChildren = item.Children != null && item.Children.Count(projectItem => CanDisplayFolder(projectItem)) > 0; } }
/// <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]; icon.sprite = Resources.Load<Sprite>("cube"); //And specify whether data item has children (to display expander arrow if needed) if(dataItem.name != "TreeView") { e.HasChildren = dataItem.transform.childCount > 0; } } }