Selaa lähdekoodia

分离游戏场景和设备调试

lvjincheng 4 vuotta sitten
vanhempi
sitoutus
41ab8b0f57

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 431 - 412
Assets/BowArrow/Scenes/Game.unity


+ 30 - 50
Assets/BowArrow/Scripts/Bluetooth/AimHandler.cs

@@ -9,12 +9,21 @@ using o0Aien;
 public class AimHandler : MonoBehaviour
 {
     [SerializeField] Transform controlObj;
-    [SerializeField] Button SetIdentityButton = default;
-    [SerializeField] Button MagCalibrationButton = default;
-    [SerializeField] Button GyrCalibrationButton = default;
-    [SerializeField] Text MagScaleText = default;
-    [SerializeField] Text GyrScaleText = default;
+    [SerializeField] Button SetIdentityButton;
+    [SerializeField] Button MagCalibrationButton;
+    [SerializeField] Button GyrCalibrationButton;
+    [SerializeField] Text MagScaleText;
+    [SerializeField] Text GyrScaleText;
 
+    //椭圆对象
+    [SerializeField] Ellipse ellipseScript;
+    [SerializeField] Toggle ellipseToggle;
+    [SerializeField] GameObject AccObj;
+    [SerializeField] GameObject MagObj;
+    [SerializeField] GameObject AMesh;
+    [SerializeField] Transform DebugTexts;
+    [SerializeField] Transform DrawImage;
+    
     long TimeGap = default;
     Vector3 Acc = default;
     Vector3 Gyr = default;
@@ -23,33 +32,9 @@ public class AimHandler : MonoBehaviour
 
     o0SigmoidIntegrationFilterQuaternion filter = new o0SigmoidIntegrationFilterQuaternion(0.2f);
 
-    //椭圆对象
-    Transform testEllipse;
-    public Ellipse ellipseScript;
-    public Toggle ellipseToggle;
-    public GameObject AccObj;
-    public GameObject MagObj;
-    public GameObject AMesh;
-
     Vector3 cMaxVector = new Vector3(0,0,0);
     Vector3 cMinVector = new Vector3(0, 0, 0);
 
-    // private void Awake()
-    // {
-    //     for (var i = 0; i < 15; ++i)
-    //     {
-    //         _9Axis.TextTester.Add(GameObject.Find("Canvas").transform.Find("DebugTexts").transform.Find("Text" + i.ToString()).gameObject.GetComponent<Text>());
-    //     }
-    // }
-    //转换读取的数据,无符号->有符号
-    float TwoByteToFloat(byte b1, byte b2) 
-    {
-        ushort twoByte = (ushort) (b1 * 256 + b2);
-        short shortNum = (short) twoByte;
-        return (float) shortNum; 
-    }
-
-    // o0MagneticCalibraterSimple MagCalibrater;
     o0MagneticCalibraterEllipsoidFitting MagCalibrater;
     o0GyrCalibrater GyrCalibrater;
     long msOld = 0;
@@ -62,16 +47,18 @@ public class AimHandler : MonoBehaviour
         BluetoothDispatcher.aim = OnDataReceived;
 
         //Init
-        ellipseToggle.onValueChanged.AddListener(OnValueChanged);
+        ellipseToggle.onValueChanged.AddListener(delegate(bool value) {
+             Debug.Log(value);
+        });
 
         for (var i = 0; i < 9; ++i)
         {
-            _9Axis.Tester.Add(GameObject.Find("Canvas").transform.Find("DrawImage").Find(i.ToString()).gameObject.AddComponent<o0UIRawImageTester>());
+            _9Axis.Tester.Add(DrawImage.Find(i.ToString()).gameObject.AddComponent<o0UIRawImageTester>());
         }
 
         for (var i = 0; i < 15; ++i)
         {
-            _9Axis.TextTester.Add(GameObject.Find("Canvas").transform.Find("DebugTexts").transform.Find("Text" + i.ToString()).gameObject.GetComponent<Text>());
+            _9Axis.TextTester.Add(DebugTexts.transform.Find("Text" + i.ToString()).gameObject.GetComponent<Text>());
         }
 
         if (SetIdentityButton) 
@@ -186,16 +173,19 @@ public class AimHandler : MonoBehaviour
         }
     }
 
