1
A
回答
0
总之,你需要检测到您的手机上的罗盘改变没有任何倾斜(即磁铁接近了电话,并扰乱了指南针,而不改变其物理方向)。
你会想看看这两个载体,看看他们是否已经改变。
有两个开源实现,这是最简单的我无耻地包括下面(从秘方运动会信贷安德鲁·怀特):
- http://www.andrewnoske.com/wiki/Unity_-_Detecting_Google_Cardboard_Click
- https://github.com/CaseyB/UnityCardboardTrigger/blob/develop/MagnetSensor.cs
/* -- MIT/X11 like license -- Copyright (c) 2014 Paramita ltd, (Secret Ingredient Games) */ // // Google Cardboard click code in C# for Unity. // Author: Andrew Whyte // using UnityEngine; using System.Collections; using System; using System.Runtime.Serialization.Formatters.Binary; using System.IO; //public static XmlDocument XmlDoc; //public static XmlNodeList xnl; //public TextAsset TA; public class magneticClick { // Concept: two FIR filters, running on Magnetics and tilt. // If the tilt hasn't changed, but the compass has, then the magnetic field moved // without device this is the essence of a cardboard magnet click. private Vector3 lastTiltVector; public float tiltedBaseLine = 0f; public float magnetBaseLine = 0f; public float tiltedMagn = 0f; public float magnetMagn = 0f; private int N_SlowFIR = 25; private int N_FastFIR_magnet = 3; private int N_FastFIR_tilted = 5; // Clicking the magnet tends to tilt the device slightly. public float threshold = 1.0f; bool click = false; bool clickReported = false; public void init() { Input.compass.enabled = true; // Note that init is platform specific to unity. magnetMagn = Input.compass.rawVector.magnitude; magnetBaseLine = Input.compass.rawVector.magnitude; tiltedBaseLine = Input.acceleration.magnitude; tiltedMagn = Input.acceleration.magnitude; } public void magUpdate(Vector3 acc, Vector3 compass) { // Call this function in the Update of a monobehaviour as follows: // <magneticClickInstance>.magUpdate(Input.acceleration, Input.compass.rawVector); // we are interested in the change of the tilt not the actual tilt. Vector3 TiltNow = acc; Vector3 motionVec3 = TiltNow - lastTiltVector; lastTiltVector = TiltNow; // update tilt and compass "fast" values tiltedMagn = ((N_FastFIR_tilted-1) * tiltedMagn + motionVec3.magnitude)/N_FastFIR_tilted; magnetMagn = ((N_FastFIR_magnet-1) * magnetMagn + compass.magnitude)/N_FastFIR_magnet; // update the "slow" values tiltedBaseLine = ((N_SlowFIR-1) * tiltedBaseLine + motionVec3.magnitude)/N_SlowFIR; magnetBaseLine = ((N_SlowFIR-1) * magnetBaseLine + compass.magnitude)/N_SlowFIR; if(tiltedMagn < 0.2 && (magnetMagn/magnetBaseLine) > 1.1 ) { if(clickReported == false) { click = true; } clickReported = true; } else { clickReported = false; } } public bool clicked() { // Basic premise is that the magnitude of magnetic field should change while the // device is steady. This seems to be suiltable for menus etc. // Clear the click by reading (so each 'click' returns true only once) if(click == true) { click = false; return true; } else { return false; } } }
相关问题
- 1. 谷歌纸板磁铁拉动是否触发aframe点击事件?
- 2. 谷歌登录按钮按检测ios
- 3. java检测点击按钮
- 4. 检测谷歌广告点击
- 5. 简易电影纹理和谷歌纸板按钮
- 6. 未检测到按钮点击
- 7. JS没有检测按钮点击
- 8. 检测父点击按钮使用javascript
- 9. 检测其它按钮点击(NSUserNotification)
- 10. 检测按钮被点击的位置
- 11. 检测第二次点击按钮
- 12. 点击一个按钮,检测的jQuery
- 13. 如何调用getBasicProfile()的谷歌登录只有按钮点击谷歌?
- 14. 按钮点击检查?
- 15. 按钮点击检索值
- 16. 统一谷歌纸板漂移
- 17. VrPanoramaView的谷歌纸板屏幕截图
- 18. 谷歌纸板默认失真值
- 19. 按下按钮点击.xaml故事板
- 20. 在谷歌纸板上检测到倾斜事件不起作用
- 21. 谷歌地图重新点击后退按钮
- 22. 在谷歌地图上添加标记时,我点击按钮
- 23. 必须两次点击按钮Javascript - 谷歌地图
- 24. 设置图标类型按钮点击谷歌地图API3
- 25. 秒按钮点击延迟不起作用谷歌浏览器
- 26. 打开时间/ datePicker按钮点击像谷歌日历做
- 27. 重新绘制谷歌图表上的按钮点击/ javascript
- 28. 如何获取谷歌环聊按钮点击事件?
- 29. 应用程序关闭点击谷歌标志在按钮
- 30. 如何使用谷歌分析来计算点击按钮