Exemplo n.º 1
0
    private bool HasWall(Vector3Int position, Vector3Int direction, Quaternion rotation, Tilemap tilemap)
    {
        TileBase      tile = tilemap.GetTile(position + (rotation * direction).RoundToInt());
        ConnectedTile t    = tile as ConnectedTile;

        return(t != null && t.connectCategory == ConnectCategory.Walls);
    }
Exemplo n.º 2
0
    private bool HasSameTile(Vector3Int position, Vector3Int direction, Quaternion rotation, ITilemap tilemap)
    {
        TileBase tile = tilemap.GetTile(position + (rotation * direction).RoundToInt());

        if (tile == null)
        {
            return(false);
        }

        switch (connectType)
        {
        case ConnectType.ToAll:
            return(true);

        case ConnectType.ToSameCategory:
            ConnectedTile t = tile as ConnectedTile;
            return(t != null && t.connectCategory == connectCategory);

        case ConnectType.ToSelf:
            return(tile == this);

        default:
            throw new ArgumentOutOfRangeException();
        }
    }
Exemplo n.º 3
0
    public static void CreateTable()
    {
        ConnectedTile tile = TileBuilder.CreateTile <ConnectedTile>(LayerType.Objects);

        tile.texturePath     = "Tables";
        tile.connectCategory = ConnectCategory.Tables;
        tile.connectType     = ConnectType.ToSameCategory;

        TileBuilder.CreateAsset(tile, "TableTile");
    }
Exemplo n.º 4
0
    public static void CreateWindow()
    {
        ConnectedTile tile = TileBuilder.CreateTile <ConnectedTile>(LayerType.Windows);

        tile.texturePath     = "Windows";
        tile.connectCategory = ConnectCategory.Windows;
        tile.connectType     = ConnectType.ToSameCategory;

        TileBuilder.CreateAsset(tile, "WindowTile");
    }
Exemplo n.º 5
0
    private static void Initialize()
    {
        // Generate a purely white 1x1 texture and convert it to a sprite
        Texture2D rend = new Texture2D(1, 1);

        rend.SetPixel(0, 0, Color.white);
        white      = Sprite.Create(rend, new Rect(0, 0, 1, 1), Vector2.zero, .1F);
        white.name = "White";

        // Load all the tiles from "Resources/${TILES_PATH}"
        BasicTile[] tiles = Resources.LoadAll <BasicTile>(TILES_PATH);

        foreach (BasicTile tile in tiles)
        {
            if (tokens.Contains(tile.name))
            {
                Debug.LogWarning(tile.name + " already exists, skipping...");
                continue;
            }

            int spriteWidth  = (int)tile.sprite.rect.width;
            int spriteHeight = (int)tile.sprite.rect.height;

            if (!ValidateSprite(tile.sprite))
            {
                continue;
            }

            tokens.Add(tile.name);

            sprites[tile.name]    = ChopSprite(tile.sprite);
            frameRates[tile.name] = tile.fps;

            if (tile.spriteVariations != null)
            {
                for (int i = 0; i < tile.spriteVariations.Length; i++)
                {
                    if (!ValidateSprite(tile.spriteVariations[i], errorPrefix: "Sprite Variation"))
                    {
                        continue;
                    }
                    sprites[tile.name + "#" + i] = ChopSprite(tile.spriteVariations[i]);
                }
            }

            if (tile is ConnectedTile)
            {
                ConnectedTile ct = (ConnectedTile)tile;

                Sprite[] u, d, l, r;
                if (ValidateSprite(ct.up))
                {
                    u = ChopSprite(ct.up, 0.5F);

                    if (ct.useRotation)
                    {
                        d = l = r = u;

                        rotations[tile.name + "$u"] = ct.rotationUp;
                        rotations[tile.name + "$d"] = ct.rotationDown;
                        rotations[tile.name + "$l"] = ct.rotationLeft;
                        rotations[tile.name + "$r"] = ct.rotationRight;
                    }
                    else
                    {
                        if (ValidateSprite(ct.down, errorSuffix: "using UP..."))
                        {
                            d = ChopSprite(ct.down, 0.5F);
                        }
                        else
                        {
                            d = u;
                        }

                        if (ValidateSprite(ct.left, errorSuffix: "using UP..."))
                        {
                            l = ChopSprite(ct.left, 0.5F);
                        }
                        else
                        {
                            l = u;
                        }

                        if (ValidateSprite(ct.right, errorSuffix: "using UP..."))
                        {
                            r = ChopSprite(ct.right, 0.5F);
                        }
                        else
                        {
                            r = u;
                        }
                    }

                    sprites[tile.name + "$u"] = u;
                    sprites[tile.name + "$d"] = d;
                    sprites[tile.name + "$l"] = l;
                    sprites[tile.name + "$r"] = r;
                }
            }

            if (tile.modifiers.spawnables != null)
            {
                List <Sprite> sb = new List <Sprite>();

                foreach (BasicTile.Modifier.Spawnable spawnable in tile.modifiers.spawnables)
                {
                    if (spawnable.chop)
                    {
                        spriteWidth  = (int)spawnable.sprite.rect.width;
                        spriteHeight = (int)spawnable.sprite.rect.height;
                        float cellSize = spawnable.cellSize;

                        if (spriteWidth % spawnable.cellSize != 0 || spriteHeight % spawnable.cellSize != 0)
                        {
                            Debug.LogError("Spawnable " + spawnable.name + " sprite size not evenly divisible by cell size, skipping...");
                            continue;
                        }

                        for (int x = 0; x < spriteWidth / spawnable.cellSize; x++)
                        {
                            for (int y = 0; y < spriteHeight / spawnable.cellSize; y++)
                            {
                                sb.Add(Sprite.Create(spawnable.sprite.texture, new Rect(x * cellSize, y * cellSize, cellSize, cellSize), Vector2.zero, spawnable.sprite.pixelsPerUnit));
                                sb.Last().name = spawnable.sprite.name + " cutout " + x * spriteWidth + y;
                            }
                        }
                    }
                    else
                    {
                        sb.Add(spawnable.sprite);
                    }
                }

                spawnables[tile.name] = sb.ToArray();
            }
        }
    }