public void ResetConnections(int sourceIndex) { var connection = new Node.Connection() { index = -1, cost = 0f }; var node = this.GetNodeByIndex <GridNode>(sourceIndex); for (int i = 0; i < node.connections.Length; ++i) { node.connections[i] = connection; } }
public void SetupConnectionByDirection(int sourceIndex, Direction direction) { var connection = new Node.Connection() { index = -1, cost = 0f }; var node = this.GetNodeByIndex <GridNode>(sourceIndex); var target = GridGraphUtilities.GetIndexByDirection(this, sourceIndex, direction); if (target >= 0) { var targetNode = this.GetNodeByIndex <GridNode>(target); var cost = (node.worldPosition - targetNode.worldPosition).sqrMagnitude; connection.cost = cost * (GridGraphUtilities.IsDiagonalDirection(direction) == true ? this.diagonalCostFactor : 1f) + targetNode.penalty; connection.index = target; } node.connections[(int)direction] = connection; }