private void drawNodeLabel(Rect labelRect, SwitchTree.Node node) { if (Event.current.isMouse && labelRect.Contains(Event.current.mousePosition) && Event.current.button == 0 && Event.current.type == EventType.MouseDown) { EditorGUIUtility.PingObject(node.objSwitch as MonoBehaviour); } EditorGUI.LabelField(labelRect, new GUIContent(node.transform.name + (node.treeDepth == 0 ? " (root)" : ""))); }
private void drawNode(SwitchTree.Node node, Rect rect, SwitchTree switchTree, SerializedProperty treeProperty, bool isEvenRow = true) { if (node.treeDepth == 0) { drawControllerBackground(rect); } else { drawTreeBackground(rect, isEvenRow); } Rect indentRect; Rect labelRect = rect.PadLeft(INDENT_WIDTH * (node.treeDepth + 1), out indentRect); drawNodeLabel(labelRect, node); Rect fullButtonRect = indentRect.TakeRight(INDENT_WIDTH, out indentRect); #region Debug Rects //EditorGUI.DrawRect(indentRect, Color.cyan); //EditorGUI.DrawRect(fullButtonRect, Color.magenta); #endregion // Line drawing. if (node.hasChildren) { bool anyChildGlowDueToParent = node.isOn && node.children .Query() .Any(c => c.isOn); drawCenteredLine(Direction4.Down, fullButtonRect, anyChildGlowDueToParent ? LineType.Glow : LineType.Default); } if (node.hasParent) { bool glowingDueToParent = node.isOn && node.isParentOn; drawCenteredLine(Direction4.Left, fullButtonRect, glowingDueToParent ? LineType.Glow : LineType.Default); } // Leftward rects. var curNode = node; bool firstLeftward = true; while (curNode.hasParent) { Rect leftwardRect = indentRect.TakeRight(INDENT_WIDTH, out indentRect); bool glowingDueToParent = curNode.isOn && curNode.isParentOn; bool isAnyPrevSiblingOnDueToParent = curNode.prevSiblings .Query() .Any(n => n.isOn && n.isParentOn); bool isSelfOrAnyPrevSiblingOnDueToParent = glowingDueToParent || isAnyPrevSiblingOnDueToParent; if (firstLeftward) { drawCenteredLine(Direction4.Right, leftwardRect, glowingDueToParent ? LineType.Glow : LineType.Default); drawCenteredLine(Direction4.Up, leftwardRect, isSelfOrAnyPrevSiblingOnDueToParent ? LineType.Glow : LineType.Default); firstLeftward = false; } else if (curNode.hasPrevSibling) { drawCenteredLine(Direction4.Up, leftwardRect, isAnyPrevSiblingOnDueToParent ? LineType.Glow : LineType.Default); } if (curNode.hasPrevSibling) { drawCenteredLine(Direction4.Down, leftwardRect, isAnyPrevSiblingOnDueToParent ? LineType.Glow : LineType.Default); } curNode = curNode.hasParent ? curNode.parent.node : default(SwitchTree.Node); } Rect buttonRect = fullButtonRect.PadInner(BUTTON_RECT_INNER_PAD); // Support undo history. Undo.IncrementCurrentGroup(); var curGroupIdx = Undo.GetCurrentGroup(); bool test_isNodeOff = node.isOff; if (test_isNodeOff) { EditorGUI.DrawRect(buttonRect, Color.red); } Color origContentColor = GUI.contentColor; if (node.isOn) { Rect glowRect = buttonRect.Extrude(GLOW_WIDTH); EditorGUI.DrawRect(glowRect, glowBackgroundColor); GUI.contentColor = glowContentColor; } if (GUI.Button(buttonRect, new GUIContent("Switch to this node."))) { // Note: It is the responsibility of the IPropertySwitch implementation // to perform operations that correctly report their actions in OnNow() to the // Undo history! switchTree.SwitchTo(node.transform.name, immediately: !Application.isPlaying); treeProperty.FindPropertyRelative("_curActiveNodeName").stringValue = node.transform.name; } Undo.CollapseUndoOperations(curGroupIdx); Undo.SetCurrentGroupName("Set Switch Tree State"); if (node.isOn) { GUI.contentColor = origContentColor; } }