【问题标题】:Vuforia namespace not found未找到 Vuforia 命名空间
【发布时间】:2015-12-29 05:21:16
【问题描述】:

我用 Vuforia 为增强现实制作了一个虚拟按钮:

using UnityEngine;
using System.Collections.Generic;

public class VBGordangDuaEventHandler : MonoBehaviour, IVirtualButtonEventHandler
{
    #region PUBLIC_MEMBER_VARIABLES

    /// <summary>
    /// The materials that will be set for the teapot model
    /// </summary>
    public Material[] m_TeapotMaterials;
    public AudioSource VBgordangduahitam;
    public AudioSource VBgordangduamerah;

    #endregion $3$



    #region PRIVATE_MEMBER_VARIABLES

private GameObject mTeapot;
private List<Material> mActiveMaterials;

#endregion $4$



#region UNITY_MONOBEHAVIOUR_METHODS

void Start()
{
    // Register with the virtual buttons TrackableBehaviour
    VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
    for (int i = 0; i < vbs.Length; ++i)
    {
        vbs[i].RegisterEventHandler(this);
    }
    
    // Get handle to the teapot object
    //      mTeapot = transform.FindChild("teapot").gameObject;
    
    // The list of active materials
    mActiveMaterials = new List<Material>();
}

#endregion $9$



#region PUBLIC_METHODS

/// <summary>
/// Called when the virtual button has just been pressed:
/// </summary>
public void OnButtonPressed(VirtualButtonAbstractBehaviour vb)
{
    Debug.Log("OnButtonPressed::" + vb.VirtualButtonName);
    
    /*if (!IsValid())
    {
        return;
    }*/
    
    // Add the material corresponding to this virtual button
    // to the active material list:
    switch (vb.VirtualButtonName)
    {
    case "VBgordangduahitam":
        Debug.Log ("gordangduahitam");
        suaragordangduahitam.Play ();
        break;
        
    case "VBgordangduamerah":
        Debug.Log ("gordang2merah");
        suaragordangduamerah.Play ();
        break;
        
    }
    
    // Apply the new material:
    /*if (mActiveMaterials.Count > 0)
        mTeapot.renderer.material = mActiveMaterials[mActiveMaterials.Count - 1];*/
}


/// <summary>
/// Called when the virtual button has just been released:
/// </summary>
public void OnButtonReleased(VirtualButtonAbstractBehaviour vb)
{
    if (!IsValid())
    {
        return;
    }
    
    // Remove the material corresponding to this virtual button
    // from the active material list:
    switch (vb.VirtualButtonName)
    {
    case "red":
        mActiveMaterials.Remove(m_TeapotMaterials[0]);
        break;
        
    case "blue":
        mActiveMaterials.Remove(m_TeapotMaterials[1]);
        break;
        
    case "yellow":
        mActiveMaterials.Remove(m_TeapotMaterials[2]);
        break;
        
    case "green":
        mActiveMaterials.Remove(m_TeapotMaterials[3]);
        break;
    }
    
    // Apply the next active material, or apply the default material:
    /*if (mActiveMaterials.Count > 0)
        mTeapot.renderer.material = mActiveMaterials[mActiveMaterials.Count - 1];
    else
        mTeapot.renderer.material = m_TeapotMaterials[4];*/
}


private bool IsValid()
{
    // Check the materials and teapot have been set:
    return  mTeapot != null;
}

#endregion $35$

为什么会出现以下错误?

1):错误 CS0246:找不到类型或命名空间名称“IVirtualButtonEventHandler”(您是否缺少 using 指令或程序集引用?)(CS0246)(Assembly-CSharp)

2):错误 CS0246:找不到类型或命名空间名称“VirtualButtonAbstractBehaviour”(您是否缺少 using 指令或程序集引用?)(CS0246)(Assembly-CSharp)

3):错误 CS0246:找不到类型或命名空间名称“VirtualButtonAbstractBehaviour”(您是否缺少 using 指令或程序集引用?)(CS0246)(Assembly-CSharp)

4):错误 CS0246:找不到类型或命名空间名称“VuforiaBehaviourComponentFactory”(您是否缺少 using 指令或程序集引用?)(CS0246)(Assembly-CSharp-Editor)

如何解决这些错误?

【问题讨论】:

  • 就像错误所说...您可能在项目中缺少对 Vuforria DLL 的一些引用。您需要确保已添加它们

标签: c# augmented-reality vuforia


【解决方案1】:

尝试添加

using Vuforia;

到代码的顶部。正如@ShaiAharoni 在他们的评论中提到的,您需要引用 Vuforia DLL。

您可能需要的其他参考资料包括

using UnityEngine;
using System.Collections.Generic;

【讨论】:

  • 我之前已经包含了.. 但 IVirtualButtonEventHandler 仍然错误
【解决方案2】:

我假设你复制了这个例子

https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/virtual-buttons-no-response-tap

登录/注册并下载示例。根据您的帖子,您没有添加对 dll 的引用,这些是您得到的错误。如果您下载代码示例,您可能会获得 dll,因此您可以相应地参考您的代码示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-16
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 2012-03-31
    相关资源
    最近更新 更多