private IHexagonNetNode <T> GetNeighbourForNotShiftedRowNode(IHexagonNetNode <T> node, HexagonNetEnums.Neighbours neighbour) { IHexagonNetNode <T> neighbourNode = null; var nodePosition = node.Position; switch (neighbour) { case HexagonNetEnums.Neighbours.UpperLeft: neighbourNode = net[nodePosition.x - 1].Nodes[nodePosition.y - 1]; break; case HexagonNetEnums.Neighbours.UpperRight: neighbourNode = net[nodePosition.x - 1].Nodes[nodePosition.y]; break; case HexagonNetEnums.Neighbours.Left: neighbourNode = net[nodePosition.x].Nodes[nodePosition.y - 1]; break; case HexagonNetEnums.Neighbours.Right: neighbourNode = net[nodePosition.x].Nodes[nodePosition.y + 1]; break; case HexagonNetEnums.Neighbours.LowerLeft: neighbourNode = net[nodePosition.x + 1].Nodes[nodePosition.y - 1]; break; case HexagonNetEnums.Neighbours.LowerRight: neighbourNode = net[nodePosition.x + 1].Nodes[nodePosition.y]; break; } return(neighbourNode); }
/// <summary> /// Sets the specified neigbour as the neighbourNode, and tries to update the corresponding OppositeNeighbourNode to this. /// </summary> /// <param name="neighbourNode"></param> /// <param name="neighbour"></param> public void SetNeighbour(IHexagonNetNode <Bubble> neighbourNode, HexagonNetEnums.Neighbours neighbour) { Neighbours[(int)neighbour] = neighbourNode; //if (neighbourNode != null) //{ // neighbourNode.Neighbours[(int)HexagonNetEnums.GetOppositeNeighbourNode(neighbour)] = this; //} }
/// <summary> /// Binds the neighbouring nodes together withing and in-between the HexagonRows. /// </summary> /// <param name="node"></param> private void UpdateNeighboursFor(IHexagonNetNode <T> node) { UpdateNeighbourFor(node, HexagonNetEnums.Neighbours.Left); UpdateNeighbourFor(node, HexagonNetEnums.Neighbours.LowerLeft); UpdateNeighbourFor(node, HexagonNetEnums.Neighbours.LowerRight); UpdateNeighbourFor(node, HexagonNetEnums.Neighbours.Right); UpdateNeighbourFor(node, HexagonNetEnums.Neighbours.UpperLeft); UpdateNeighbourFor(node, HexagonNetEnums.Neighbours.UpperRight); }
private void SetupBubbleGraphics(IHexagonNetNode <Bubble> bubbleNode) { if (bubbleNode.Value != null) { var bubbleGraphics = BubbleGraphicsPool.Instance.Get(); bubbleGraphics.Bubble = bubbleNode.Value; bubbleGraphics.SyncGraphicsWithBubble(); var bubbleGraphicsPosition = ComputeBubbleGraphicsPosition(bubbleNode.Position); bubbleGraphics.SetPosition(bubbleGraphicsPosition); bubbleGraphics.gameObject.SetActive(true); bubblesGraphics.Add(bubbleNode, bubbleGraphics); } }
private void UpdateNeighbourFor(IHexagonNetNode <T> node, Neighbours neighbour) { IHexagonNetNode <T> neighbourNode = GetNeighbourFor(node, neighbour); if (node != null) { node.SetNeighbour(neighbourNode, neighbour); } if (neighbourNode != null) { // Find which neighbour from HexaonNetEnums.Neighbours is this node for the neighbourNode var oppositeNeighbour = GetOppositeNeighbourNode(neighbour); Neighbours neighbourForNeighbour = GetNeighbourWithSameNameAsOpposite(oppositeNeighbour); neighbourNode.SetNeighbour(node, neighbourForNeighbour); } }
/// <summary> /// Retrieves the specified neighbour of this node. /// </summary> /// <param name="node"></param> /// <param name="neighbour"></param> /// <returns>The neighbour or null, if no neighbour is found.</returns> public IHexagonNetNode <T> GetNeighbourFor(IHexagonNetNode <T> node, HexagonNetEnums.Neighbours neighbour) { if (node == null) { throw new ArgumentException("Cannot find the neigbour for the node that is null!"); } if (node.Position == null) { throw new ArgumentException("The node has to be positioned within the HexagonNet!"); } IHexagonNetNode <T> neighbourNode = null; try { var row = net[node.Position.x]; if (row.Shifted) { neighbourNode = GetNeighbourForShiftedRowNode(node, neighbour); } else { neighbourNode = GetNeighbourForNotShiftedRowNode(node, neighbour); } } catch (Exception ex) { Type exType = ex.GetType(); if (exType == typeof(IndexOutOfRangeException) || exType == typeof(KeyNotFoundException)) { // Means we are at the border or the row above/below is not yet added // Simply leave the neighbourNode == null; } else { throw; } } return(neighbourNode); }