无法调用IVirtualButtonEventHandler Vuforia 5.0.10

时间:2016-02-26 23:12:48

标签: unity3d vuforia

我使用的是Unity 4.7.0和Vuforia 5.0.10,我无法调用IVirtualButtonEventHandler

using UnityEngine;
using System.Collections;

public class VBEventHandler : MonoBehaviour, IVirtualButtonEventHandler 
{

}

2 个答案:

答案 0 :(得分:1)

我刚刚遇到过这个,希望你还在使用Unity& Vuforia。您需要使用Vuforia添加来进行呼叫。

using UnityEngine;
using System.Collections;
using Vuforia;

答案 1 :(得分:0)

注册虚拟按钮:

要向图像目标添加虚拟按钮,请将VirtualButton元素及其属性添加到.xml文件中的ImageTarget元素。

XML属性:

  1. 名称 - 按钮的唯一名称
  2. 矩形 - 由矩形中的四个角定义 目标的坐标空间
  3. 已启用 - 一个布尔值,指示是否应启用该按钮 默认情况下
  4. 灵敏度 - 高,中,低对遮挡的敏感度
  5. 注册虚拟按钮代码后很简单:

    using UnityEngine;
    using System.Collections;
    using Vuforia;
        public class Custom_VirtualButton : MonoBehaviour, IVirtualButtonEventHandler
        {
            // Use this for initialization
            void Start () {
    
        // here it finds any VirtualButton Attached to the ImageTarget and register it's event handler and in the
        //OnButtonPressed and OnButtonReleased methods you can handle different buttons Click state
        //via "vb.VirtualButtonName" variable and do some really awesome stuff with it.
                VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
                foreach (VirtualButtonBehaviour item in vbs)
                {
                    item.RegisterEventHandler(this);
                }
    
            }
    
            // Update is called once per frame
            void Update () {
    
            }
    
    
            #region VirtualButton
    
            public void OnButtonPressed(VirtualButtonAbstractBehaviour vb)
            {
                Debug.Log("Helllllloooooooooo");
            }
    
            public void OnButtonReleased(VirtualButtonAbstractBehaviour vb)
            {
                Debug.Log("Goooooodbyeeee");
            }
    
            #endregion //VirtualButton
        }