Exemplo n.º 1
0
        public void SetupConnectionByDirection(int sourceIndex, Direction direction)
        {
            var connection = Node.Connection.NoConnection;
            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;
        }