예제 #1
0
    public override void RefreshTile(Vector3Int position, ITilemap tilemap)
    {
        base.RefreshTile(position, tilemap);
        for (int x = -1; x < 2; x++)
        {
            for (int y = -1; y < 2; y++)
            {
                if (x == 0 && y == 0)
                {
                    continue;
                }
                Vector3Int tmp_pos  = position + new Vector3Int(x, y, 0);
                A3_Tile    tmp_Tile = tilemap.GetTile(tmp_pos) as A3_Tile;
                if (tmp_Tile != null //&& tmp_Tile.id_tile_type == this.id_tile_type
                    )
                {
                    tilemap.RefreshTile(tmp_pos);
                }
            }
        }

        Vector3Int tmp_pos1 = position;

        while (true)
        {
            tmp_pos1 += Vector3Int.up;
            A3_Tile tmp_Tile = tilemap.GetTile(tmp_pos1) as A3_Tile;
            if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
            {
                tilemap.RefreshTile(tmp_pos1 + Vector3Int.right);
                tilemap.RefreshTile(tmp_pos1 + Vector3Int.left);
                tilemap.RefreshTile(tmp_pos1);
            }
            else
            {
                break;
            }
        }
        tmp_pos1 = position;
        while (true)
        {
            tmp_pos1 += Vector3Int.down;
            A3_Tile tmp_Tile = tilemap.GetTile(tmp_pos1) as A3_Tile;
            if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
            {
                tilemap.RefreshTile(tmp_pos1 + Vector3Int.right);
                tilemap.RefreshTile(tmp_pos1 + Vector3Int.left);
                tilemap.RefreshTile(tmp_pos1);
            }
            else
            {
                break;
            }
        }
    }
    public static void Generate_A3_Wall_Tile(string source_File_Path, string tile_path, Dictionary <byte, int> rule_tiles, int wBlock)
    {
        //create the auto tile
        string atile_path = string.Format(@"{0}/_{1}/{2}.asset", Tiles_Utility.Auto_Tile_Folder_Path, Path.GetFileNameWithoutExtension(source_File_Path),
                                          Path.GetFileNameWithoutExtension(tile_path));
        string dir = string.Format(@"{0}/_{1}", Tiles_Utility.Auto_Tile_Folder_Path, Path.GetFileNameWithoutExtension(source_File_Path));

        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }
        A3_Tile atile = ScriptableObject.CreateInstance <A3_Tile>();

        if (File.Exists(atile_path))
        {
            atile = AssetDatabase.LoadAssetAtPath <A3_Tile>(atile_path);
        }
        EditorUtility.SetDirty(atile);

        if (atile != null)
        {
            atile.tile_Variants = new Sprite[rule_tiles.Count];
            string[] tiles = Directory.GetFiles(tile_path, "*.png");
            foreach (var fTile in tiles)
            {
                //set the image importer setting
                Tiles_Utility.Set_Impoter_Settings(fTile, wBlock);
            }

            int cc = 0;
            //StreamWriter myFile = new StreamWriter(@"C:\tmp\file.txt");
            foreach (var kvp in rule_tiles)
            {
                Sprite tmp = AssetDatabase.LoadAssetAtPath <Sprite>(tiles[kvp.Value]);
                if (cc == 0) //setting the sprite for the tile palette
                {
                    cc++;
                    atile.sprite  = tmp;
                    atile.preview = tmp;
                }
                atile.tile_Variants[kvp.Key] = tmp;
                //myFile.WriteLine(string.Format("{0},{1}", kvp.Key, kvp.Value));
            }
            //myFile.Close();
        }
        if (File.Exists(atile_path))
        {
            AssetDatabase.SaveAssets();
        }
        else
        {
            AssetDatabase.CreateAsset(atile, atile_path);
        }
    }
    public static void Generate_A3_Wall_tile_SS(string source_File_Path, string tile_path, Dictionary <byte, int> rule_tiles)
    {
        //create the auto tile
        string atile_path = string.Format(@"{0}/_{1}/{2}.asset", Tiles_Utility.Auto_Tile_Folder_Path, Path.GetFileNameWithoutExtension(source_File_Path),
                                          Path.GetFileNameWithoutExtension(tile_path));
        string dir = string.Format(@"{0}/_{1}", Tiles_Utility.Auto_Tile_Folder_Path, Path.GetFileNameWithoutExtension(source_File_Path));

        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }
        //A2_Tile atile = new A2_Tile();
        A3_Tile atile = ScriptableObject.CreateInstance <A3_Tile>();

        if (File.Exists(atile_path))
        {
            atile = AssetDatabase.LoadAssetAtPath <A3_Tile>(atile_path);
        }
        EditorUtility.SetDirty(atile);

        if (atile != null)
        {
            atile.tile_Variants = new Sprite[rule_tiles.Count];
            object[] vars = AssetDatabase.LoadAllAssetsAtPath(tile_path);

            int cc = 0;
            foreach (var kvp in rule_tiles)
            {
                Sprite tmp = vars[kvp.Value + 1] as Sprite;
                if (cc == 0) //setting the sprite for the tile palette
                {
                    cc++;
                    atile.sprite  = tmp;
                    atile.preview = tmp;
                }
                atile.tile_Variants[kvp.Key] = tmp;
            }
        }
        if (File.Exists(atile_path))
        {
            AssetDatabase.SaveAssets();
        }
        else
        {
            AssetDatabase.CreateAsset(atile, atile_path);
        }
    }
