Unity VR Cardboard Gaze不在UI上工作

时间:2016-11-30 10:08:22

标签: unity3d monodevelop

我正在尝试在UI上使用Cardboard Gaze脚本。此脚本附加到相机,UI项目正在实施ICardboardResponder但没有成功。

1 个答案:

答案 0 :(得分:0)

试试这个脚本

void FixedUpdate() {
    var pointerEventData = new PointerEventData(EventSystem);

    Vector2 hotspot = new Vector2(0.5f, 0.5f);
    if(UnityEngine.VR.VRSettings.enabled)
        pointerEventData.position = new Vector2(hotspot.x * UnityEngine.VR.VRSettings.eyeTextureWidth, hotspot.y * UnityEngine.VR.VRSettings.eyeTextureHeight);
    else
        pointerEventData.position = new Vector2(hotspot.x * Screen.width, hotspot.y * Screen.height);

    List<RaycastResult> raycastResults = new List<RaycastResult>();
    EventSystem.RaycastAll(pointerEventData, raycastResults);
    for (var i = 0; i < raycastResults.Count; i++)
    {
        var hit = raycastResults[i];
        var other = hit.gameObject;
        var cardboardResponder = other.GetComponent<ICardboardResponder>()
        if (cardboardResponder != null)
        {
            //Do domething
        }
    }
}