(Unity3d)Vuforia开发高阶二-虚拟按钮
来源:互联网 发布:分布式数据库 hadoop 编辑:程序博客网 时间:2024/06/06 02:37
第三部分:
既然虚拟按钮的事件可以被检测到,那么可以像正常的按钮一样,执行长按短按,或者双击之类的操作。这里以判断虚拟按钮长按还是短按为例。
主要的实现原理是通过判断触发持续的时间长短。
复制代码
既然虚拟按钮的事件可以被检测到,那么可以像正常的按钮一样,执行长按短按,或者双击之类的操作。这里以判断虚拟按钮长按还是短按为例。
主要的实现原理是通过判断触发持续的时间长短。
复制代码
using UnityEngine;using System.Collections;using Vuforia; public class MyButtonControl : MonoBehaviour,IVirtualButtonEventHandler { public GameObject bowling; private GameObject clone; private float intervalTime = 0; private bool isPressed = false; // 判断是长按还是短按 private bool isShortPress = false; private bool isLongPress = false; // Use this for initialization void Start () { VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour> (); for (int i =0; i<vbs.Length; i++) { vbs[i].RegisterEventHandler(this); } } // Update is called once per frame void Update () { Debug.Log ("---->"+gameObject.transform.rotation); if (isPressed) { intervalTime += Time.deltaTime; } } // 检测长按和短按 public void OnButtonPressed (VirtualButtonAbstractBehaviour vb){ switch (vb.VirtualButtonName) { case "fire": Debug.Log("----------> Fire"); //bowling.transform.rigidbody.AddForce (Vector3.forward*20000); //clone = (GameObject)Instantiate(bowling,bowling.transform.position,gameObject.transform.rotation); //clone.transform.rigidbody.AddForce (-Vector3.forward*20000); //clone.transform.rigidbody.velocity = new Vector3(0,0,10); bowling.transform.rigidbody.velocity = new Vector3(0,0,1000); isPressed = true; intervalTime = 0; break; default: break; } } public void OnButtonReleased (VirtualButtonAbstractBehaviour vb){ isPressed = false; if (intervalTime <= 1) { Debug.Log("-----> short Pressed!"+intervalTime); } else { Debug.Log("-----> long Pressed!"+intervalTime); } }}
0 0
- (Unity3d)Vuforia开发高阶二-虚拟按钮
- Vuforia开发高阶二-虚拟按钮(第一部分)
- Vuforia开发高阶二-虚拟按钮(第二部分)
- Vuforia开发高阶二-虚拟按钮(第一部分)
- Vuforia开发高阶二-虚拟按钮(第二部分)
- Vuforia开发高阶二-虚拟按钮(第三部分)
- Vuforia开发高阶二-虚拟按钮(第四部分)
- Unity + vuforia 开发虚拟按钮
- (Unity3d)Vuforia开发基础
- Vuforia虚拟按钮
- (Unity3D)利用Vuforia开发增强现实
- (Unity3d)Vuforia开发基础0
- (Unity3d)Vuforia开发基础六-音频
- (Unity3D)Vuforia开发高阶一-VideoPlayback
- Vuforia Virtual Button(虚拟按钮)使用技巧
- vuforia结合unity3d开发AR的androidAPP总结(一)
- vuforia结合unity3d开发AR的androidAPP总结(二)
- vuforia结合unity3d开发AR的androidAPP总结(三)
- html表格标签使用
- 二维树状数组
- hexo+github搭建博客
- [Extjs6]清除数组内容
- 教你如何在Android 6.0上创建系统悬浮窗
- (Unity3d)Vuforia开发高阶二-虚拟按钮
- 去除桌面的svn问号标志符
- IOS 疯狂基础之 页面间跳转
- C++数组巧妙用法
- 注解形式的定时器
- iOS 获取当前时间并且显示走在视图上
- 1508-张晨曦总结《2016年-10月-28日》【连续7天总结】
- XSS跨站脚本攻击过程最简单演示
- mybatis中使用if标签比较两个字符串是否相等