1

当对象被“点击”时,我需要获取注视指针和 Hololens 中的对象之间的碰撞坐标。

所有示例都使用 MRTK1,您如何在 MRTK2 中做到这一点?我知道您需要使用光标,但是您如何获得它=它仅在我实际运行代码时出现。

这是我到目前为止所拥有的:

using Microsoft.MixedReality.Toolkit.Input;


public class MoveTo : BaseInputHandler, IMixedRealityInputHandler
{
    public GameObject Sphere;
    public GameObject Cursor;

    public void OnInputUp(InputEventData eventData)
    {
        GetComponent<MeshRenderer>().material.color = Color.red;
    }

    public void OnInputDown(InputEventData eventData)
    {
        Vector3 gazePos = Cursor.transform.position;
        Sphere.transform.position = gazePos;
        GetComponent<MeshRenderer>().material.color = Color.green;
    }
}
4

1 回答 1

1

弄清楚了。我不得不改用指针处理程序。此代码有效:

public class MoveTo : BaseInputHandler, IMixedRealityPointerHandler
{
    public GameObject Sphere;

    public void OnPointerDown(MixedRealityPointerEventData eventData)
    {
        GetComponent<MeshRenderer>().material.color = Color.green;
    }

    public void OnPointerDragged(MixedRealityPointerEventData eventData)
    {
    }

    public void OnPointerUp(MixedRealityPointerEventData eventData)
    {
        Vector3 gazePos = Sphere.transform.position;
        Sphere.transform.position = eventData.Pointer.Result.Details.Point;
        GetComponent<MeshRenderer>().material.color = Color.red;
    }

    public void OnPointerClicked(MixedRealityPointerEventData eventData)
    {
    }
}
于 2019-06-05T12:03:33.843 回答