【问题标题】:Unity: Getting the pixel on an image based on the location of buttons above the imageUnity:根据图像上方按钮的位置获取图像上的像素
【发布时间】:2016-09-03 00:25:57
【问题描述】:

对于我的 2D 游戏;我有一个带有图像组件(带有精灵)和 GridLayout 组件的面板。 在面板上,我还放置了一个为面板创建按钮的脚本(作为子项)

public void InitializeGrid(int rows, int columns, List<RbzFilteredWord> words)
{
    RectTransform myRect = GetComponent<RectTransform>();
    buttonHeight = myRect.rect.height / (float)rows;
    buttonWidth = myRect.rect.width / (float)columns;
    GridLayoutGroup grid = this.GetComponent<GridLayoutGroup>();
    grid.cellSize = new Vector2(buttonWidth, buttonHeight);

...
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < columns; j++)
        {
            button = (Button)Instantiate(prefab);
            button.transform.SetParent(transform, false);
          ...
}

问题:

每个按钮的文本必须指示该按钮枢轴位置处像素(来自底层图像)的颜色

我知道这个方法可用:GetPixel(x,y),但我不知道我需要使用哪个坐标作为这个方法的参数,因为我是一个统一的菜鸟

【问题讨论】:

    标签: image unity3d grid getpixel


    【解决方案1】:

    x 和 y 是纹理像素二维数组中的位置索引。

    即:

    • x 从 0 变为纹理图像的宽度 - 1(以像素为单位)
    • y 从 0 变为纹理图像的高度 - 1(以像素为单位)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      相关资源
      最近更新 更多