Esempio n. 1
0
    private void TestDebugAllBoundsInt(string beginStr, BoundsInt boundsInt)
    {
        StringBuilder stringBuilder = new StringBuilder();

        stringBuilder.AppendFormat("==============BeginLog {0} =================== \r\n", beginStr);
        //boundsInt.allPositionsWithin.Current
        BoundsInt.PositionEnumerator positionEnumerator = boundsInt.allPositionsWithin;
        bool flag = true;

        do
        {
            Vector3 now = positionEnumerator.Current;

            if (positionEnumerator.MoveNext())
            {
                stringBuilder.AppendFormat("[{0},{1},{2}],", now.x, now.y, now.z);
            }
            else
            {
                stringBuilder.AppendFormat("[{0},{1},{2}]\r\n", now.x, now.y, now.z);
                flag = false;
            }
        }while (flag);
        stringBuilder.Append("=================End========================= \r\n");
        Debug.LogFormat("{0}", stringBuilder.ToString());
    }
Esempio n. 2
0
    // Start is called before the first frame update
    void Start()
    {
        validPositions = new HashSet <Vector3Int>();
        BoundsInt.PositionEnumerator positions = tilemap.cellBounds.allPositionsWithin;
        // float count = 0;
        while (positions.MoveNext())
        {
            if (tilemap.HasTile(positions.Current))
            {
                // count++;
                // Debug.Log(positions.Current);
                validPositions.Add(new Vector3Int(positions.Current.x, positions.Current.y, 0));
            }
        }
        var validPosItr = validPositions.GetEnumerator();

        validPosItr.MoveNext();
        player.position = validPosItr.Current;
        validPosItr.MoveNext();
        targetPos = validPosItr.Current;
        Debug.Log(validPosItr.Current);

        // Debug.Log("total valid tiles: " + count);
        // Debug.Log("all position found!");
        // displaySet(validPositions);
    }
Esempio n. 3
0
    // TODO make this work wtih all the different tilemap layers.
    private void PopulateContainingCells()
    {
        // TODO throw error when not spawned?
        if (!IsSpawned)
        {
            return;
        }

        Tilemap tm = LandMap;

        NorthernBounds = -10000000;
        SouthernBounds = 10000000;
        EasternBounds  = -10000000;
        WesternBounds  = 10000000;

        // Get an enumerator for all the cells within this area.
        BoundsInt.PositionEnumerator pe = tm.cellBounds.allPositionsWithin;
        do
        {
            if (tm.GetSprite(pe.Current) != null)
            {
                Vector2Int coords = WorldGridHolder.GetCell(pe.Current).Coordinates;
                localContainingCellCoordinates.Add(coords);
                if (coords.x > NorthernBounds)
                {
                    NorthernBounds = coords.x;
                }
                if (coords.x < SouthernBounds)
                {
                    SouthernBounds = coords.x;
                }
                if (coords.y > EasternBounds)
                {
                    EasternBounds = coords.y;
                }
                if (coords.y < WesternBounds)
                {
                    WesternBounds = coords.y;
                }

                #region Debug
                if (DebugSettings.DebugZone)
                {
                    tm.SetTile(new Vector3Int(coords.x, coords.y, 0), DebugSettings.DebugZoneTile);
                }
                #endregion
            }
        } while (pe.MoveNext());

        // Now that we have the localized values, let's generalize them for global usage.
        foreach (Vector2Int localCellCorrdinate in localContainingCellCoordinates)
        {
            containingCellCoordinates.Add(new Vector2Int(
                                              localCellCorrdinate.x + spawnLocation.x,
                                              localCellCorrdinate.y + spawnLocation.y));
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Ayuda visual para el ataque
    /// </summary>
    public void attack()
    {
        Vector3Int currentPosition = tilemap.WorldToCell(currentChar.transform.position);

        attackArea = currentChar.getMoveArea(currentPosition);
        BoundsInt.PositionEnumerator tiles = attackArea.allPositionsWithin;
        tiles = tiles.GetEnumerator();
        while (tiles.MoveNext())
        {
            if (!currentPosition.Equals(tiles.Current))
            {
                tilemap.RemoveTileFlags(tiles.Current, TileFlags.LockColor);
                tilemap.SetColor(tiles.Current, new Color(1, 0, 0, 0.8f));
            }
        }
    }
Esempio n. 5
0
    /// <summary>
    /// Ayuda visual para movimiento del jugador
    /// </summary>
    public void movement()
    {
        Vector3Int currentPosition = tilemap.WorldToCell(currentChar.transform.position);

        move = currentChar.getMoveArea(currentPosition);
        BoundsInt.PositionEnumerator tiles = move.allPositionsWithin;
        tiles = tiles.GetEnumerator();
        while (tiles.MoveNext())
        {
            if (availableTile(tiles.Current) && (tiles.Current.x - currentPosition.x == 0 || tiles.Current.y - currentPosition.y == 0))
            {
                tilemap.RemoveTileFlags(tiles.Current, TileFlags.LockColor);
                tilemap.SetColor(tiles.Current, new Color(0, 0, 1, 0.8f));
            }
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Metodo para eliminar toda ayuda visual
    /// </summary>
    public void clearVisualHelp()
    {
        BoundsInt.PositionEnumerator tiles = new BoundsInt.PositionEnumerator();
        switch (currentChar.getState())
        {
        case StateManager.move:
            tiles = move.allPositionsWithin;
            break;

        case StateManager.attack:
            tiles = attackArea.allPositionsWithin;
            break;
        }
        tiles = tiles.GetEnumerator();

        while (tiles.MoveNext())
        {
            tilemap.SetColor(tiles.Current, defaultTileColor);
        }
    }
Esempio n. 7
0
    /// <summary>
    /// Metodo para colocar los triggers de sala en las entradas de una sala
    /// </summary>
    /// <param name="tile"></param>
    /// <param name="tilemap"></param>
    public void setTriggers(GameObject tile, ref Tilemap tilemap)
    {
        GameObject clon = tile;

        for (int i = 0; i < sides.Length; ++i)
        {
            //si el lado tiene camino se comprueba donde colocar el trigger
            if (sides[i])
            {
                BoundsInt wall = getTriggerPosition(i);
                BoundsInt.PositionEnumerator iterator = wall.allPositionsWithin;
                iterator = iterator.GetEnumerator();
                while (iterator.MoveNext())
                {
                    if (tilemap.GetTile(iterator.Current) != null && tilemap.GetTile(iterator.Current).name.Contains("Floor"))
                    {
                        clon.transform.position = tilemap.GetCellCenterWorld(iterator.Current);
                        GameObject.Instantiate(clon);
                    }
                }
            }
        }
    }