在unity3d Google vr sdk中是否只有凝视模式(与单击/按钮输入相反)?

问题描述 投票:0回答:1

我正在使用unity3d中的google VR SDK(用于硬纸板),但是我的硬纸板没有按钮。是否有一种方法可以启用仅注视模式,该模式将extended gaze(几秒钟)视为按钮单击? (我在一个教程视频中说“您可以启用仅凝视模式”,但此后没有任何解释)这是内置的功能还是我必须从头开始编写凝视交互才能完成此操作?

我在各处搜索了代码,以使不仅启用了演示场景中可用的不同预制件上显示在编辑器上的公共道具。

unity3d google-cardboard google-vr google-vr-sdk gaze-buttons
1个回答
0
投票

我不知道该如何或是否有内置方法。但是您可以轻松构建扩展按钮:

using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.UI;
#endif

[RequireComponent(typeof(Button))]
public class DwellTimeButton : Button
{
    public float dwellTime = 0.5f;

    public override void OnPointerEnter(PointerEventData pointerEventData)
    {
        base.OnPointerEnter(pointerEventData);

        StartCoroutine (DwellTimeRoutine());
    }

    public override void OnPointerExit (PointerEventData pointerEventData)
    {
        base.OnPointerExit(pointerEventData);

        StopAllCoroutines ();
    }

    private IEnumerator DwellTimeRoutine ()
    {
        yield return new WaitForSeconds (dwellTime);

        onClick.Invoke();
    }

#if UNITY_EDITOR
    [CustomEditor (typeof (DwellTimeButton)]
    private class DwellTimeButtonEditor : ButtonEditor
    {
        SerializedProperty dwellTime;

        protected override void OnEnable()
        {
            base.OnEnable();

            dwellTime = serializedObject.FindProperty("dwellTime");
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();

            EditorGUILayout.PropertyField(dwellTime);
            serializedObject.ApplyModifiedProperties();
        }
    }
#endif
}

用此组件替换普通的Unity按钮,并设置所需的dwellTime。然后,在专注于dwellTime之后,它将自动调用onClick事件。

© www.soinside.com 2019 - 2024. All rights reserved.