-    private void OnValueChanged(bool value)
+    void OnDestroy()
     {
-        if (value)
-        {
-            //选中了的逻辑
-        }
-        Debug.Log(value);
+        ins = null;
+        BluetoothDispatcher.aim = null;
     }
 
-    
+    //转换读取的数据,无符号->有符号
+    float TwoByteToFloat(byte b1, byte b2) 
+    {
+        ushort twoByte = (ushort) (b1 * 256 + b2);
+        short shortNum = (short) twoByte;
+        return (float) shortNum; 
+    }
 
     public void OnDataReceived(byte[] bytes)
     {
@@ -321,20 +311,10 @@ public class AimHandler : MonoBehaviour
         {
             // 最终结果进行lerp
             controlObj.localRotation = Quaternion.Lerp(controlObj.localRotation, newRotation, Time.deltaTime * 8);
-            // controlObj.localRotation = newRotation;
-            // GameObject.Find("Canvas/RPY_LOG").GetComponent<Text>().text = 
-            //     "roll: " + controlObj.localEulerAngles.x +
-            //     "\npitch: " + controlObj.localEulerAngles.y +
-            //     "\nyaw: " + controlObj.localEulerAngles.z;
-            // GameObject.Find("Canvas/RPY_LOG").GetComponent<Text>().text = 
-            //     "x: " + _9Axis.x +
-            //     "\ny: " + _9Axis.y +
-            //     "\nz: " + _9Axis.States.z;
-                
+            // controlObj.localRotation = newRotation;          
         }
         if (doIdentity)
         {
-            // _9Axis.SetIdentityAccordingToRecords();
             _9Axis.SetIdentity();
             if (controlObj)
             {

+ 23 - 0
Assets/BowArrow/Scripts/Bluetooth/BluetoothHolder.cs

@@ -0,0 +1,23 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class BluetoothHolder : MonoBehaviour
+{   
+    public static BluetoothHolder ins;
+
+    void Start() {
+        ins = this;
+        CloseDebug();
+    } 
+
+    public void openDebug() {
+        this.transform.Find("Canvas").gameObject.SetActive(true);
+        this.transform.Find("Objects").gameObject.SetActive(true);
+    }
+
+    public void CloseDebug() {
+        this.transform.Find("Canvas").gameObject.SetActive(false);
+        this.transform.Find("Objects").gameObject.SetActive(false);
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Bluetooth/BluetoothHolder.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e4a8103abc6f24f4a9c89fa7f84b5d41
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Assets/BowArrow/Scripts/Bluetooth/ShootCheck.cs

@@ -103,6 +103,7 @@ public class ShootCheck : MonoBehaviour
     void OnDestroy()
     {
         ins = null;
+        BluetoothDispatcher.shoot = null;
     }
 
     public void OnBluetoothReady(BluetoothShoot bluetoothShoot) {

+ 4 - 0
Assets/BowArrow/Scripts/Manager/GameMgr.cs

@@ -91,6 +91,10 @@ public class GameMgr : MonoBehaviour
             Destroy(arrow);
         }
     }
+
+    public void OpenBluetoothDebug() {
+        BluetoothHolder.ins.openDebug();
+    }
 }
 
 /**闯关模式 */

+ 2 - 2
Assets/BowArrow/Scripts/View/ChallengeGameView.cs

@@ -33,7 +33,7 @@ public class ChallengeGameView : MonoBehaviour
     public void back() 
     {
         AudioMgr.ins.PlayBtn();
-        SceneManager.LoadScene("Home", LoadSceneMode.Single);
-        // Application.Quit();
+        // SceneManager.LoadScene("Home", LoadSceneMode.Single);
+        Application.Quit();
     }
 }

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä