Vuforia开发高阶二-虚拟按钮(第二部分)

public class MyVirtualButtonControl : MonoBehaviour,
IVirtualButtonEventHandler
{
    #region PUBLIC_MEMBER_VARIABLES
  
    public ImageTargetBehaviour imageTargetBehaviour;
  
    public AudioSource button_audio;
  
    /// <summary>
    /// The materials that will be set for the teapot model
    /// </summary>
    //public Material[] m_TeapotMaterials;
      
    #endregion // PUBLIC_MEMBER_VARIABLES
      
    #region PRIVATE_MEMBER_VARIABLES
      
    private GameObject mTeapot;
    private List<Material> mActiveMaterials;
      
    #endregion // PRIVATE_MEMBER_VARIABLES
      
    private Vector2 top;
    private Vector2 bottom;
  
    public GameObject myObject;
  
    private string labelname = "Hello,ANTVR!";
    #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);
            vbs<i>.CalculateButtonArea(out top,out bottom);
            Debug.Log("----->"+vbs.Length);
            //vbs<i>.VirtualButton.Name+
            Debug.Log("---->"+top.x+":"+top.y+"----->"+bottom.x+":"+bottom.y);
        }
  
        VirtualButtonBehaviour vb=
            (VirtualButtonBehaviour)imageTargetBehaviour.CreateVirtualButton ("eleven",new Vector2(-10,10),new Vector2(10,-10));
        if (vb != null) {
            vb.VirtualButton.SetEnabled(true);
            Debug.Log("!!!!!!!!!"+vb.VirtualButton.Name);
        }
        // Get handle to the teapot object
        //mTeapot = transform.FindChild("teapot").gameObject;
          
        // The list of active materials
        mActiveMaterials = new List<Material>();
    }
      
    #endregion // UNITY_MONOBEHAVIOUR_METHODS
      
      
      
    #region PUBLIC_METHODS
      
    /// <summary>
    /// Called when the virtual button has just been pressed:
    /// </summary>
    public void OnButtonPressed(VirtualButtonAbstractBehaviour vb)
    {
        if (!button_audio.isPlaying) {
            button_audio.Play();        
        }
        if (button_audio.isPlaying) {
            button_audio.volume=1;      
        }
        Debug.Log("OnButtonPressed::" + vb.VirtualButtonName);
          
        // Add the material corresponding to this virtual button
        // to the active material list:
        switch (vb.VirtualButtonName)
        {
        case "one":
            //myObject.transform.animation.Play();
            myObject.transform.animation.Play("Take 4");
            labelname = "one -> Run!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            if (button_audio.isPlaying) {
                button_audio.volume=1;      
            }
            break;
              
        case "two":
            myObject.transform.animation.Play("Take 002");
            labelname = "two -> Nothing!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
              
        case "three":
            //myObject.transform.animation.Play("Take 4");
            myObject.transform.animation.Play();
            labelname = "three -> Stand!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
              
        case "four":
            myObject.transform.animation.Play("Take 5");
            labelname = "four -> Hello!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
  
        case "five":
            //myObject.transform.animation.Play("Take 5");
            myObject.transform.animation.Play();
            labelname = "five -> Stand!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
  
        case "six":
            myObject.transform.animation.Play("Take 5");
            labelname = "six -> Hello!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
        case "seven":
            //myObject.transform.animation.Play("Take 5");
            myObject.transform.animation.Play("Take 4");
            labelname = "seven -> Stand!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
              
        case "eight":
            myObject.transform.animation.Play("Take 002");
            labelname = "eight -> Hello!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
  
        case "nine":
            //myObject.transform.animation.Play("Take 5");
            myObject.transform.animation.Play("Take 4");
            labelname = "nine -> Stand!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
              
        case "ten":
            myObject.transform.animation.Play("Take 002");
            labelname = "ten -> Hello!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
  
        case "eleven":
            myObject.transform.animation.Play("Take 002");
            labelname = "eleven -> Hello!";
            if (!button_audio.isPlaying) {
                button_audio.Play();        
            }
            break;
        }
  
    }
      
    /// <summary>
    /// Called when the virtual button has just been released:
    /// </summary>
    public void OnButtonReleased(VirtualButtonAbstractBehaviour vb)
    {
          
        // Remove the material corresponding to this virtual button
        // from the active material list:
        switch (vb.VirtualButtonName)
        {
        case "one":
  
            break;
              
        case "two":
  
            break;
              
        case "three":
  
            break;
              
        case "four":
  
            break;
        }
    }
      
    #endregion // PUBLIC_METHODS
      
    void OnGUI(){
        GUI.Label (new Rect (10, 10, 100, 100), labelname);
    }
}</i></i></i>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值