Exemple #1
0
    // create a new board, destroy old first
    void CreateBoard()
    {
        Debug.Assert(Model.InLevel);
        var level = Model.CurrentLevel;

        Util.Trace(1, "Create board '{0}' level {1} size {2}x{3}",
                   GameDef.GetSetting(OptionSetting.title, "unknown"), Model.CurrentLevelIndex, level.Length, level.Depth);
        var camera     = Camera.main;
        var camerasize = new Vector2(2 * camera.orthographicSize * camera.aspect, 2 * camera.orthographicSize);

        _screentoortho = 2 * camera.orthographicSize / camera.pixelHeight;

        // the size of the board including surroundings
        var boardsize = new Vector3(camerasize.x, camerasize.y) * BoardScale;
        // the rectangle of tiles in the level
        var levelsize = new Vector3Int(level.Width, level.Height, level.Depth);
        // the rectangle of tiles to be displayed
        var displaysize = (_modelinfo.ScreenSize == Vector2Int.zero) ? levelsize
      : Vector3Int.Min(levelsize, new Vector3Int(_modelinfo.ScreenSize.x, _modelinfo.ScreenSize.y, level.Depth));
        // the size of each tile in units
        var scale = Math.Min(boardsize.x / displaysize.x, boardsize.y / displaysize.y);

        _board     = Instantiate(BoardPrefab);
        _boardview = _board.GetComponent <BoardView>();
        _boardview.Setup(boardsize);
        _boardview.CreateTiles(displaysize, scale, level.Width, TilePrefab);
    }