IVirtualButtonEventHandler interface not implementing in Unity

て烟熏妆下的殇ゞ 提交于 2020-06-17 13:14:07

问题


I am working with virtual buttons in my unity vuforia project but i keep getting these errors. All examples I have seen show that the code is fine.

Assets\DataFiles\Scripts\VirtualButtonScript.cs(27,34): error CS0246: The type or namespace name 'VirtualButtonAbstractBehaviour' could not be found (are you missing a using directive or an assembly reference?)

Assets\DataFiles\Scripts\ARBCard.cs(32,33): error CS0246: The type or namespace name 'VirtualButtonAbstractBehaviour' could not be found (are you missing a using directive or an assembly reference?)

This is my code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class VirtualButtonScript : MonoBehaviour, IVirtualButtonEventHandler
{
    public GameObject spherego, cubego;
    VirtualButtonBehaviour vrb;

    // Start is called before the first frame update
    void Start()
    {
       vrb = GetComponentInChildren<VirtualButtonBehaviour>();
       vrb.RegisterEventHandler(this);

       cubego.SetActive(true);
       spherego.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void OnButtonPressed(VirtualButtonAbstractBehaviour vb)
    {
       cubego.SetActive(false);
       spherego.SetActive(true);
    }

    public void OnButtonReleased(VirtualButtonAbstractBehaviour vb)
    {
       cubego.SetActive(true);
       spherego.SetActive(false);
    }
}

回答1:


Update your Vuforia Version yo 8.1.7
Here is the Steps : https://library.vuforia.com/articles/Solution/update-installers-unity.html




回答2:


VirtualButtonAbstractBehaviour is deprecated. Even if you write code given below with current project it may not work but create new project and edit my sample it should work.

Following code is tested with unity 2018.4.9f1 LTS version and Vuforia V8.3.8

using System.Collections;
using System.Collections.Generic;
using Vuforia;
using UnityEngine;

public class VirtualButtonScript : MonoBehaviour, IVirtualButtonEventHandler
{
    public GameObject spherego, cubego;
    VirtualButtonBehaviour vrb;
    // Start is called before the first frame update
    void Start()
    {
        vrb = GetComponentInChildren<VirtualButtonBehaviour>();
        vrb.RegisterEventHandler(this);
        cubego.SetActive(true);
        spherego.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void OnButtonPressed(VirtualButtonBehaviour vb) {
        cubego.SetActive(false);
        spherego.SetActive(true);
    }

    public void OnButtonReleased(VirtualButtonBehaviour vb) {
        cubego.SetActive(true);
        spherego.SetActive(false);
    }
}



回答3:


I am using Unity 2019.3.13f1 (64-bit) version with Vuforia Engine Version 9.1.7. While using virtual buttons ( which we can find under ImageTarget > Insepector Window > Image Target Behavior Script > Advanced > Add Virtual Button) I faced an issue that I was not able to use IVirtualButtonEventHandler.

After searching the internet for almost 1 day I found a link (https://library.vuforia.com/content/vuforia-library/en/reference/unity/classVuforia_1_1VirtualButtonBehaviour.html#a3d314e8b4f58949efeb0255e47e8019b) which tells the changes specific to virtual button in new release.

I found that they have deprecated the IVirtualButtonEventHandler and have introduced a VuforiaMonoBehavior and VirtualButtonBehavior class. For the changes specific to button events are below:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class vbScript : MonoBehaviour

{   

    void Start()
    {
        Debug.Log("I reached in start of image target");
        zombie = GameObject.Find("zombie");
        var vbbs = GetComponentsInChildren<VirtualButtonBehaviour>();
        for (int i = 0; i < vbbs.Length; ++i)
        {
            vbbs[i].RegisterOnButtonPressed(OnButtonPressed);
            vbbs[i].RegisterOnButtonReleased(OnButtonReleased);
        }
        Debug.Log("should start walking here");
    }

    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {

        switch (vb.VirtualButtonName)
        {

            case "DanceButton":
                animator.SetBool("isWalking", false);
                animator.SetBool("isDancing", true);
                break;

            case "WalkButton":
                animator.SetBool("isDancing", false);
                animator.SetBool("isWalking", true);
                break;

            case "actionButton":
                Debug.Log("actionButton button Pressed or found...");
                zombie.GetComponent<Animation>().Play();
                // animator.SetBool("isDancing", false);
                //animator.SetBool("isWalking", true);
                break;

            default:
                animator.SetBool("isWalking", false);
                animator.SetBool("isDancing", false);
                break;
        }
    }

    public void OnButtonReleased(VirtualButtonBehaviour vb)
    {
        zombie.GetComponent<Animation>().Stop();
    }
}


来源:https://stackoverflow.com/questions/55498520/ivirtualbuttoneventhandler-interface-not-implementing-in-unity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!