示例#1
0
    private void SetPosition(Transform figure)
    {
        // Take the coordinates of the left, right and top walls and put the figure regarding them

        Debug.Assert(figure);

        FigurePolygon polygon = figure.GetComponent <FigurePolygon>();

        Debug.Assert(polygon);

        float leftWallCenterX  = borders.Left.position.x;
        float rightWallCenterX = borders.Right.position.x;
        float leftWallX        = leftWallCenterX - borders.Left.localScale.x / 2;
        float leftWallWidth    = borders.Left.localScale.x;
        float rightWallX       = rightWallCenterX - borders.Right.localScale.x / 2;

        float areaX     = leftWallX + leftWallWidth;
        float areaWidth = rightWallX - areaX;

        Debug.Assert(areaWidth > 0);
        Vector2 polygonSize = polygon.CalculateSize();

        float figureX = areaX + (areaWidth - polygonSize.x) / 2;

        float topWallCenterY = borders.Top.position.y;
        float topWallY       = topWallCenterY - borders.Top.localScale.y / 2;

        float figureY = topWallY - polygonSize.y;

        figure.position = new Vector3(figureX, figureY, 0);
    }
示例#2
0
    private void SetPosition(GameObject figure)
    {
        // Take the coordinates of the next figure's area and put the figure to the center

        Debug.Assert(figure);

        FigurePolygon polygon = figure.GetComponent <FigurePolygon>();

        Debug.Assert(polygon);
        Vector2 polygonSize = polygon.CalculateSize();

        float polygonCenterX = nextFigureArea.Top.position.x;
        float polygonCenterY = nextFigureArea.Left.position.y;

        float figureX = polygonCenterX - polygonSize.x / 2;
        float figureY = polygonCenterY - polygonSize.y / 2;

        Transform figureT = figure.GetComponent <Transform>();

        figureT.position = new Vector3(figureX, figureY, 0);
    }
示例#3
0
    public Transform Push(FigureData figureData)
    {
        GameObject figure = new GameObject("Next figure");

        figure.AddComponent <FigurePolygon>();
        figure.AddComponent <FigureDataComponent>();
        figure.AddComponent <MeshFilter>();
        figure.AddComponent <MeshRenderer>();
        figure.AddComponent <FigureRotatorY>();

        FigurePolygon polygon = figure.GetComponent <FigurePolygon>();

        polygon.SetPoints(figureData.Points, nextFigureArea.Left.transform.localScale.z);

        FigureDataComponent figureDataStorage = figure.GetComponent <FigureDataComponent>();

        figureDataStorage.Data = figureData;

        Mesh       mesh       = polygon.GetMesh();
        MeshFilter meshFilter = figure.GetComponent <MeshFilter>();

        meshFilter.mesh = mesh;

        MeshRenderer renderer = figure.GetComponent <MeshRenderer>();

        renderer.material.color = figureData.Color;

        SetPosition(figure);

        FigureRotatorY rotator = figure.GetComponent <FigureRotatorY>();
        Vector2        size    = polygon.CalculateSize();
        Vector3        center  = new Vector3(size.x / 2, size.y / 2, 0);

        rotator.SetCenter(figure.transform.position + center);

        return(figure.transform);
    }