コード例 #1
0
    void TileSet()
    {
        List <TileSaveData> tileSaveDataList = new List <TileSaveData>();

        for (int x = 0; x < TileController.x_max_value; x++)
        {
            for (int y = 0; y < TileController.y_max_value; y++)
            {
                TileSaveData tileSaveData = new TileSaveData();
                tileSaveData.pos = new Vector2(x, y);

                if (y < 4 && (x <= 2 || x >= 12))
                {
                    tileSaveData.tile_Type = Tile_Type.None;
                }
                else
                {
                    tileSaveData.tile_Type = Tile_Type.White;
                }

                tileSaveDataList.Add(tileSaveData);
            }
        }

        foreach (var tile in tileSaveDataList)
        {
            tileController.TileCreate(tile);
        }
    }
コード例 #2
0
 public void Add(TileSaveData tile)
 {
     if (data == null)
     {
         CustomLogger.Instance.Error("Start_Saving needs to be called before Add");
     }
     else
     {
         data.Map.Tiles.Add(tile);
     }
 }
コード例 #3
0
    public void TileCreate(TileSaveData tile)
    {
        if (tile.pos.x >= x_max_value || tile.pos.y >= y_max_value)
        {
            return;
        }

        Tile tileobj = Instantiate(Resources.Load <Tile>("InGame/Tile"), tileParant.transform);

        tileobj.pos = tile.pos;
        //tileobj.transform.localPosition = new Vector2(tileobj.pos.x * 55, tileobj.pos.y * 43);
        tileobj.transform.localPosition = new Vector2(tileobj.pos.x * 67, tileobj.pos.y * 55);
        tileobj.TileChange(tile.tile_Type, true);
        tileobj.tileChangeOn = RedTileCheck;
        tiles[(int)tileobj.pos.x, (int)tileobj.pos.y] = tileobj;
        SetNodeData(tileobj);
    }
コード例 #4
0
    public TileMapSaveData CreateSaveDataFromTexutre(Texture2D loadTexture)
    {
        var             allData = Resources.LoadAll("", typeof(LevelTileData)).Cast <LevelTileData>().ToArray();
        TileMapSaveData st      = new TileMapSaveData();

        st.sizeX = loadTexture.width;
        st.sizeY = loadTexture.height;
        TileSaveData[] datas = new TileSaveData[st.sizeX * st.sizeY];
        for (int x = 0; x < loadTexture.width; x++)
        {
            for (int y = 0; y < loadTexture.height; y++)
            {
                datas[x + y * loadTexture.width] = GetDataFromColor(loadTexture.GetPixel(x, y), allData);
            }
        }
        st.tiles = datas;
        return(st);
    }
コード例 #5
0
    private static List <TileSaveData> ExtractTilesSaveData(List <Vector2> gridPositions)
    {
        List <TileSaveData> tilesSaveData = new List <TileSaveData>();

        foreach (Vector2 gridPosition in gridPositions)
        {
            Tile tile = TileGrid.Instance.GetTile(gridPosition);

            TileSaveData tileSaveData = new TileSaveData {
                GridPosition = gridPosition,
                Rotation     = tile.GameObject.transform.rotation,
                TileType     = tile.TileType,
            };

            tilesSaveData.Add(tileSaveData);
        }

        return(tilesSaveData);
    }
コード例 #6
0
 public void Load(TileSaveData saveData)
 {
     color      = saveData.Color;
     savedColor = color;
     effects    = EffectTracker.IDStoEffects(saveData.EffectIDs);
     pins       = saveData.Pins;
     items      = new List <Item>();
     foreach (ItemSaveData isd in saveData.Items)
     {
         items.Add(new Item(isd));
     }
     hints     = saveData.Hints;
     occupants = new List <CharacterSheet>();
     foreach (CharacterSaveData csd in saveData.Occupants)
     {
         occupants.Add(new CharacterSheet(csd));
     }
     isReveialed = saveData.isReveialed;
     isBlock     = saveData.isBlock;
     isVisible   = saveData.isVisible;
 }
コード例 #7
0
    /// <summary>
    /// Creates a new grid and loads the saved tiles into its tilemap
    /// </summary>
    /// <param name="gridPrefab">Prefab of the grid which holds the tilemap as a child of it</param>
    /// <returns>Tilemap. Reference to the loaded tilemap</returns>
    public static Tilemap LoadTilemap(GameObject gridPrefab)
    {
        // Create the grid and get the tilemap
        Tilemap tilemap = Object.Instantiate(gridPrefab).transform.GetChild(0).GetComponent <Tilemap>();

        // Load the bounds for the tilemap
        TilemapBoundsData tilemapBoundsData = SaveSystem.LoadTilemapBounds();
        Vector2Int        botLeft           = tilemapBoundsData.GetBotLeftCorner();
        Vector2Int        topRight          = tilemapBoundsData.GetTopRightCorner();

        // Load each of the tiles
        // Iterate over one column of the tilemap (going up)
        for (int col = botLeft.y; col <= topRight.y; ++col)
        {
            // Iterate over one row of the tilemap (going right)
            for (int row = botLeft.x; row <= topRight.x; ++row)
            {
                // Position of the tile (3D)
                Vector3Int tilePos = new Vector3Int(row, col, 0);

                // Load the data of the tile there
                TileSaveData tileData = SaveSystem.LoadTile(tilePos);
                // Get the key of the tile
                int key = tileData.GetKey();
                // If the key is valid, there is a saved tile there
                if (key >= 0)
                {
                    // Get the tile by the saved key
                    TileBase tile = SaveTilemapController.GetTile(key);
                    // Set the tile at the position to the correct one
                    tilemap.SetTile(tilePos, tile);
                }
            }
        }

        return(tilemap);
    }
コード例 #8
0
ファイル: LevelTilemap.cs プロジェクト: claudyy/TileMap
    public TileMapSaveData GetSaveDataFromTileMap()
    {
        var             size = GetTileMapSize();
        TileMapSaveData st   = new TileMapSaveData();

        st.sizeX = size.x;
        st.sizeY = size.y;
        Vector3Int pos = new Vector3Int(0, 0, 0);

        TileSaveData[] datas   = new TileSaveData[size.x * size.y];
        var            allData = Resources.LoadAll("", typeof(LevelTileData)).Cast <LevelTileData>().ToArray();

        for (int x = 0; x < size.x; x++)
        {
            for (int y = 0; y < size.y; y++)
            {
                pos.x = x;
                pos.y = y;
                datas[x + y * size.x] = new TileSaveData(LoadDataFromTileMap(pos, allData));
            }
        }
        st.tiles = datas;
        return(st);
    }
コード例 #9
0
ファイル: Tile.cs プロジェクト: CravemobAidenYang/Roguelike
    public void ApplySaveData(TileSaveData data)
    {
        _State = data.state;
        _SprIndex = data.sprIndex;
        _IsVisited = data.isVisited;

        if(IsWall)
        {
            _SprRenderer.sprite = TileSpriteManager.Instance.GetWallSpriteFromIndex(_SprIndex);
        }
        else if(IsExit)
        {
            _SprRenderer.sprite = TileSpriteManager.Instance.GetExitSprite();
        }
        else
        {
            _SprRenderer.sprite = TileSpriteManager.Instance.GetGroundSpriteFromIndex(_SprIndex);
        }
    }