【问题标题】:IVirtualButtonEventHandler interface not implementing in UnityIVirtualButtonEventHandler 接口未在 Unity 中实现
【发布时间】:2019-04-03 15:11:14
【问题描述】:

我在我的 unity vuforia 项目中使用虚拟按钮,但我不断收到这些错误。我看到的所有例子都表明代码很好。

Assets\DataFiles\Scripts\VirtualButtonScript.cs(27,34):错误 CS0246:找不到类型或命名空间名称“VirtualButtonAbstractBehaviour”(您是否缺少 using 指令或程序集引用?)

Assets\DataFiles\Scripts\ARBCard.cs(32,33):错误 CS0246:找不到类型或命名空间名称“VirtualButtonAbstractBehaviour”(您是否缺少 using 指令或程序集引用?)

这是我的代码

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);
    }
}

【问题讨论】:

    标签: c# unity3d vuforia


    【解决方案1】:

    更新您的 Vuforia 版本 yo 8.1.7
    这是步骤: https://library.vuforia.com/articles/Solution/update-installers-unity.html

    【讨论】:

      【解决方案2】:

      VirtualButtonAbstractBehaviour 已弃用。即使您使用当前项目编写下面给出的代码,它也可能无法正常工作,但创建新项目并编辑我的示例它应该可以工作。

      以下代码使用 unity 2018.4.9f1 LTS 版本和 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】:

        我正在使用 Unity 2019.3.13f1(64 位)版本和 Vuforia 引擎版本 9.1.7。在使用虚拟按钮(我们可以在 ImageTarget > Insepector Window > Image Target Behavior Script > Advanced > Add Virtual Button 下找到)时,我遇到了无法使用 IVirtualButtonEventHandler 的问题。

        在互联网上搜索了将近 1 天后,我找到了一个链接 (https://library.vuforia.com/content/vuforia-library/en/reference/unity/classVuforia_1_1VirtualButtonBehaviour.html#a3d314e8b4f58949efeb0255e47e8019b),它说明了新版本中特定于虚拟按钮的更改。

        我发现他们已经弃用了 IVirtualButtonEventHandler 并引入了 VuforiaMonoBehavior 和 VirtualButtonBehavior 类。对于特定于按钮事件的更改如下:

        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();
            }
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-10-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-07-09
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多