예제 #4
0
    protected override byte Compute_Neighbours(Vector3Int pos, ITilemap map)
    {
        int res = 0;

        Vector3Int tmp_pos  = pos + Vector3Int.right + Vector3Int.up;
        A3_Tile    tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;

        //if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        //    res |= (1 << 0);

        tmp_pos = pos;
        while (true)
        {
            tmp_pos  = tmp_pos + Vector3Int.up; //top
            tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;

            if (tmp_Tile == null || tmp_Tile.id_tile_type != this.id_tile_type)
            {
                tmp_pos += Vector3Int.down;
                //Debug.Log(tmp_pos);
                A3_Tile tmp_Tile_r = map.GetTile(tmp_pos + Vector3Int.right) as A3_Tile; //right
                right_side = !(tmp_Tile_r != null && tmp_Tile_r.id_tile_type == this.id_tile_type);

                //A3_Tile tmp_Tile_ru = map.GetTile(tmp_pos + Vector3Int.right + Vector3Int.up) as A3_Tile; //right-up
                //right_side = !((tmp_Tile_r != null && tmp_Tile_r.id_tile_type == this.id_tile_type) &&
                //    (tmp_Tile_ru != null && tmp_Tile_ru.id_tile_type == this.id_tile_type && !tmp_Tile_ru.left_side));

                A3_Tile tmp_Tile_l = map.GetTile(tmp_pos + Vector3Int.left) as A3_Tile; //left
                left_side = !(tmp_Tile_l != null && tmp_Tile_l.id_tile_type == this.id_tile_type);

                //A3_Tile tmp_Tile_lu = map.GetTile(tmp_pos + Vector3Int.left + Vector3Int.up) as A3_Tile; //left-up

                break;
            }
        }

        tmp_pos  = pos + Vector3Int.up; //down
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            res |= (1 << 1);
        }

        tmp_pos  = pos + Vector3Int.down; //down
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            res |= (1 << 6);
        }

        tmp_pos  = pos + Vector3Int.right; //right
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            if (!right_side)
            {
                res |= (1 << 3);
            }
        }

        tmp_pos  = pos + Vector3Int.left; //left
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            if (!left_side)
            {
                res |= (1 << 4);
            }
        }

        return((byte)res);
    }
