Example #1
0
    private void HandleCommandImage(ref UiCommand command)
    {
        string url = imageSystem.GetImageUrl(command.imageId);

        if (string.IsNullOrEmpty(url))
        {
            draw2D.FillRect(ToSurfaceRect(command.rect), Color.gray);
        }
        else
        {
            Texture2D tex = imageLoader.GetOrRequest(url);
            if (tex == null)
            {
                draw2D.FillRect(ToSurfaceRect(command.rect), Color.black);
            }
            else
            {
                UiRect gameUiRect = command.rect;
                if (gameUiRect.w < 0)
                {
                    // Means "auto compute from image".
                    gameUiRect.w = tex.width;
                }
                if (gameUiRect.h < 0)
                {
                    // Means "auto compute to keep aspect ratio".
                    gameUiRect.h = tex.width > 0 ? (tex.height * gameUiRect.w / tex.width) : 1;
                }
                Rect screenRect = ToSurfaceRect(gameUiRect);
                tex.filterMode = command.noFilter ? FilterMode.Point : FilterMode.Bilinear;
                draw2D.DrawTexture(screenRect, Color.white, tex);
            }
        }
    }
Example #2
0
    private void FontSizeTest()
    {
        UiRect rect = new UiRect();

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 100; j++)
            {
                rect.x = j * DEFAULT_CHAR_WIDTH;
                rect.y = 200 + i * DEFAULT_LINE_HEIGHT;
                rect.w = DEFAULT_CHAR_WIDTH;
                rect.h = DEFAULT_LINE_HEIGHT;
                draw2D.FillRect(ToSurfaceRect(rect), (i + j) % 2 == 0 ? Color.green : Color.blue);
            }
        }
        UiCommand cmd = new UiCommand
        {
            rect = new UiRect
            {
                x = 0,
                y = 200
            },
            textColor = 0xffffff,
            text      = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\n" +
                        "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789\n" +
                        "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
            opacity = 1
        };

        HandleCommandText(ref cmd);
    }
    public void EnableHighlight(Color color)
    {
        Image highlight = UiRect.GetChild(0).GetComponent <Image>();

        highlight.color   = color;
        highlight.enabled = true;
    }
Example #4
0
 private Rect ToSurfaceRect(UiRect gameUiRect)
 {
     return(new Rect(
                ToSurfaceX(gameUiRect.x), ToSurfaceY(gameUiRect.y),
                ToSurfaceLength(gameUiRect.w), ToSurfaceLength(gameUiRect.h)));
 }
    public void DisableHighlight()
    {
        Image highlight = UiRect.GetChild(0).GetComponent <Image>();

        highlight.enabled = false;
    }
 public void SetLabel(string text)
 {
     UnityEngine.UI.Text label = UiRect.GetComponent <Text>();
     label.text = text;
 }