如何获取您指向DestinationMarkerEventHandler的纹理的像素值?

时间:2018-07-02 10:44:33

标签: c# unity3d vrtk

使用Unity3D和VRTK,我需要使用VRTK_Pointer脚本获取我要指向的纹理上的像素值。

我创建了一个脚本,该脚本附加到名为 COLOR_GRID 的球体上,我声明了一个与球体纹理相对应的公共成员Texture2D。它包含此方法,当我指向并单击该球体时将调用该方法。

private void DoPointerDestinationSet(object sender, DestinationMarkerEventArgs e)
{
    DebugLogger(VRTK_ControllerReference.GetRealIndex(e.controllerReference), "POINTER DESTINATION", e.target, e.raycastHit, e.distance, e.destinationPosition);

    if (e.target.name == "COLOR_GRID")
    {
        int[] coordinates = ????
        Color c = this.GetPixel(coordinates[0], coordinates[1]);
    }
}

我想可以从e.raycastHit中访问指针对球体的局部坐标。使用此信息,问题是如何将该局部坐标转换为Texture2D坐标?但是我被困在那里。

或者有更好的方法吗?

编辑:e.raycastHit.textureCoord始终为(0,0)。

0 个答案:

没有答案