Beispiel #1
0
    public void SetPointByScreenNormalizedCoords()
    {
        Vector2 size  = UnityCustoms.GetGameWindowSize();
        float   x_pos = x_screen_coord * size.x;
        float   y_pos = y_screen_coord * size.y;

        point    = cam.ScreenToWorldPoint(new Vector3(x_pos, y_pos, 0));
        point.z += 2;
    }
Beispiel #2
0
    public void DrawScaledCubeInScreenCenter()
    {
        if (squarePoints == null || squarePoints.Length == 0)
        {
            squarePoints = new Vector3[4];
        }

        float c_to_center = 0f;
        var   size        = UnityCustoms.GetGameWindowSize();

        if (size.x > size.y)
        {
            if (proportion < size.x / size.y)
            {
                squarePoints[0] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f - proportion * size.y / 2f, 0 + c_to_center, 2f));
                squarePoints[1] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f + proportion * size.y / 2f, 0 + c_to_center, 2f));
                squarePoints[2] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f + proportion * size.y / 2f, size.y - c_to_center, 2f));
                squarePoints[3] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f - proportion * size.y / 2f, size.y - c_to_center, 2f));
            }
            else
            {
                squarePoints[0] = cam.ScreenToWorldPoint(new Vector3(0 + c_to_center, size.y / 2f - size.x / (2f * proportion), 2f));
                squarePoints[1] = cam.ScreenToWorldPoint(new Vector3(0 + c_to_center, size.y / 2f + size.x / (2f * proportion), 2f));
                squarePoints[2] = cam.ScreenToWorldPoint(new Vector3(size.x - c_to_center, size.y / 2f + size.x / (2f * proportion), 2f));
                squarePoints[3] = cam.ScreenToWorldPoint(new Vector3(size.x - c_to_center, size.y / 2f - size.x / (2f * proportion), 2f));
            }
        }
        else
        {
            if (proportion > size.x / size.y)
            {
                squarePoints[0] = cam.ScreenToWorldPoint(new Vector3(0 + c_to_center, size.y / 2f - size.x / (2f * proportion), 2f));
                squarePoints[1] = cam.ScreenToWorldPoint(new Vector3(0 + c_to_center, size.y / 2f + size.x / (2f * proportion), 2f));
                squarePoints[2] = cam.ScreenToWorldPoint(new Vector3(size.x - c_to_center, size.y / 2f + size.x / (2f * proportion), 2f));
                squarePoints[3] = cam.ScreenToWorldPoint(new Vector3(size.x - c_to_center, size.y / 2f - size.x / (2f * proportion), 2f));
            }
            else
            {
                squarePoints[0] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f - proportion * size.y / 2f, 0 + c_to_center, 2f));
                squarePoints[1] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f + proportion * size.y / 2f, 0 + c_to_center, 2f));
                squarePoints[2] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f + proportion * size.y / 2f, size.y - c_to_center, 2f));
                squarePoints[3] = cam.ScreenToWorldPoint(new Vector3(size.x / 2f - proportion * size.y / 2f, size.y - c_to_center, 2f));
            }
        }
    }