unity基础开发----高通 AR Unity 虚拟按钮
2013-12-28 17:29
615 查看
高通开发AR都想用到互动,虚拟按钮互动可以实现虚拟和现实的结合互动。
我使用的版本是vuforia-sampleapps-unity-2-5-8的,具体怎么得到这个看/article/2378723.html
主要代码
添加到这个物体上ImageTarget,在添加
注意 virtual Button Behaviour 这个脚本的name就是vb.VirtualButtonName=="button";
这样就ok了
我使用的版本是vuforia-sampleapps-unity-2-5-8的,具体怎么得到这个看/article/2378723.html
主要代码
/*============================================================================== Copyright (c) 2010-2013 QUALCOMM Austria Research Center GmbH. All Rights Reserved. ==============================================================================*/ using UnityEngine; using System.Collections.Generic; /// <summary> /// This class implements the IVirtualButtonEventHandler interface and /// contains the logic to swap materials for the teapot model depending on what /// virtual button has been pressed. /// </summary> public class VirtualButtonEventHandler : MonoBehaviour, IVirtualButtonEventHandler { private GameObject mTeapot; 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; } #endregion // UNITY_MONOBEH***IOUR_METHODS #region PUBLIC_METHODS //按下 public void OnButtonPressed(VirtualButtonBehaviour vb) { //Debug.Log("OnButtonPressed"); if(vb.VirtualButtonName=="button") { print("button name!!!"); } if(vb.VirtualButtonName=="buttoon_text") { print("button_text "); } } //释放 public void OnButtonReleased(VirtualButtonBehaviour vb) { if(vb.VirtualButtonName=="button") { print("button name released !!!"); } if(vb.VirtualButtonName=="buttoon_text") { print("button_text released"); } } #endregion // PUBLIC_METHODS }
/*============================================================================== * Copyright (c) 2012-2013 Qualcomm Connected Experiences, Inc. All Rights Reserved. * ==============================================================================*/ using UnityEngine; using System.Collections.Generic; /// <summary> /// This class implements the IVirtualButtonEventHandler interface and /// contains the logic to swap materials for the teapot model depending on what /// virtual button has been pressed. /// </summary> public class VirtualButtonEventHandler : MonoBehaviour, IVirtualButtonEventHandler { #region PUBLIC_MEMBER_VARIABLES /// <summary> /// The materials that will be set for the teapot model /// </summary> #endregion // PUBLIC_MEMBER_VARIABLES #region PRIVATE_MEMBER_VARIABLES #endregion // PRIVATE_MEMBER_VARIABLES #region UNITY_MONOBEH***IOUR_METHODS void Start() { VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>(); for (int i = 0; i < vbs.Length; ++i) { vbs[i].RegisterEventHandler(this); } } #endregion // UNITY_MONOBEH***IOUR_METHODS #region PUBLIC_METHODS /// <summary> /// Called when the virtual button has just been pressed: /// </summary> public void OnButtonPressed(VirtualButtonAbstractBehaviour vb) { if (vb.VirtualButtonName == "Button01") { GameObject obj = GameObject.Find("ankylosaurus"); obj.animation.Play(); print("123456"); } } /// <summary> /// Called when the virtual button has just been released: /// </summary> public void OnButtonReleased(VirtualButtonAbstractBehaviour vb) { if (vb.VirtualButtonName == "Button01") { GameObject obj = GameObject.Find("ankylosaurus"); obj.animation.Stop(); print("wwwww"); } } #endregion // PUBLIC_METHODS }
添加到这个物体上ImageTarget,在添加
注意 virtual Button Behaviour 这个脚本的name就是vb.VirtualButtonName=="button";
这样就ok了
相关文章推荐
- Unity3D特效-场景淡入淡出
- Unity3D NGUI Localization国际化
- unity优化DrawCall
- Unity3D占用内存太大的解决方法
- 移动平台unity3d优化
- 我的Unity学习路线
- unity 中编写xml
- experience for unity
- unity3d Android客户端与PC服务器实现Socket通信(wifi)
- (五)Unity3d第四次面试
- (四)Unity3d第三次面试
- (三)Unity3d第二次面试
- Unity3d 中的 A*寻路
- (二)关于Unity3d面试的一些说明
- unity3d 使用c#如何访问某个对象里的c#脚本里的一个变量
- unity项目总结-3
- Unity3D播放视频
- Unity3D 调用C++的DLL的代码
- Unity3d的Animation使用注意事项
- Unity中播放动画和回放动画