private void PaintElements(TreeNode <NodeData> branch, bool backButton) { if (this.PaintTitle(branch.GetID(), backButton)) { this.currentBranch = this.pathTrace.Pop(); this.listIndex = this.currentBranch.GetData().listIndex; } this.scroll = EditorGUILayout.BeginScrollView(this.scroll, GUIStyle.none, GUI.skin.verticalScrollbar); int elemIndex = 0; foreach (TreeNode <NodeData> element in branch) { NodeData nodeData = element.GetData(); bool mouseEnter = this.listIndex == elemIndex && UnityEngine.Event.current.type == EventType.MouseDown; Rect buttonRect = GUILayoutUtility.GetRect(nodeData.content, this.elementSelectorStyle); bool buttonHasFocus = this.listIndex == elemIndex; if (UnityEngine.Event.current.type == EventType.Repaint) { if (this.listIndex == elemIndex) { this.listSelectedRect = buttonRect; } this.elementSelectorStyle.Draw( buttonRect, nodeData.content, buttonHasFocus, buttonHasFocus, false, false ); if (nodeData.component == null) { CoreGUIStyles.GetButtonRightArrow().Draw( new Rect( buttonRect.x + buttonRect.width - ARROW_SIZE, buttonRect.y + buttonRect.height / 2.0f - ARROW_SIZE / 2.0f, ARROW_SIZE, ARROW_SIZE ), false, false, false, false ); } } if (buttonHasFocus) { if (nodeData.component == null) { if (mouseEnter || this.keyPressedRight || this.keyPressedEnter) { if (this.keyPressedRight) { UnityEngine.Event.current.Use(); } if (this.keyPressedEnter) { UnityEngine.Event.current.Use(); } this.currentBranch.GetData().listIndex = this.listIndex; this.pathTrace.Push(this.currentBranch); this.currentBranch = this.currentBranch.GetChild(element.GetID()); this.listIndex = 0; } } else { if (mouseEnter || this.keyPressedEnter) { if (this.keyPressedEnter) { UnityEngine.Event.current.Use(); } if (this.callback != null) { this.callback(nodeData.component); } this.editorWindow.Close(); } } } if (UnityEngine.Event.current.type == EventType.MouseMove && GUILayoutUtility.GetLastRect().Contains(UnityEngine.Event.current.mousePosition)) { this.listIndex = elemIndex; this.currentBranch.GetData().listIndex = this.listIndex; } ++elemIndex; } if (this.keyPressedDown && this.listIndex < elemIndex - 1) { this.listIndex++; this.currentBranch.GetData().listIndex = this.listIndex; UnityEngine.Event.current.Use(); } else if (this.keyPressedUp && this.listIndex > 0) { this.listIndex--; this.currentBranch.GetData().listIndex = this.listIndex; UnityEngine.Event.current.Use(); } EditorGUILayout.EndScrollView(); float scrollHeight = GUILayoutUtility.GetLastRect().height; if (UnityEngine.Event.current.type == EventType.Repaint && this.keyFlagVerticalMoved) { this.keyFlagVerticalMoved = false; if (this.listSelectedRect != Rect.zero) { if (this.scroll.y > this.listSelectedRect.y) { this.scroll = Vector2.up * (this.listSelectedRect.position.y); this.editorWindow.Repaint(); } else if (this.scroll.y + scrollHeight < this.listSelectedRect.position.y + this.listSelectedRect.size.y) { float positionY = this.listSelectedRect.y + this.listSelectedRect.height - scrollHeight; this.scroll = Vector2.up * positionY; this.editorWindow.Repaint(); } } } }