예제 #5
0
    protected override byte Compute_Neighbours(Vector3Int pos, ITilemap map)
    {
        int res            = 0;
        int tmp_right_side = -1;
        int tmp_left_side  = -1;

        Vector3Int tmp_pos  = pos;
        A3_Tile    tmp_Tile = null;

        while (true)
        {
            //going up to find a different kind of tile
            tmp_pos  = tmp_pos + Vector3Int.up; //top
            tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;

            //if there is no tile or the tile is different
            if (tmp_Tile == null || tmp_Tile.id_tile_type != this.id_tile_type)
            {
                tmp_pos += Vector3Int.down;
                //get right and right-up
                A3_Tile tmp_Tile_r  = map.GetTile(tmp_pos + Vector3Int.right) as A3_Tile;                 //right
                A3_Tile tmp_Tile_ru = map.GetTile(tmp_pos + Vector3Int.right + Vector3Int.up) as A3_Tile; //right-up
                if (tmp_Tile_r != null && tmp_Tile_r.id_tile_type == this.id_tile_type)
                {
                    if (tmp_Tile_ru == null || tmp_Tile_ru.id_tile_type != this.id_tile_type)
                    {
                        tmp_right_side = 0;
                    }
                    else
                    {
                        tmp_right_side = -1;
                    }
                }
                else
                {
                    tmp_right_side = 1;
                }

                //get left and left-up
                A3_Tile tmp_Tile_l  = map.GetTile(tmp_pos + Vector3Int.left) as A3_Tile;                 //left
                A3_Tile tmp_Tile_lu = map.GetTile(tmp_pos + Vector3Int.left + Vector3Int.up) as A3_Tile; //left-up
                if (tmp_Tile_l != null && tmp_Tile_l.id_tile_type == this.id_tile_type)
                {
                    if (tmp_Tile_lu == null || tmp_Tile_lu.id_tile_type != this.id_tile_type)
                    {
                        tmp_left_side = 0;
                    }
                    else
                    {
                        tmp_left_side = -1;
                    }
                }
                else
                {
                    tmp_left_side = 1;
                }
                break;
            }
        }

        tmp_pos = pos + Vector3Int.right + Vector3Int.up;
        A3_Tile tmp_TileRU = map.GetTile(tmp_pos) as A3_Tile; //right-up
        bool    rTRU       = tmp_TileRU != null && tmp_TileRU.id_tile_type == this.id_tile_type;

        if (rTRU && tmp_right_side == -1)
        {
            tmp_right_side = 0;
        }

        tmp_pos = pos + Vector3Int.left + Vector3Int.up;
        A3_Tile tmp_TileLU = map.GetTile(tmp_pos) as A3_Tile; //left-up
        bool    rTLU       = tmp_TileLU != null && tmp_TileLU.id_tile_type == this.id_tile_type;

        if (rTLU && tmp_left_side == -1)
        {
            tmp_left_side = 0;
        }

        tmp_pos = pos + Vector3Int.up; //up
        A3_Tile tmp_TileU = map.GetTile(tmp_pos) as A3_Tile;
        bool    rTU       = tmp_TileU != null && tmp_TileU.id_tile_type == this.id_tile_type;

        if (rTU)
        {
            res |= (1 << 1);
        }

        tmp_pos = pos + Vector3Int.down; //down
        A3_Tile tmp_TileD = map.GetTile(tmp_pos) as A3_Tile;
        bool    rTD       = tmp_TileD != null && tmp_TileD.id_tile_type == this.id_tile_type;

        if (rTD)
        {
            res |= (1 << 6);
        }
        else
        {
            if (tmp_TileU == null || tmp_TileU.id_tile_type != this.id_tile_type)
            {
                if (tmp_left_side != -1)
                {
                    tmp_left_side = -1;
                }
                if (tmp_right_side != -1)
                {
                    tmp_right_side = -1;
                }
            }
        }

        tmp_pos = pos + Vector3Int.down + Vector3Int.right; //down-Right
        A3_Tile tmp_TileDR = map.GetTile(tmp_pos) as A3_Tile;
        bool    rTDR       = tmp_TileDR != null && tmp_TileDR.id_tile_type == this.id_tile_type;

        tmp_pos = pos + Vector3Int.down + Vector3Int.left; //down-Right
        A3_Tile tmp_TileLR = map.GetTile(tmp_pos) as A3_Tile;
        bool    rTDL       = tmp_TileLR != null && tmp_TileLR.id_tile_type == this.id_tile_type;

        tmp_pos = pos + Vector3Int.right; //right
        A3_Tile tmp_TileR = map.GetTile(tmp_pos) as A3_Tile;
        bool    rTR       = tmp_TileR != null && tmp_TileR.id_tile_type == this.id_tile_type;

        if (tmp_right_side == -1)
        {
            if (rTR)
            {
                res |= (1 << 3);
            }
        }
        else
        {
            res |= (tmp_right_side == 1 ||
                    (!rTU && rTRU && !rTDR) ||
                    (rTU && rTRU && !rTR && !rTDR && !rTD) ||
                    !rTR ? 0 : 1) << 3;
        }

        tmp_pos = pos + Vector3Int.left; //left
        A3_Tile tmp_TileL = map.GetTile(tmp_pos) as A3_Tile;
        bool    rTL       = tmp_TileL != null && tmp_TileL.id_tile_type == this.id_tile_type;

        if (tmp_left_side == -1)
        {
            if (rTL)
            {
                res |= (1 << 4);
            }
        }
        else
        {
            res |= (tmp_left_side == 1 ||
                    (!rTU && rTLU && !rTDL) ||
                    (rTU && rTLU && !rTL && !rTDL && !rTD) ||
                    !rTL ? 0 : 1) << 4;
        }
        return((byte)res);
    }
