예제 #1
0
    public virtual bool MoveTo(GridTile gridTile, bool animate = true, bool triggerCooldown = true)
    {
        // If the tile is occupied return
        if (gridTile.IsTileOccupied())
        {
            return(false);
        }

        // Animated movement
        if (animate)
        {
            AnimateMoveTo(gridTile);
        }
        else
        {
            // Non animated movement (instant)
            // Update the movement variables
            StartMovement(gridTile);
            // Update variables on the owner GridObject
            SwapPosition(gridTile);
            // Set the transform's position to the target GridTile's world position
            transform.position = gridTile.m_GridObjectsPivotPosition;
            // Reset the movement variables
            EndMovement();
        }

        // Trigger the cooldown
        if (triggerCooldown)
        {
            TriggerCooldown();
        }


        return(true);
    }
예제 #2
0
    // Returns a list with the neighbors of the tile
    public virtual List <GridTile> WalkableNeighbors(GridTile gridTile, bool ignoresHeight = false, bool unoccupiedTilesOnly = true, GridTile goalTile = null, bool canFly = false, List <Vector2Int> customDirections = null)
    {
        List <GridTile> results    = new List <GridTile>();
        var             directions = customDirections != null ? customDirections : GetNeighborPositions((gridTile.m_GridPosition.y & 1) == 1);

        foreach (Vector2Int dir in directions)
        {
            Vector2Int newVector = dir + gridTile.m_GridPosition;
            if (ExistsTileAtPosition(newVector))
            {
                GridTile targetTile = GetGridTileAtPosition(newVector);
                if (targetTile != null)
                {
                    if (targetTile.m_IsTileFlyable)
                    {
                        if (canFly)
                        {
                            results.Add(targetTile);
                        }
                        continue;
                    }

                    if (targetTile.m_IsTileWalkable || (goalTile != null && targetTile == goalTile))
                    {
                        if (unoccupiedTilesOnly && targetTile.IsTileOccupied() && (goalTile == null || (goalTile != null && targetTile != goalTile)))
                        {
                            continue;
                        }

                        if (m_UsesHeight && !ignoresHeight)
                        {
                            if (Mathf.Abs(Mathf.Abs(gridTile.m_TileHeight) - Mathf.Abs(targetTile.m_TileHeight)) <= 1)
                            {
                                results.Add(targetTile);
                            }
                        }
                        else
                        {
                            results.Add(targetTile);
                        }
                    }
                }
            }
        }

        // Add manual neighbors to the result
        foreach (GridTile tile in gridTile.m_manualNeighbors)
        {
            if (!results.Contains(tile))
            {
                results.Add(tile);
            }
        }

        results.Distinct();
        return(results);
    }
예제 #3
0
 // Add this Gridobject to the occupant list on the target Gridtile
 public virtual void AddToTile(GridTile gridTile)
 {
     // If the tile exists
     if (gridTile != null)
     {
         // And it is not already occupied
         if (!gridTile.IsTileOccupied())
         {
             m_CurrentGridTile.AddOccupyingGridObject(this);
         }
     }
 }