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. 檢測谷歌紙板磁性按鈕點擊使用Javascript
- 2. 檢測谷歌Android中的搜索按鈕點擊Android
- 3. 如何檢測按鈕點擊谷歌地圖infowindow
- 4. 谷歌紙板磁鐵拉動是否觸發aframe點擊事件?
- 5. 谷歌登錄按鈕按檢測ios
- 6. 按鈕點擊檢測
- 7. java檢測點擊按鈕
- 8. 按鈕打開谷歌URL點擊
- 9. 用vb.net點擊谷歌+ 1按鈕
- 10. 顯示谷歌地圖,點擊按鈕
- 11. 檢測谷歌廣告點擊
- 12. 從谷歌紙板的真實點擊圖像製作場景
- 13. VC++,檢測按下按鈕前點擊
- 14. 簡易電影紋理和谷歌紙板按鈕
- 15. 檢測父點擊按鈕使用javascript
- 16. JS沒有檢測按鈕點擊
- 17. 點擊一個按鈕,檢測的jQuery
- 18. 檢測一個html按鈕點擊node.js?
- 19. 未檢測到按鈕點擊
- 20. 檢測ctrl +點擊pygtk中的按鈕
- 21. 檢測第二次點擊按鈕
- 22. 檢測耳機按鈕點擊iPhone SDK
- 23. 檢測按鈕點擊次數Gui Gui
- 24. 帶按鈕點擊檢測的NSInvalidArgumentException
- 25. 檢測其它按鈕點擊(NSUserNotification)
- 26. 檢測按鈕被點擊的位置
- 27. jquery模板按鈕點擊?
- 28. 檢測耳機按鈕,雙擊和長按(點擊)的Android
- 29. 檢測後退按鈕點擊和忽略額外的點擊
- 30. 如何調用getBasicProfile()的谷歌登錄只有按鈕點擊谷歌?