private bool CreateNodeUnit(NavigatorNode _parent, Node _node, ref float _xPoint, bool _useRestrics = true, float _originalXPoint = -1) { GameObject childNodeGO = Instantiate(_nodePrefab); RectTransform childNodeRect = childNodeGO.transform as RectTransform; childNodeRect.SetParent(transform, false); childNodeRect.pivot = new Vector2(-1 * _parent.nodeSide * 0.5f + 0.5f, 0.5f); childNodeRect.localPosition = new Vector3(_xPoint + _xDelta * _parent.nodeSide, _parent.transform.localPosition.y); Vector3 originalPosition = (_originalXPoint == -1) ? childNodeRect.localPosition : new Vector3(_originalXPoint + _xDelta * _parent.nodeSide, _parent.transform.localPosition.y); NavigatorNode childNode = childNodeGO.GetComponent <NavigatorNode>(); childNode.Init(_node, _parent.nodeSide, _parent.nodeLevel + 1, _parent.nodeRow, originalPosition); childNode.parent = _parent; _sceneNodes.Add(childNode); _xPoint = childNodeRect.localPosition.x + childNodeRect.rect.width * childNode.nodeSide; if (_useRestrics && Mathf.Abs(_xPoint) > 400) { return(false); } return(true); }
private void CreateSide(List <Node> _sideNodes, int _direction) { for (int i = 0; i < _sideNodes.Count; i++) { GameObject nodeGO = Instantiate(_nodePrefab); RectTransform nodeRect = nodeGO.transform as RectTransform; nodeRect.SetParent(transform, false); nodeRect.pivot = new Vector2(-1 * _direction * 0.5f + 0.5f, 0.5f); float hd = (_sideNodes.Count - 1) / 2f; nodeRect.localPosition = new Vector3(_homeXdelta * _direction, navigationZero + (hd - i) * (nodeRect.rect.height + _yDelta)); NavigatorNode node = nodeGO.GetComponent <NavigatorNode>(); node.Init(_sideNodes[i], _direction, 0, i + 1, nodeRect.localPosition, i); _sceneNodes.Add(node); float xPoint = nodeRect.localPosition.x + nodeRect.rect.width * _direction; for (int j = 0; j < _sideNodes[i].children.Count; j++) { Node childNodeData = RepositoryController.Instance.nodes.Find(x => x.nodeId.Equals(_sideNodes[i].children[j])); if (childNodeData != null) { bool res = CreateNodeUnit(node, childNodeData, ref xPoint); if (!res) { break; } } } } }