private void CreateChildNodes(NavigatorNode _parent) { float xPoint = _parent.transform.localPosition.x + _parent.nodeSize.x * _parent.nodeSide; float originalXPoint = _parent.originalPosition.x + _parent.nodeSize.x * _parent.nodeSide; for (int i = 0; i < _parent.nodeData.children.Count; i++) { Node childNodeData = RepositoryController.Instance.nodes.Find(x => x.nodeId.Equals(_parent.nodeData.children[i])); if (childNodeData != null) { NavigatorNode nodeOnScene = _sceneNodes.Find(x => x.nodeData.Equals(childNodeData)); if (nodeOnScene != null) { xPoint = nodeOnScene.transform.localPosition.x + nodeOnScene.nodeSize.x * nodeOnScene.nodeSide; originalXPoint = nodeOnScene.originalPosition.x + nodeOnScene.nodeSize.x * nodeOnScene.nodeSide; continue; } bool res = CreateNodeUnit(_parent, childNodeData, ref xPoint, _originalXPoint: originalXPoint); if (!res) { break; } } } }
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 ClearFarNodes(NavigatorNode _selected) { int lastRow = _selectedNode.nodeRow; if (_selectedNode.nodeData.nodeId == 1000 || (lastRow == _selected.nodeRow && _selectedNode.nodeSide == _selected.nodeSide)) { return; } List <NavigatorNode> sameRowNodes = _sceneNodes.FindAll(x => x.nodeRow.Equals(lastRow) && x.nodeSide.Equals(_selectedNode.nodeSide)); List <NavigatorNode> delNodes = new List <NavigatorNode>(); if (sameRowNodes != null && sameRowNodes.Count > 0) { for (int i = 0; i < sameRowNodes.Count; i++) { float xPoint = sameRowNodes[i].transform.localPosition.x + sameRowNodes[i].nodeSize.x * sameRowNodes[i].nodeSide; if ((sameRowNodes[i].nodeSide > 0 && xPoint > _homeNode.transform.localPosition.x + 600) || (sameRowNodes[i].nodeSide < 0 && xPoint < _homeNode.transform.localPosition.x - 600)) { delNodes.Add(sameRowNodes[i]); Destroy(sameRowNodes[i].gameObject); } } _sceneNodes.RemoveAll(x => delNodes.Contains(x)); } }
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; } } } } }
private void RestoreDefaultNodes(int _lastRow, NavigatorNode _mainLineParent, NavigatorNode _selected) { if ((_lastRow == _selected.nodeRow && _selected.nodeLevel > 0) || _mainLineParent == null) { return; } CreateChildNodes(_mainLineParent); }
private void SelectNavNode(NavigatorNode selected) { if (_selectedNode != null) { _selectedNode.Deselect(); } if (!selected.selected) { selected.SelectBy(); } float delta = selected.transform.localPosition.x + selected.nodeSide * (selected.nodeSize.x / 2f); if (Mathf.Abs(delta) > 0f && _selectedNode != null) { if (selected.nodeData.children.Count > 0) { ClearSameChildNodes(selected); } ClearUpLevel(selected, _selectedNode); NavigatorNode mainLineParent = null; while (mainLineParent == null && _selectedNode.nodeData.nodeId != 1000) { if (_selectedNode.nodeLevel == 0) { mainLineParent = _selectedNode; } else { _selectedNode = _selectedNode.parent; } } int row = (mainLineParent == null) ? 0 : mainLineParent.nodeRow; _selectedNode = selected; Action postAction = () => { RestoreDefaultNodes(row, mainLineParent, selected); ClearFarNodes(selected); CreateNodesAfterSelected(); _selectedNode = selected; _selectedNode.nodeState = NavigatorNode.Navigator_state.Selected; _homeNode.Deselect(); RepositoryController.Instance.isAction = true; }; StartCoroutine(MoveNodes(-delta, postAction)); } else { _selectedNode = selected; RepositoryController.Instance.isAction = true; } }
public void ExpandNode(Node _node) { RepositoryController.Instance.isAction = false; NavigatorNode selected = _sceneNodes.Find(x => !x.nodeData.Equals(null) && x.nodeData.Equals(_node)); Action postAction = () => { NavigatorNode next = _sceneNodes.Find(x => x.Equals(selected.parent)); RepositoryController.Instance.isAction = true; next.Select(); }; StartCoroutine(ExpandNode(postAction)); }
private void ClearUpLevel(NavigatorNode _newSelected, NavigatorNode _parent) { if (_parent.nodeData.children.Contains(_newSelected.nodeData.nodeId) || _parent.nodeLevel == 0 || _parent == _newSelected) { return; } for (int i = 0; i < _parent.nodeData.children.Count; i++) { NavigatorNode childOnScene = _sceneNodes.Find(x => x.nodeData.nodeId.Equals(_parent.nodeData.children[i])); if (childOnScene != null) { Destroy(childOnScene.gameObject); _sceneNodes.Remove(childOnScene); } } ClearUpLevel(_newSelected, _parent.parent); }
private void ClearSameChildNodes(NavigatorNode _selected) { if (_selected.parent != null) { List <int> parentChildrenId = _selected.parent.nodeData.children; for (int i = 0; i < parentChildrenId.Count; i++) { if (_selected.nodeData.nodeId == parentChildrenId[i]) { continue; } NavigatorNode sameParentNode = _sceneNodes.Find(x => x.nodeData.nodeId.Equals(parentChildrenId[i])); if (sameParentNode != null && (sameParentNode.transform.position.x - _selected.transform.position.x) * _selected.nodeSide > 0f) { Destroy(sameParentNode.gameObject); _sceneNodes.Remove(sameParentNode); } } } }
public void SelectNode(Node _node) { RepositoryController.Instance.isAction = false; NavigatorNode selected = _sceneNodes.Find(x => !x.nodeData.Equals(null) && x.nodeData.Equals(_node)); if (selected != null) { if (selected.nodeState == NavigatorNode.Navigator_state.Squeeze) { Action postAction = () => { SelectNavNode(selected); }; StartCoroutine(ExpandNode(postAction)); } else { List <NavigatorNode> squeezeNodes = _sceneNodes.FindAll(x => x.nodeState == NavigatorNode.Navigator_state.Squeeze); if (squeezeNodes.Count > 0) { if (squeezeNodes[0].nodeRow == selected.nodeRow && squeezeNodes[0].nodeSide == selected.nodeSide) { if (selected.nodeLevel == 0) { Action postAction = () => { SelectNavNode(selected); }; StartCoroutine(ExpandNode(postAction)); } else { SelectNavNode(selected); } } else { Action postAction = () => { SelectNavNode(selected); }; StartCoroutine(ExpandNode(postAction)); } } else { SelectNavNode(selected); } } } else { List <NavigatorNode> squeezeNodes = _sceneNodes.FindAll(x => x.nodeState == NavigatorNode.Navigator_state.Squeeze); if (squeezeNodes.Count > 0) { Action postAction = () => { CreateUnexist(_node); }; StartCoroutine(ExpandNode(postAction)); } else { CreateUnexist(_node); } } }
private void CreateUnexist(Node _node) { List <Node> nodesChain = new List <Node>(); NavigatorNode mainParent = null; Node currentChild = _node; while (mainParent == null) { nodesChain.Add(currentChild); Node currentParent = RepositoryController.Instance.nodes.Find(x => x.children.Contains(currentChild.nodeId)); int cci = currentParent.children.IndexOf(currentChild.nodeId); for (int i = currentParent.children.Count - 1; i >= 0; i--) { if (i < cci) { Node cousin = RepositoryController.Instance.nodes.Find(x => x.nodeId.Equals(currentParent.children[i])); nodesChain.Add(cousin); } } NavigatorNode parentOnScene = _sceneNodes.Find(x => x.nodeData.Equals(currentParent)); if (parentOnScene != null && parentOnScene.nodeLevel == 0) { mainParent = parentOnScene; } else { currentChild = currentParent; } } float xPoint = mainParent.transform.localPosition.x + mainParent.nodeSize.x * mainParent.nodeSide; List <NavigatorNode> nodesForDel = _sceneNodes.FindAll(x => x.nodeRow.Equals(mainParent.nodeRow) && x.nodeSide.Equals(mainParent.nodeSide) && x.nodeLevel > 0); if (nodesForDel != null && nodesForDel.Count > 0) { for (int i = 0; i < nodesForDel.Count; i++) { if (nodesChain.Contains(nodesForDel[i].nodeData) || nodesForDel[i].nodeLevel <= 0) { xPoint = nodesForDel[i].transform.localPosition.x + nodesForDel[i].nodeSize.x * nodesForDel[i].nodeSide; continue; } Destroy(nodesForDel[i].gameObject); _sceneNodes.Remove(nodesForDel[i]); } } for (int i = nodesChain.Count - 1; i >= 0; i--) { NavigatorNode nodeOnScene = _sceneNodes.Find(x => x.nodeData.Equals(nodesChain[i])); if (nodeOnScene != null) { xPoint = nodeOnScene.transform.localPosition.x + nodeOnScene.nodeSize.x * nodeOnScene.nodeSide; continue; } NavigatorNode parent = _sceneNodes.Find(x => x.nodeData.children.Contains(nodesChain[i].nodeId)); CreateNodeUnit(parent, nodesChain[i], ref xPoint, false); } NavigatorNode selected = _sceneNodes[_sceneNodes.Count - 1]; if (!selected.selected) { selected.SelectBy(); } float delta = selected.transform.localPosition.x + selected.nodeSide * (selected.nodeSize.x / 2f); //int row = -1; if (Mathf.Abs(delta) > 0f && _selectedNode != null) { if (selected.nodeData.children.Count > 0) { ClearSameChildNodes(selected); } ClearUpLevel(selected, _selectedNode); NavigatorNode mainLineParent = null; while (mainLineParent == null && _selectedNode.nodeData.nodeId != 1000) { if (_selectedNode.nodeLevel == 0) { mainLineParent = _selectedNode; } else { if (_selectedNode != null) { _selectedNode.Deselect(); } _selectedNode = _selectedNode.parent; } } int row = (mainLineParent == null) ? 0 : mainLineParent.nodeRow; _selectedNode = selected; Action postAction = () => { RestoreDefaultNodes(row, mainLineParent, selected); ClearFarNodes(selected); CreateNodesAfterSelected(); _selectedNode = selected; _selectedNode.nodeState = NavigatorNode.Navigator_state.Selected; _homeNode.Deselect(); RepositoryController.Instance.isAction = true; }; StartCoroutine(MoveNodes(-delta, postAction)); } else { if (_selectedNode != null) { _selectedNode.Deselect(); } _selectedNode = selected; RepositoryController.Instance.isAction = true; } }