예제 #6
0
    protected override byte Compute_Neighbours(Vector3Int pos, ITilemap map)
    {
        int res            = 0;
        int tmp_right_side = -1;
        int tmp_left_side  = -1;

        Vector3Int tmp_pos  = pos;
        A3_Tile    tmp_Tile = null;

        while (true)
        {
            tmp_pos  = tmp_pos + Vector3Int.up; //top
            tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;

            if (tmp_Tile == null || tmp_Tile.id_tile_type != this.id_tile_type)
            {
                tmp_pos += Vector3Int.down;

                A3_Tile tmp_Tile_r  = map.GetTile(tmp_pos + Vector3Int.right) as A3_Tile;                 //right
                A3_Tile tmp_Tile_ru = map.GetTile(tmp_pos + Vector3Int.right + Vector3Int.up) as A3_Tile; //right-up
                if ((tmp_Tile_r != null && tmp_Tile_r.id_tile_type == this.id_tile_type) &&
                    (tmp_Tile_ru == null || tmp_Tile_ru.id_tile_type != this.id_tile_type) && tmp_right_side == -1)
                {
                    tmp_right_side = 0;
                }
                else
                {
                    tmp_right_side = 1;
                }

                A3_Tile tmp_Tile_l  = map.GetTile(tmp_pos + Vector3Int.left) as A3_Tile;                 //left
                A3_Tile tmp_Tile_lu = map.GetTile(tmp_pos + Vector3Int.left + Vector3Int.up) as A3_Tile; //left-up
                if ((tmp_Tile_l != null && tmp_Tile_l.id_tile_type == this.id_tile_type) &&
                    (tmp_Tile_lu == null || tmp_Tile_lu.id_tile_type != this.id_tile_type) && tmp_left_side == -1)
                {
                    tmp_left_side = 0;
                }
                else
                {
                    tmp_left_side = 1;
                }
                break;
            }
        }

        tmp_pos  = pos + Vector3Int.right + Vector3Int.up;
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile; //right-up
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type && tmp_right_side == -1)
        {
            tmp_right_side = 0;
        }

        tmp_pos  = pos + Vector3Int.left + Vector3Int.up;
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile; //left-up
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type && tmp_left_side == -1)
        {
            tmp_left_side = 0;
        }

        tmp_pos  = pos + Vector3Int.up; //up
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            res |= (1 << 1);
        }

        tmp_pos  = pos + Vector3Int.down; //down
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            res |= (1 << 6);
        }

        if (tmp_right_side == -1)
        {
            tmp_pos  = pos + Vector3Int.right; //right
            tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
            if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
            {
                res |= (1 << 3);
            }
        }
        else
        {
            res |= (tmp_right_side == 1 ? 0 : 1 << 3);
        }

        if (tmp_left_side == -1)
        {
            tmp_pos  = pos + Vector3Int.left; //left
            tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
            if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
            {
                res |= (1 << 4);
            }
        }
        else
        {
            res |= (tmp_left_side == 1 ? 0 : 1 << 4);
        }
        return((byte)res);
    }
