Example #1
0
    public void PlaceBoundaries(GameAreaData areaData)
    {
        EdgePointDistanceY = (float)Math.Round(areaData.Height_World / 2, 2);
        EdgePointDistanceX = (float)Math.Round(areaData.Width_World / 2, 2);
        var SidesEdgePoints     = new Vector2[] { new Vector2(0, -EdgePointDistanceY), new Vector2(0, EdgePointDistanceY) };
        var TopBottomEdgePoints = new Vector2[] { new Vector2(-EdgePointDistanceX, 0), new Vector2(EdgePointDistanceX, 0) };

        //LEFT Border
        LeftEdge.transform.position = new Vector3(areaData.CornersWorld[0].x, (float)areaData.Middle_Y, 1);
        LeftEdge.points             = SidesEdgePoints;

        //RIGHT Border
        RightEdge.transform.position = new Vector3(areaData.CornersWorld[2].x, (float)areaData.Middle_Y, 1);
        RightEdge.points             = SidesEdgePoints;

        //TOP Border
        TopEdge.transform.position = new Vector3((float)areaData.Middle_X, areaData.CornersWorld[1].y, 1);
        TopEdge.points             = TopBottomEdgePoints;

        //BOTTOM Border
        BottomEdge.transform.position = new Vector3((float)areaData.Middle_X, areaData.CornersWorld[0].y, 1);
        BottomEdge.points             = TopBottomEdgePoints;

        //Preventer
        InfinityLockPreventer.transform.position   = areaData.CornersWorld[2];
        InfinityLockPreventer.transform.localScale = BallCollider.transform.localScale;
        InfinityLockPreventer.radius = BallCollider.radius * 0.7f;
        InfinityLockPreventer.offset = BallCollider.offset;
    }
    public void InitialGameAreaCalculations()
    {
        boundariesLocate = GetComponent <BoundariesLocate>();

        Canvas.ForceUpdateCanvases();
        gameAreaData = new GameAreaData(GameArea);

        var gameAreaWidth        = gameAreaData.Width_World;
        var totalBlockSpaceInRaw = gameAreaWidth;
        var singleBlockSpace     = (float)totalBlockSpaceInRaw / BlockInRawCount;

        tilemap.layoutGrid.transform.position = gameAreaData.CornersWorld[1];
        tilemap.transform.position            = gameAreaData.CornersWorld[1];

        var blocks    = new List <GameObject>();
        var prevState = new Dictionary <GameObject, Vector3Int>();

        for (int i = 0; i < tilemap.transform.childCount; i++)
        {
            var child = tilemap.transform.GetChild(i);
            blocks.Add(child.gameObject);
            var cell = tilemap.layoutGrid.WorldToCell(child.transform.position);
            prevState.Add(child.gameObject, cell);
        }

        tilemap.layoutGrid.cellSize = new Vector3(singleBlockSpace, singleBlockSpace, 0);

        foreach (var block in blocks)
        {
            block.transform.localScale = new Vector3(singleBlockSpace, singleBlockSpace, 0);
            block.transform.position   = tilemap.GetCellCenterWorld(prevState[block]);
        }
        ActiveBall.transform.localScale = new Vector3(singleBlockSpace, singleBlockSpace, 0);
        BallLauncher.CreateBalls();
        boundariesLocate.PlaceBoundaries(gameAreaData);
    }