/// <summary> /// Display node. /// </summary> /// <param name="node">Node.</param> /// <param name="connector">Connector.</param> /// <param name="position">Position.</param> /// <returns>Node size.</returns> protected virtual Vector2 DisplayNode(TreeNode <TItem> node, MultipleConnector connector, Vector2 position) { var component = GetComponentInstance(); var size = GetNodeSize(node); (component.transform as RectTransform).anchoredPosition = IsHorizontal() ? new Vector2(position.x, -position.y - (size.y / 2f)) : new Vector2(position.x + (size.x / 2f), -position.y); component.SetData(node); if (connector != null) { var start = ConnectorPosition.Center; var end = ConnectorPosition.Center; switch (Direction) { case TreeGraphDirections.TopToBottom: start = ConnectorPosition.Bottom; end = ConnectorPosition.Top; break; case TreeGraphDirections.BottomToTop: start = ConnectorPosition.Top; end = ConnectorPosition.Bottom; break; case TreeGraphDirections.LeftToRight: start = ConnectorPosition.Right; end = ConnectorPosition.Left; break; case TreeGraphDirections.RightToLeft: start = ConnectorPosition.Left; end = ConnectorPosition.Right; break; default: #if NETFX_CORE throw new ArgumentException("Unsupported direction: " + Direction); #else throw new InvalidEnumArgumentException("Unsupported direction: " + Direction); #endif } var line = new ConnectorLine() { Target = component.transform as RectTransform, Start = start, End = end, Thickness = 1f, Type = ConnectorType.Straight, }; connector.Lines.Add(line); } if (node.IsExpanded) { var new_position = GetNextLevelPosition(position); DisplayNodes(node.Nodes, component.GetComponent <MultipleConnector>(), new_position); } return(size); }
/// <summary> /// Display nodes. /// </summary> /// <param name="nodesToDisplay">Nodes to display.</param> /// <param name="connector">Connector.</param> /// <param name="position">Start position.</param> protected virtual void DisplayNodes(ObservableList <TreeNode <TItem> > nodesToDisplay, MultipleConnector connector, Vector2 position) { if (nodesToDisplay == null) { return; } var size = Vector2.zero; foreach (var node in nodesToDisplay) { if (!node.IsVisible) { continue; } size = DisplayNode(node, connector, position); position = GetNextPosition(position, size); } }