예제 #7
0
    protected byte Compute_Neighbours1(Vector3Int pos, ITilemap map)
    {
        int res = 0;

        right_side = -1;
        left_side  = -1;
        int tmp_right_side = -1;
        int tmp_left_side  = -1;

        Vector3Int tmp_pos  = pos;
        A3_Tile    tmp_Tile = null;

        //while (true)
        //{
        //    tmp_pos = tmp_pos + Vector3Int.up; //top
        //    tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;

        //    if(tmp_Tile == null || tmp_Tile.id_tile_type != this.id_tile_type)
        //    {
        //        tmp_pos += Vector3Int.down;
        //        Debug.Log(tmp_pos);

        //        A3_Tile tmp_Tile_r = map.GetTile(tmp_pos + Vector3Int.right) as A3_Tile; //right
        //        if (tmp_Tile_r != null && tmp_Tile_r.id_tile_type == this.id_tile_type)
        //            right_side = -1;
        //        //right_side = !(tmp_Tile_r != null && tmp_Tile_r.id_tile_type == this.id_tile_type);

        //        //right_side = !((tmp_Tile_r != null && tmp_Tile_r.id_tile_type == this.id_tile_type) &&
        //        //    !(tmp_Tile_ru != null && tmp_Tile_ru.id_tile_type == this.id_tile_type));

        //        A3_Tile tmp_Tile_l = map.GetTile(tmp_pos + Vector3Int.left) as A3_Tile; //left
        //        if (tmp_Tile_l != null && tmp_Tile_l.id_tile_type == this.id_tile_type)
        //            left_side = -1;
        //        //left_side = !(tmp_Tile_l != null && tmp_Tile_l.id_tile_type == this.id_tile_type);

        //        //A3_Tile tmp_Tile_lu = map.GetTile(tmp_pos + Vector3Int.left + Vector3Int.up) as A3_Tile; //left-up
        //        break;
        //    }
        //}

        tmp_pos  = pos + Vector3Int.right + Vector3Int.up;
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile; //right-up
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            tmp_right_side = 0;
        }

        tmp_pos  = pos + Vector3Int.left + Vector3Int.up;
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile; //left-up
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            tmp_left_side = 0;
        }

        tmp_pos  = pos + Vector3Int.up; //up
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            //Debug.Log(string.Format("{2} {0} {1}", tmp_Tile.left_side, tmp_Tile.right_side, tmp_pos));
            if (tmp_Tile.left_side != -1)
            {
                tmp_left_side = tmp_Tile.left_side;
            }

            if (tmp_Tile.right_side != -1)
            {
                tmp_right_side = tmp_Tile.right_side;
            }
            res |= (1 << 1);
        }

        tmp_pos  = pos + Vector3Int.down; //down
        tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
        if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
        {
            res |= (1 << 6);
        }

        if (tmp_right_side == -1)
        {
            tmp_pos  = pos + Vector3Int.right; //right
            tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
            if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
            {
                res |= (1 << 3);
                //else if(right_side == true) res |= (1 << 3);
            }
        }
        else
        {
            res |= (tmp_right_side == 1 ? 0 : 1 << 3);
        }

        if (tmp_left_side == -1)
        {
            tmp_pos  = pos + Vector3Int.left; //left
            tmp_Tile = map.GetTile(tmp_pos) as A3_Tile;
            if (tmp_Tile != null && tmp_Tile.id_tile_type == this.id_tile_type)
            {
                res |= (1 << 4);
                // else if (left_side == 1) res |= (1 << 4);
            }
        }
        else
        {
            res |= (tmp_left_side == 1 ? 0 : 1 << 4);
        }
        right_side = tmp_right_side;
        left_side  = tmp_left_side;
        return((byte)res);
    }