public TreeViewItemEditor(TreeViewControlEditor parentControlEditor, TreeViewItemEditor parent) { ParentControlEditor = parentControlEditor; Parent = parent; if (null == parentControlEditor) { return; } }
/// <summary> /// Add a tree view control to the game object /// </summary> /// <param name="go"></param> public static TreeViewControlEditor AddTreeView(GameObject go) { if (null == go) { return(null); } TreeViewControlEditor item = go.AddComponent <TreeViewControlEditor>(); AssignDefaults(go); return(item); }
public void OnSceneGUI() { bool needsRepainted = false; if (null != Event.current && m_mousePos != Event.current.mousePosition) { needsRepainted = true; } if (null == target && !(target is TreeViewControlEditor)) { Debug.LogError("Not a TreeViewControl"); return; } TreeViewControlEditor item = (TreeViewControlEditor)target; if (null == item) { Debug.LogError("TreeViewControl is null"); return; } if (!item.DisplayOnScene) { return; } item.DisplayTreeView(TreeViewControlEditor.DisplayTypes.USE_SCROLL_AREA); if (item.SelectedItemEditor != _mLastSelectedItemEditor) { _mLastSelectedItemEditor = item.SelectedItemEditor; needsRepainted = true; } if (needsRepainted) { Repaint(); SceneView.RepaintAll(); } }
public static bool CheckApplySkin() { GameObject go = Selection.activeGameObject; if (null == go || !(go is GameObject)) { return(false); } TreeViewControlEditor item = go.GetComponent <TreeViewControlEditor>(); if (null == item) { return(false); } else { return(true); } }
public override void OnInspectorGUI() { if (Application.isPlaying) { GUILayout.Label("Please avoid editing these fields while playing"); } if (null == target && !(target is TreeViewControlEditor)) { Debug.LogError("Not a TreeViewControl"); return; } TreeViewControlEditor item = (TreeViewControlEditor)target; if (null == item) { Debug.LogError("TreeViewControl is null"); return; } bool needsRepainted = false; if (null != Event.current && m_mousePos != Event.current.mousePosition) { needsRepainted = true; } if (item.SelectedItemEditor != _mLastSelectedItemEditor) { _mLastSelectedItemEditor = item.SelectedItemEditor; needsRepainted = true; } if (null != item.SelectedItemEditor && string.IsNullOrEmpty(item.SelectedItemEditor.Header)) { item.SelectedItemEditor.Header = "Root item"; needsRepainted = true; } if (GUILayout.Button("Select Root TreeViewItem")) { item.SelectedItemEditor = item.RootItemEditor; Selection.activeGameObject = item.gameObject; needsRepainted = true; } if (null != item.SelectedItemEditor && GUILayout.Button("Add Child TreeView Item")) { item.SelectedItemEditor.AddItem("Default text"); needsRepainted = true; } if (null != item.SelectedItemEditor && item.SelectedItemEditor != item.RootItemEditor && null != item.SelectedItemEditor.Parent && GUILayout.Button("Remove TreeView Item")) { TreeViewItemEditor oldItemEditor = item.SelectedItemEditor; item.SelectedItemEditor.Parent.Items.Remove(oldItemEditor); item.SelectedItemEditor = null; needsRepainted = true; } if (null != item.SelectedItemEditor && null != item.SelectedItemEditor.Parent && item.SelectedItemEditor != item.RootItemEditor && item.SelectedItemEditor.Parent.Items.IndexOf(item.SelectedItemEditor) > 0 && GUILayout.Button("Move Up")) { TreeViewItemEditor oldItemEditor = item.SelectedItemEditor; item.SelectedItemEditor = null; int index = oldItemEditor.Parent.Items.IndexOf(oldItemEditor); oldItemEditor.Parent.Items.Remove(oldItemEditor); oldItemEditor.Parent.Items.Insert(index - 1, oldItemEditor); item.SelectedItemEditor = oldItemEditor; needsRepainted = true; } if (null != item.SelectedItemEditor && null != item.SelectedItemEditor.Parent && item.SelectedItemEditor != item.RootItemEditor && (item.SelectedItemEditor.Parent.Items.IndexOf(item.SelectedItemEditor) + 1) < item.SelectedItemEditor.Parent.Items.Count && GUILayout.Button("Move Down")) { TreeViewItemEditor oldItemEditor = item.SelectedItemEditor; item.SelectedItemEditor = null; int index = oldItemEditor.Parent.Items.IndexOf(oldItemEditor); oldItemEditor.Parent.Items.Remove(oldItemEditor); oldItemEditor.Parent.Items.Insert(index + 1, oldItemEditor); item.SelectedItemEditor = oldItemEditor; needsRepainted = true; } if (null != item.SelectedItemEditor && null != item.SelectedItemEditor.Parent && null != item.SelectedItemEditor.Parent.Parent && item.SelectedItemEditor != item.RootItemEditor && item.SelectedItemEditor.Parent != item.RootItemEditor && GUILayout.Button("Promote TreeView Item")) { TreeViewItemEditor oldItemEditor = item.SelectedItemEditor; item.SelectedItemEditor = null; oldItemEditor.Parent.Items.Remove(oldItemEditor); oldItemEditor.Parent.Parent.Items.Insert(0, oldItemEditor); oldItemEditor.Parent = oldItemEditor.Parent.Parent; item.SelectedItemEditor = oldItemEditor; needsRepainted = true; } EditorGUILayout.Separator(); if (null != item.SelectedItemEditor) { EditorGUILayout.LabelField("Parent:", (item.SelectedItemEditor.Parent == null) ? "(null)" : "(valid)"); EditorGUILayout.LabelField("Parent Control:", (item.SelectedItemEditor.ParentControlEditor == null) ? "(null)" : "(valid)"); } EditorGUILayout.Separator(); EditorGUILayout.LabelField("***** Selected Item:", "(editable fields) *******"); if (null != item.SelectedItemEditor) { if (!string.IsNullOrEmpty(item.SelectedItemEditor.Header)) { string header = EditorGUILayout.TextField("Header:", item.SelectedItemEditor.Header); if (!item.SelectedItemEditor.Header.Equals(header)) { item.SelectedItemEditor.Header = header; needsRepainted = true; } } bool isExpanded = EditorGUILayout.Toggle("IsExpanded:", item.SelectedItemEditor.IsExpanded); if (isExpanded != item.SelectedItemEditor.IsExpanded) { item.SelectedItemEditor.IsExpanded = isExpanded; needsRepainted = true; } bool isCheckBox = EditorGUILayout.Toggle("IsCheckBox:", item.SelectedItemEditor.IsCheckBox); if (isCheckBox != item.SelectedItemEditor.IsCheckBox) { item.SelectedItemEditor.IsCheckBox = isCheckBox; needsRepainted = true; } bool isChecked = EditorGUILayout.Toggle("IsChecked:", item.SelectedItemEditor.IsChecked); if (isChecked != item.SelectedItemEditor.IsChecked) { item.SelectedItemEditor.IsChecked = isChecked; needsRepainted = true; } } if (needsRepainted) { Repaint(); SceneView.RepaintAll(); } base.OnInspectorGUI(); if (item.DisplayInInspector) { EditorGUILayout.Separator(); item.DisplayTreeView(TreeViewControlEditor.DisplayTypes.NONE); EditorGUILayout.Separator(); } }
/// <summary> /// Called from OnGUI or EditorWindow.OnGUI /// </summary> public void DisplayTreeView(TreeViewControlEditor.DisplayTypes displayType) { if (!m_forceDefaultSkin) { GUI.skin = m_skinUnselected; } switch (displayType) { case TreeViewControlEditor.DisplayTypes.USE_SCROLL_VIEW: m_scrollView = GUILayout.BeginScrollView(m_scrollView, GUILayout.MaxWidth(Width), GUILayout.MaxHeight(Height)); break; case TreeViewControlEditor.DisplayTypes.USE_SCROLL_AREA: GUILayout.BeginArea(new Rect(X, Y, Width, Height)); m_scrollView = GUILayout.BeginScrollView(m_scrollView, GUIStyle.none,GUIStyle.none,GUILayout.MaxWidth(Width), GUILayout.MaxHeight(Height)); break; } RootItemEditor.DisplayItem(0, TreeViewItemEditor.SiblingOrder.FIRST_CHILD); switch (displayType) { case TreeViewControlEditor.DisplayTypes.USE_SCROLL_VIEW: GUILayout.EndScrollView(); break; case TreeViewControlEditor.DisplayTypes.USE_SCROLL_AREA: GUILayout.EndScrollView(); GUILayout.EndArea(); break; } GUI.skin = null; }