Explorar el Código

整理代码以及把AimHandler拆分出来

lvjincheng hace 4 años
padre
commit
28993cb21c

+ 462 - 23
Assets/BowArrow/Scenes/Game.unity

@@ -241,7 +241,7 @@ GameObject:
   - component: {fileID: 29012942}
   - component: {fileID: 29012941}
   m_Layer: 5
-  m_Name: SliderBG (1)
+  m_Name: TargetDistanceSlider
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -367,6 +367,17 @@ Transform:
   m_Father: {fileID: 1256775562}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 2.3821315e-13, y: -5.719704e-13, z: 2.024968}
+--- !u!114 &40509674 stripped
+MonoBehaviour:
+  m_CorrespondingSourceObject: {fileID: 2873263698492052743, guid: 8c9e3b1466f251343934a20aeea28cd0, type: 3}
+  m_PrefabInstance: {fileID: 2873263697436857648}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 0}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: b1d6997c80c485f4291c7a975c1407da, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
 --- !u!1 &41881024
 GameObject:
   m_ObjectHideFlags: 0
@@ -1464,6 +1475,208 @@ MonoBehaviour:
   AP_bow: {fileID: 1195327002}
   arrow: {fileID: 1957562167}
   bowCamera: {fileID: 394830269}
+  recordRotations:
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  recordRotationVars:
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  recordCount: 0
 --- !u!114 &150264296
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -4799,7 +5012,7 @@ GameObject:
   - component: {fileID: 485623850}
   - component: {fileID: 485623849}
   m_Layer: 5
-  m_Name: SliderBG
+  m_Name: ShootSpeedSlider
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -5648,6 +5861,11 @@ Transform:
   m_Father: {fileID: 1071984804}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 3.098478, y: 15.7349, z: -59.93969}
+--- !u!1 &596345190 stripped
+GameObject:
+  m_CorrespondingSourceObject: {fileID: 5267297738912478573, guid: b100e5f3d1feffb49824e72907d434a4, type: 3}
+  m_PrefabInstance: {fileID: 1411222548}
+  m_PrefabAsset: {fileID: 0}
 --- !u!1 &602693960
 GameObject:
   m_ObjectHideFlags: 0
@@ -6205,6 +6423,11 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 668134155}
   m_CullTransparentMesh: 1
+--- !u!1 &668975288 stripped
+GameObject:
+  m_CorrespondingSourceObject: {fileID: 5267297738912478573, guid: b100e5f3d1feffb49824e72907d434a4, type: 3}
+  m_PrefabInstance: {fileID: 659914778}
+  m_PrefabAsset: {fileID: 0}
 --- !u!1 &675796228
 GameObject:
   m_ObjectHideFlags: 0
@@ -9198,7 +9421,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 1
+  m_IsActive: 0
 --- !u!114 &992649508
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -10212,11 +10435,6 @@ Camera:
   m_OcclusionCulling: 1
   m_StereoConvergence: 10
   m_StereoSeparation: 0.022
---- !u!4 &1092288566 stripped
-Transform:
-  m_CorrespondingSourceObject: {fileID: 2873263698492052742, guid: 8c9e3b1466f251343934a20aeea28cd0, type: 3}
-  m_PrefabInstance: {fileID: 2873263697436857648}
-  m_PrefabAsset: {fileID: 0}
 --- !u!1 &1098599323
 GameObject:
   m_ObjectHideFlags: 0
@@ -10260,7 +10478,7 @@ GameObject:
   - component: {fileID: 1105832657}
   - component: {fileID: 1105832659}
   m_Layer: 5
-  m_Name: DebugText (1)
+  m_Name: MagScaleText
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -10278,7 +10496,7 @@ RectTransform:
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
   m_Father: {fileID: 1979114040}
-  m_RootOrder: 7
+  m_RootOrder: 8
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 1, y: 1}
   m_AnchorMax: {x: 1, y: 1}
@@ -12027,7 +12245,7 @@ GameObject:
   - component: {fileID: 1293471642}
   - component: {fileID: 1293471641}
   m_Layer: 5
-  m_Name: Button (2)
+  m_Name: GyrCalibrationButton
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -12046,7 +12264,7 @@ RectTransform:
   m_Children:
   - {fileID: 1394525658}
   m_Father: {fileID: 1979114040}
-  m_RootOrder: 8
+  m_RootOrder: 7
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 1, y: 1}
   m_AnchorMax: {x: 1, y: 1}
@@ -13882,7 +14100,7 @@ GameObject:
   - component: {fileID: 1478558958}
   - component: {fileID: 1478558957}
   m_Layer: 5
-  m_Name: Button
+  m_Name: SetIdentityButton
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -14173,7 +14391,7 @@ GameObject:
   - component: {fileID: 1509022409}
   - component: {fileID: 1509022408}
   m_Layer: 5
-  m_Name: DebugText (2)
+  m_Name: GyrScaleText
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -15610,6 +15828,7 @@ GameObject:
   m_Component:
   - component: {fileID: 1680053129}
   - component: {fileID: 1680053130}
+  - component: {fileID: 1680053131}
   m_Layer: 0
   m_Name: CameraToLook
   m_TagString: Untagged
@@ -15644,17 +15863,30 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 03d0c42942f31844abda9f17bb8e3ec9, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  targetDeviceName: Bbow_20210501
   textUI: {fileID: 1105832657}
+--- !u!114 &1680053131
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1680053128}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: e97c37446b5827f4a9f74dce82e5ff36, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
   controlObj: {fileID: 1680053129}
-  SetIdentity: {fileID: 1478558957}
+  SetIdentityButton: {fileID: 1478558957}
   MagCalibrationButton: {fileID: 1990278318}
   GyrCalibrationButton: {fileID: 1293471641}
   MagScaleText: {fileID: 1105832657}
   GyrScaleText: {fileID: 1509022409}
-  OriginalDataText: {fileID: 0}
-  testEllipse: {fileID: 1092288566}
-  testEllipseToggle: {fileID: 689102713}
+  ellipseScript: {fileID: 40509674}
+  ellipseToggle: {fileID: 689102714}
+  AccObj: {fileID: 668975288}
+  MagObj: {fileID: 596345190}
+  AMesh: {fileID: 2060559633}
 --- !u!1 &1680621885
 GameObject:
   m_ObjectHideFlags: 0
@@ -15998,7 +16230,7 @@ GameObject:
   - component: {fileID: 1691070389}
   - component: {fileID: 1691070388}
   m_Layer: 5
-  m_Name: DebugText
+  m_Name: ShootDebugText
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -17768,6 +18000,208 @@ MonoBehaviour:
   AP_bow: {fileID: 0}
   arrow: {fileID: 340970074}
   bowCamera: {fileID: 394830269}
+  recordRotations:
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  - {x: 0, y: 0, z: 0, w: 0}
+  recordRotationVars:
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  - 0
+  recordCount: 0
 --- !u!114 &1908395047
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -18614,8 +19048,8 @@ RectTransform:
   - {fileID: 1691070387}
   - {fileID: 1478558956}
   - {fileID: 1990278317}
-  - {fileID: 1105832656}
   - {fileID: 1293471640}
+  - {fileID: 1105832656}
   - {fileID: 1509022407}
   - {fileID: 698090359}
   - {fileID: 1475481933}
@@ -18759,7 +19193,7 @@ GameObject:
   - component: {fileID: 1990278319}
   - component: {fileID: 1990278318}
   m_Layer: 5
-  m_Name: Button (1)
+  m_Name: MagCalibrationButton
   m_TagString: Untagged
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
@@ -19726,6 +20160,11 @@ MonoBehaviour:
           m_StringArgument: 
           m_BoolArgument: 0
         m_CallState: 2
+--- !u!1 &2060559633 stripped
+GameObject:
+  m_CorrespondingSourceObject: {fileID: 6939955684172241614, guid: 615af2d9be23fc54b9d22ed181782bc7, type: 3}
+  m_PrefabInstance: {fileID: 897521227}
+  m_PrefabAsset: {fileID: 0}
 --- !u!1 &2062971352
 GameObject:
   m_ObjectHideFlags: 0
@@ -22760,7 +23199,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 1
+  m_IsActive: 0
 --- !u!1 &919132147533326250
 GameObject:
   m_ObjectHideFlags: 0

+ 365 - 0
Assets/BowArrow/Scripts/Bluetooth/AimHandler.cs

@@ -0,0 +1,365 @@
+using System;
+using UnityEngine;
+using System.Collections.Generic;
+using System.Linq;
+using UnityEngine.UI;
+using Newtonsoft.Json;
+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;
+
+    long TimeGap = default;
+    Vector3 Acc = default;
+    Vector3 Gyr = default;
+    Vector3 Mag = default;
+    o09Axis _9Axis = new o09Axis();
+
+    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;
+
+    public static AimHandler ins; 
+
+    void Start()
+    {
+        ins = this;
+        BluetoothDispatcher.aim = OnDataReceived;
+
+        //Init
+        ellipseToggle.onValueChanged.AddListener(OnValueChanged);
+
+        for (var i = 0; i < 9; ++i)
+        {
+            _9Axis.Tester.Add(GameObject.Find("Canvas").transform.Find("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>());
+        }
+
+        if (SetIdentityButton) 
+        {
+            SetIdentityButton.onClick.AddListener(DoIdentity);
+        }
+        
+        try 
+        {  
+            string magDataStr = PlayerPrefs.GetString("o0MagneticCalibrater");
+            MagCalibrater = JsonConvert.DeserializeObject<o0MagneticCalibraterEllipsoidFitting>(magDataStr);
+        } 
+        catch(Exception) 
+        {
+            MagCalibrater = null;
+        }
+
+        if (MagCalibrater == null) 
+        {
+            MagCalibrater = new o0MagneticCalibraterEllipsoidFitting();
+        }
+        if (MagCalibrationButton)
+        {
+            MagCalibrationButton.onClick.AddListener(delegate {
+                if (MagCalibrater.Calibration)
+                {
+                    List<Vector3> list = MagCalibrater.getRecords();
+                    //停止校准时候,看看数组值
+                    float maxDistance = 0f,ratio = 1f;
+                    Vector3 maxVector3 = new Vector3(0,0,0);
+                    List<Vector3> endRecords = new List<Vector3>();
+                    foreach (Vector3 i in list)
+                    {
+                        Vector3 v = i - MagCalibrater._Center;
+                        if (Math.Abs(v.magnitude) > maxDistance)
+                        {
+                            maxVector3 = v;
+                            maxDistance = Math.Abs(v.magnitude);
+                            if(Math.Abs(v.magnitude) < Math.Abs(MagCalibrater._Radius.magnitude))
+                                ratio = Math.Abs(v.magnitude) / Math.Abs(MagCalibrater._Radius.magnitude);
+                            else
+                                ratio = Math.Abs(MagCalibrater._Radius.magnitude) / Math.Abs(v.magnitude);
+                        }
+                    }
+                    Debug.LogWarning(maxDistance + " == " + Math.Abs(MagCalibrater._Radius.magnitude) + " == " + MagCalibrater._Radius + " = " + maxVector3);
+                    //如果比例效果不理想。可以设置为ratio=0.5f 
+                    foreach (Vector3 i in list)
+                    {
+                        //- MagCalibrater._Center
+                        Vector3 v = i ;
+                        v *= ratio;
+                        if(endRecords.Count>3000)
+                        {
+                            endRecords.RemoveAt(0);
+                        }
+                        endRecords.Add(v);
+                    }
+                    this.ellipseScript.ClearAndUpdatePointArray();
+                    this.ellipseScript.DrawPointCloud(endRecords);
+
+                    //绘制椭圆形
+                    if (MagCalibrater._Radius != this.ellipseScript.ellipseTran.localScale)
+                    {
+                        this.ellipseScript.setEllipseLocalScaleAndCenter(MagCalibrater._Radius, MagCalibrater._Center* ratio);
+                        //设置绘制图像相机的对应位置
+                        this.ellipseScript.setCameraPos(MagCalibrater._Center * 0.5f);
+                    }
+
+                    MagCalibrater.Calibration = false;
+                    MagCalibrationButton.GetComponentInChildren<Text>().text = "开始地磁计校准";
+                    PlayerPrefs.SetString("o0MagneticCalibrater", JsonConvert.SerializeObject(MagCalibrater));
+
+                }
+                else
+                {
+                    MagCalibrater.Calibration = true;
+                    MagCalibrationButton.GetComponentInChildren<Text>().text = "停止地磁计校准";
+
+                    this.cMaxVector = new Vector3(0, 0, 0);
+                    this.cMinVector = new Vector3(0, 0, 0);
+                }
+            });
+        }
+
+        try {
+            string gyrDataStr = PlayerPrefs.GetString("o0GyrCalibrater");
+            GyrCalibrater = JsonConvert.DeserializeObject<o0GyrCalibrater>(gyrDataStr);
+            if (GyrCalibrater._Average != Vector3.zero) GyrScaleText.text = "已校准";
+        } catch(Exception) {
+            GyrCalibrater = null;
+        }
+        if (GyrCalibrater == null) 
+        {
+            GyrCalibrater = new o0GyrCalibrater();
+        }
+        if (GyrCalibrationButton)
+        {
+            GyrCalibrationButton.onClick.AddListener(delegate {
+                if (GyrCalibrater.Calibration)
+                {
+                    GyrCalibrater.Calibration = false;
+                    GyrCalibrationButton.GetComponentInChildren<Text>().text = "开始陀螺仪校准";
+                    PlayerPrefs.SetString("o0GyrCalibrater", JsonConvert.SerializeObject(GyrCalibrater));
+
+                }
+                else
+                {
+                    GyrCalibrater.Calibration = true;
+                    GyrCalibrationButton.GetComponentInChildren<Text>().text = "停止陀螺仪校准";
+                }
+            });
+        }
+    }
+
+    private void OnValueChanged(bool value)
+    {
+        if (value)
+        {
+            //选中了的逻辑
+        }
+        Debug.Log(value);
+    }
+
+    
+
+    public void OnDataReceived(byte[] bytes)
+    {
+        // Debug.Log("瞄准模块数据长度" + bytes.Length);
+        if (bytes.Length != 26)
+        {
+            if (bytes[3] == 125)
+            {
+                DoIdentity();
+            }
+            return;
+        }
+        if (bytes[4] == 0 && bytes[5] == 0 && bytes[6] == 0 && bytes[7] == 0 && bytes[8] == 0 && bytes[9] == 0)
+            return;
+        if (bytes[16] == 0 && bytes[17] == 0 && bytes[18] == 0 && bytes[19] == 0 && bytes[20] == 0 && bytes[21] == 0)
+            return;
+        
+        float ax = -TwoByteToFloat(bytes[4], bytes[5]);
+        float ay = TwoByteToFloat(bytes[6], bytes[7]);
+        float az = -TwoByteToFloat(bytes[8], bytes[9]);
+        ax = ax / 32768 * 16;
+        ay = ay / 32768 * 16;
+        az = az / 32768 * 16;
+        Acc = new Vector3(ax, ay, az);
+        AccObj.transform.GetChild(0).localPosition = Acc;
+
+
+        float roll = TwoByteToFloat(bytes[10], bytes[11]);
+        float pitch = TwoByteToFloat(bytes[12], bytes[13]);
+        float yaw = TwoByteToFloat(bytes[14], bytes[15]);
+        roll = -roll / 32768 * 2000;
+        pitch = pitch / 32768 * 2000;
+        yaw = -yaw / 32768 * 2000;
+        Gyr = new Vector3(roll, pitch, yaw) / 1000;
+        Gyr = GyrCalibrater.Update(Gyr);
+        if (GyrScaleText && GyrCalibrater.Calibration) 
+        {    
+            // GyrScaleText.text = GyrCalibrater._Average.x + "\n" + GyrCalibrater._Average.y + "\n" + GyrCalibrater._Average.z;
+            // GyrScaleText.text = "Gyr*1000,000:" + (_9Axis.GyrOld * 1000000).ToString();
+            GyrScaleText.text = "" + (_9Axis.GyrOld * 1000000).ToString();
+        }
+
+        float x = TwoByteToFloat(bytes[16], bytes[17]);
+        float y = TwoByteToFloat(bytes[18], bytes[19]);
+        float z = -TwoByteToFloat(bytes[20], bytes[21]);
+        var mag = new Vector3(x, y, z);
+        Mag = mag / 32768 * 256;
+    
+
+        if(Mag.x > -128 && Mag.y > -128 && Mag.z > -128 && Mag.x < 128 && Mag.y < 128 && Mag.z < 128)
+        {   
+            //绘制地磁计点
+            if (MagCalibrater.Calibration)
+            {
+                this.ellipseScript.AddAndUpdatePointArray(Mag);
+
+                if (Mag.magnitude > this.cMaxVector.magnitude)
+                {
+                    this.cMaxVector = Mag;
+                }
+                else if (Mag.magnitude < this.cMinVector.magnitude) {
+                    this.cMinVector = Mag;
+                }
+
+                Vector3 _center = this.cMaxVector - this.cMinVector;
+                Debug.LogWarning(_center + " == "+ _center.magnitude);
+                //设置绘制图像相机的对应位置
+                this.ellipseScript.setCameraPos(_center/2);
+            }
+            Mag = MagCalibrater.Update(Mag);
+
+            if (MagScaleText)
+            {
+                MagScaleText.text = MagCalibrater._Radius.ToString();
+            }
+           
+        }
+        MagObj.transform.GetChild(0).localPosition = Mag;
+
+        var ms = (((long)bytes[22]) *60 + bytes[23])*1000 + (long)TwoByteToFloat(bytes[1], bytes[2]);
+        if(msOld == default)
+        {
+            msOld = ms;
+            return;
+        }
+        TimeGap = ms - msOld;
+        msOld = ms;
+
+        AMesh.transform.localRotation = newRotation = _9Axis.Update(Acc * 10, Gyr, Mag, TimeGap);
+        Quaternion nextRotation = controlObj.localRotation;
+        filter.Update(ref nextRotation, newRotation);
+        newRotation = nextRotation;
+
+        // 记录一些旋转角---start
+        if (ArmBow.ins) {
+            for (int i = ArmBow.ins.recordRotations.Length - 1; i > 0 ; i--)
+            {
+                ArmBow.ins.recordRotations[i] = ArmBow.ins.recordRotations[i - 1];
+            }
+            ArmBow.ins.recordRotations[0] = newRotation;
+            ArmBow.ins.recordCount++;
+        }
+        // 记录一些旋转角---end
+
+        receiveDataCount++;
+        if (!hasAutoIdentity && receiveDataCount == 5) {
+            doIdentity = true;
+        }
+    }   
+
+    void DoIdentity()
+    {
+        if (hasAutoIdentity)
+        {
+            doIdentity = true;
+            Debug.Log("reset identity");
+        }
+    }
+
+    public void Update()
+    {
+        if (hasAutoIdentity && controlObj)
+        {
+            // 最终结果进行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;
+                
+        }
+        if (doIdentity)
+        {
+            // _9Axis.SetIdentityAccordingToRecords();
+            _9Axis.SetIdentity();
+            if (controlObj)
+            {
+                controlObj.localRotation = _9Axis.States.Last().Qua;
+            }
+            doIdentity = false;
+            hasAutoIdentity = true;
+        }
+    }
+
+    int receiveDataCount = 0;
+    bool doIdentity = false;
+    bool hasAutoIdentity = false;
+    Quaternion newRotation;
+
+    public void InitAutoIdentity() 
+    {
+        receiveDataCount = 0;
+        doIdentity = false;
+        hasAutoIdentity = false;
+    }
+
+    public void SetControlObject(Transform obj)
+    {
+        controlObj = obj;
+        if (controlObj) InitAutoIdentity();
+    }
+}

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

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

+ 6 - 410
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -2,43 +2,18 @@
 using System;
 using UnityEngine;
 using System.Collections.Generic;
-using System.Linq;
 using UnityEngine.UI;
-using Newtonsoft.Json;
-using o0Aien;
 
 public class BluetoothAim : MonoBehaviour
 {
     BluetoothHelper bluetoothHelper;
     BluetoothHelperCharacteristic characteristicWrite;
     BluetoothHelperService bluetoothService;
+    string targetDeviceName = "Bbow_20210501";
     string deviceName = "";
     bool canConnect = true;
-
-    [SerializeField] string targetDeviceName = "Bbow_20210501";
-  
     [SerializeField] Text textUI;
-    [SerializeField] Transform controlObj = default;
-    [SerializeField] Button SetIdentity = default;
-    [SerializeField] Button MagCalibrationButton = default;
-    [SerializeField] Button GyrCalibrationButton = default;
-    [SerializeField] Text MagScaleText = default;
-    [SerializeField] Text GyrScaleText = default;
-    [SerializeField] Text OriginalDataText = default;
-
-    [SerializeField] public Transform testEllipse;
-    [SerializeField] public Transform testEllipseToggle;
-
-    AimHandler aimHandler = null;
-
     public static bool scanLock = false; //防止同时扫描冲突
-    
-    void Start()
-    {
-        aimHandler = new AimHandler(controlObj, SetIdentity, MagCalibrationButton, GyrCalibrationButton, MagScaleText, GyrScaleText,OriginalDataText, testEllipse, testEllipseToggle);
-        BluetoothDispatcher.aim = aimHandler.OnDataReceived;
-
-    }
 
     void OnDestroy()
     {
@@ -53,11 +28,6 @@ public class BluetoothAim : MonoBehaviour
         Connect();
     }
 
-    void Update()
-    {
-        aimHandler.Update();   
-    }
-
     void Connect()
     {
         if (BluetoothShoot.scanLock)
@@ -113,7 +83,10 @@ public class BluetoothAim : MonoBehaviour
                 byte[] bytes = value;
                 // Log(String.Join(",", bytes));
                 BluetoothClient.UploadData(0, bytes);
-                aimHandler.OnDataReceived(bytes);
+                if (AimHandler.ins)
+                {
+                    AimHandler.ins.OnDataReceived(bytes);
+                }
             };
             bluetoothHelper.OnScanEnded += (BluetoothHelper helper, LinkedList<BluetoothDevice> nearbyDevices) =>
             {
@@ -154,386 +127,9 @@ public class BluetoothAim : MonoBehaviour
 
     void Log(string text)
     {
-        if (textUI != null) 
+        if (textUI) 
         {
             textUI.text = text;
         }
     }
-
-    public void SetControlObject(Transform obj)
-    {
-        this.aimHandler.controlObj = obj;
-        if (obj != null)
-        {
-            this.aimHandler.InitAutoIdentity();
-        }
-    }
-}
-
-class AimHandler
-{
-    public Transform controlObj;
-    Button SetIdentity = default;
-    Button MagCalibrationButton = default;
-    Button GyrCalibrationButton = default;
-    Text MagScaleText = default;
-    Text GyrScaleText = default;
-    Text OriginalDataText = default;
-
-    long TimeGap = default;
-    Vector3 Acc = default;
-    Vector3 Gyr = default;
-    Vector3 Mag = default;
-    o09Axis _9Axis = new o09Axis();
-    
-    o0SigmoidIntegrationFilterQuaternion filter = new o0SigmoidIntegrationFilterQuaternion(0.2f);
-
-    //椭圆对象
-    Transform testEllipse;
-    public Ellipse ellipseScript;
-    public Toggle ellipseToggle;
-
-    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;
-
-    public AimHandler(
-        Transform controlObj, 
-        Button SetIdentity, 
-        Button MagCalibrationButton, 
-        Button GyrCalibrationButton, 
-        Text MagScaleText,
-        Text GyrScaleText,
-        Text OriginalDataText,
-         //椭圆对象
-        Transform testEllipse,
-        Transform testToggle
-    ) {
-        this.controlObj = controlObj;
-        this.SetIdentity = SetIdentity;
-        this.MagCalibrationButton = MagCalibrationButton;
-        this.GyrCalibrationButton = GyrCalibrationButton;
-        this.MagScaleText = MagScaleText;
-        this.GyrScaleText = GyrScaleText;
-        this.OriginalDataText = OriginalDataText;
-         //椭圆对象
-        this.testEllipse = testEllipse;
-        this.ellipseScript = this.testEllipse.gameObject.GetComponent<Ellipse>();
-        this.ellipseToggle = testToggle.gameObject.GetComponent<Toggle>();
-        this.ellipseToggle.onValueChanged.AddListener(OnValueChanged);
-
-
-        for (var i = 0; i < 9; ++i)
-        {
-            _9Axis.Tester.Add(GameObject.Find("Canvas").transform.Find("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>());
-        }
-
-        if (SetIdentity != null) 
-        {
-            SetIdentity.onClick.AddListener(DoIdentity);
-        }
-        
-        try 
-        {  
-            string magDataStr = PlayerPrefs.GetString("o0MagneticCalibrater");
-            MagCalibrater = JsonConvert.DeserializeObject<o0MagneticCalibraterEllipsoidFitting>(magDataStr);
-        } 
-        catch(Exception) 
-        {
-            MagCalibrater = null;
-        }
-
-        if (MagCalibrater == null) 
-        {
-            MagCalibrater = new o0MagneticCalibraterEllipsoidFitting();
-        }
-        if (MagCalibrationButton != null)
-        {
-            MagCalibrationButton.onClick.AddListener(delegate {
-                if (MagCalibrater.Calibration)
-                {
-                    List<Vector3> list = MagCalibrater.getRecords();
-                    //停止校准时候,看看数组值
-                    float maxDistance = 0f,ratio = 1f;
-                    Vector3 maxVector3 = new Vector3(0,0,0);
-                    List<Vector3> endRecords = new List<Vector3>();
-                    foreach (Vector3 i in list)
-                    {
-                        Vector3 v = i - MagCalibrater._Center;
-                        if (Math.Abs(v.magnitude) > maxDistance)
-                        {
-                            maxVector3 = v;
-                            maxDistance = Math.Abs(v.magnitude);
-                            if(Math.Abs(v.magnitude) < Math.Abs(MagCalibrater._Radius.magnitude))
-                                ratio = Math.Abs(v.magnitude) / Math.Abs(MagCalibrater._Radius.magnitude);
-                            else
-                                ratio = Math.Abs(MagCalibrater._Radius.magnitude) / Math.Abs(v.magnitude);
-                        }
-                    }
-                    Debug.LogWarning(maxDistance + " == " + Math.Abs(MagCalibrater._Radius.magnitude) + " == " + MagCalibrater._Radius + " = " + maxVector3);
-                    //如果比例效果不理想。可以设置为ratio=0.5f 
-                    foreach (Vector3 i in list)
-                    {
-                        //- MagCalibrater._Center
-                        Vector3 v = i ;
-                        v *= ratio;
-                        if(endRecords.Count>3000)
-                        {
-                            endRecords.RemoveAt(0);
-                        }
-                        endRecords.Add(v);
-                    }
-                    this.ellipseScript.ClearAndUpdatePointArray();
-                    this.ellipseScript.DrawPointCloud(endRecords);
-
-                    //绘制椭圆形
-                    if (MagCalibrater._Radius != this.ellipseScript.ellipseTran.localScale)
-                    {
-                        this.ellipseScript.setEllipseLocalScaleAndCenter(MagCalibrater._Radius, MagCalibrater._Center* ratio);
-                        //设置绘制图像相机的对应位置
-                        this.ellipseScript.setCameraPos(MagCalibrater._Center * 0.5f);
-                    }
-
-                    MagCalibrater.Calibration = false;
-                    MagCalibrationButton.GetComponentInChildren<Text>().text = "开始地磁计校准";
-                    PlayerPrefs.SetString("o0MagneticCalibrater", JsonConvert.SerializeObject(MagCalibrater));
-
-                }
-                else
-                {
-                    MagCalibrater.Calibration = true;
-                    MagCalibrationButton.GetComponentInChildren<Text>().text = "停止地磁计校准";
-
-                    this.cMaxVector = new Vector3(0, 0, 0);
-                    this.cMinVector = new Vector3(0, 0, 0);
-                }
-            });
-        }
-
-        try {
-            string gyrDataStr = PlayerPrefs.GetString("o0GyrCalibrater");
-            GyrCalibrater = JsonConvert.DeserializeObject<o0GyrCalibrater>(gyrDataStr);
-            if (GyrCalibrater._Average != Vector3.zero) GyrScaleText.text = "已校准";
-        } catch(Exception) {
-            GyrCalibrater = null;
-        }
-        if (GyrCalibrater == null) 
-        {
-            GyrCalibrater = new o0GyrCalibrater();
-        }
-        if (GyrCalibrationButton != null)
-        {
-            GyrCalibrationButton.onClick.AddListener(delegate {
-                if (GyrCalibrater.Calibration)
-                {
-                    GyrCalibrater.Calibration = false;
-                    GyrCalibrationButton.GetComponentInChildren<Text>().text = "开始陀螺仪校准";
-                    PlayerPrefs.SetString("o0GyrCalibrater", JsonConvert.SerializeObject(GyrCalibrater));
-
-                }
-                else
-                {
-                    GyrCalibrater.Calibration = true;
-                    GyrCalibrationButton.GetComponentInChildren<Text>().text = "停止陀螺仪校准";
-                }
-            });
-        }
-    }
-    private void OnValueChanged(bool value)
-    {
-        if (value)
-        {
-           
-            //选中了的逻辑
-        }
-        Debug.Log(value);
-    }
-
-    GameObject AccObj = GameObject.Find("Acc");
-    GameObject MagObj = GameObject.Find("Mag");
-    GameObject AMesh = GameObject.Find("AMesh");
-
-    public void OnDataReceived(byte[] bytes)
-    {
-        // Debug.Log("瞄准模块数据长度" + bytes.Length);
-        if (bytes.Length != 26)
-        {
-            if (bytes[3] == 125)
-            {
-                DoIdentity();
-            }
-            return;
-        }
-        if (bytes[4] == 0 && bytes[5] == 0 && bytes[6] == 0 && bytes[7] == 0 && bytes[8] == 0 && bytes[9] == 0)
-            return;
-        if (bytes[16] == 0 && bytes[17] == 0 && bytes[18] == 0 && bytes[19] == 0 && bytes[20] == 0 && bytes[21] == 0)
-            return;
-        
-        float ax = -TwoByteToFloat(bytes[4], bytes[5]);
-        float ay = TwoByteToFloat(bytes[6], bytes[7]);
-        float az = -TwoByteToFloat(bytes[8], bytes[9]);
-        ax = ax / 32768 * 16;
-        ay = ay / 32768 * 16;
-        az = az / 32768 * 16;
-        Acc = new Vector3(ax, ay, az);
-        AccObj.transform.GetChild(0).localPosition = Acc;
-
-
-        float roll = TwoByteToFloat(bytes[10], bytes[11]);
-        float pitch = TwoByteToFloat(bytes[12], bytes[13]);
-        float yaw = TwoByteToFloat(bytes[14], bytes[15]);
-        roll = -roll / 32768 * 2000;
-        pitch = pitch / 32768 * 2000;
-        yaw = -yaw / 32768 * 2000;
-        Gyr = new Vector3(roll, pitch, yaw) / 1000;
-        Gyr = GyrCalibrater.Update(Gyr);
-        if (GyrScaleText != null && GyrCalibrater.Calibration) 
-        {    
-            // GyrScaleText.text = GyrCalibrater._Average.x + "\n" + GyrCalibrater._Average.y + "\n" + GyrCalibrater._Average.z;
-            // GyrScaleText.text = "Gyr*1000,000:" + (_9Axis.GyrOld * 1000000).ToString();
-            GyrScaleText.text = "" + (_9Axis.GyrOld * 1000000).ToString();
-        }
-
-        float x = TwoByteToFloat(bytes[16], bytes[17]);
-        float y = TwoByteToFloat(bytes[18], bytes[19]);
-        float z = -TwoByteToFloat(bytes[20], bytes[21]);
-        var mag = new Vector3(x, y, z);
-        Mag = mag / 32768 * 256;
-    
-
-        if(Mag.x > -128 && Mag.y > -128 && Mag.z > -128 && Mag.x < 128 && Mag.y < 128 && Mag.z < 128)
-        {   
-            //绘制地磁计点
-            if (MagCalibrater.Calibration)
-            {
-                this.ellipseScript.AddAndUpdatePointArray(Mag);
-
-                if (Mag.magnitude > this.cMaxVector.magnitude)
-                {
-                    this.cMaxVector = Mag;
-                }
-                else if (Mag.magnitude < this.cMinVector.magnitude) {
-                    this.cMinVector = Mag;
-                }
-
-                Vector3 _center = this.cMaxVector - this.cMinVector;
-                Debug.LogWarning(_center + " == "+ _center.magnitude);
-                //设置绘制图像相机的对应位置
-                this.ellipseScript.setCameraPos(_center/2);
-            }
-            Mag = MagCalibrater.Update(Mag);
-
-            if (MagScaleText != null)
-            {
-                MagScaleText.text = MagCalibrater._Radius.ToString();
-            }
-           
-        }
-        MagObj.transform.GetChild(0).localPosition = Mag;
-
-        var ms = (((long)bytes[22]) *60 + bytes[23])*1000 + (long)TwoByteToFloat(bytes[1], bytes[2]);
-        if(msOld == default)
-        {
-            msOld = ms;
-            return;
-        }
-        TimeGap = ms - msOld;
-        msOld = ms;
-
-        AMesh.transform.localRotation = newRotation = _9Axis.Update(Acc * 10, Gyr, Mag, TimeGap);
-        Quaternion nextRotation = controlObj.localRotation;
-        filter.Update(ref nextRotation, newRotation);
-        newRotation = nextRotation;
-
-        // 记录一些旋转角---start
-        if (ArmBow.ins != null) {
-            for (int i = ArmBow.ins.recordRotations.Length - 1; i > 0 ; i--)
-            {
-                ArmBow.ins.recordRotations[i] = ArmBow.ins.recordRotations[i - 1];
-            }
-            ArmBow.ins.recordRotations[0] = newRotation;
-            ArmBow.ins.recordCount++;
-        }
-        // 记录一些旋转角---end
-
-        receiveDataCount++;
-        if (!hasAutoIdentity && receiveDataCount == 5) {
-            doIdentity = true;
-        }
-    }   
-
-    void DoIdentity()
-    {
-        if (hasAutoIdentity)
-        {
-            doIdentity = true;
-            Debug.Log("reset identity");
-        }
-    }
-
-    public void Update()
-    {
-        if (hasAutoIdentity && controlObj != null)
-        {
-            // 最终结果进行lerp
-            // controlObj.localRotation = Quaternion.Lerp(controlObj.localRotation, newRotation, Time.deltaTime * 6);
-            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;
-                
-        }
-        if (doIdentity)
-        {
-            // _9Axis.SetIdentityAccordingToRecords();
-            _9Axis.SetIdentity();
-            if (controlObj != null)
-            {
-                controlObj.localRotation = _9Axis.States.Last().Qua;
-            }
-            doIdentity = false;
-            hasAutoIdentity = true;
-        }
-    }
-
-    int receiveDataCount = 0;
-    bool doIdentity = false;
-    bool hasAutoIdentity = false;
-    Quaternion newRotation;
-
-    public void InitAutoIdentity() 
-    {
-        receiveDataCount = 0;
-        doIdentity = false;
-        hasAutoIdentity = false;
-    }
 }

+ 4 - 15
Assets/BowArrow/Scripts/Bluetooth/BluetoothShoot.cs

@@ -10,13 +10,10 @@ public class BluetoothShoot : MonoBehaviour
     BluetoothHelper bluetoothHelper;
     BluetoothHelperCharacteristic characteristicWrite;
     BluetoothHelperService bluetoothService;
+    string targetDeviceName = "BArrow_202105";
     string deviceName = "";
     bool canConnect = true;
-    bool bFirstIn = true;
-    // string targetDeviceName = "BGBox_202012";
-    string targetDeviceName = "BArrow_202105";
     [SerializeField] Text textUI;
-
     public static bool scanLock = false; //防止同时扫描冲突
 
     void OnDestroy()
@@ -85,17 +82,9 @@ public class BluetoothShoot : MonoBehaviour
             bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
             {
                 byte[] bytes = value;
-
-                if(bFirstIn)
-                {
-                    bFirstIn = false;
-                    Log(String.Join(",", bytes));
-                    return;
-                }
-
                 // Log(String.Join(",", bytes));
                 BluetoothClient.UploadData(1, bytes);
-                if (ShootCheck.ins != null)
+                if (ShootCheck.ins)
                 {
                     ShootCheck.ins.OnDataReceived(bytes);
                 }
@@ -134,7 +123,7 @@ public class BluetoothShoot : MonoBehaviour
         WriteData("5");
         Sequence sequence = DOTween.Sequence();
         sequence.PrependInterval(1).AppendCallback(delegate() {
-            if (ShootCheck.ins != null)
+            if (ShootCheck.ins)
             {
                 ShootCheck.ins.OnBluetoothReady(this);
                 Log("射击模块准备完成\n" + deviceName);
@@ -151,7 +140,7 @@ public class BluetoothShoot : MonoBehaviour
 
     void Log(string text)
     {
-        if (textUI != null) 
+        if (textUI) 
         {
             textUI.text = text;
         }

+ 2 - 2
Assets/BowArrow/Scripts/Bluetooth/ShootCheck.cs

@@ -130,7 +130,7 @@ public class ShootCheck : MonoBehaviour
             }    
             if (ins.check(acc))
             {
-                if (ArmBow.ins != null)
+                if (ArmBow.ins)
                 {
                     ArmBow.ins.ADS_fire();   
                     // if (webSocket != null)
@@ -192,7 +192,7 @@ public class ShootCheck : MonoBehaviour
     
     void Log(string text)
     {
-        if (this.text != null)
+        if (this.text)
         {
             this.text.text = text;
         } else {

+ 3 - 3
Assets/BowArrow/Scripts/Game/ArmBow.cs

@@ -33,7 +33,7 @@ public class ArmBow : MonoBehaviour
     {
         if (this.canShoot)
         {
-            if (DebugBowPower.ins != null) DebugBowPower.ins.DoUpdate();
+            if (DebugBowPower.ins) DebugBowPower.ins.DoUpdate();
         }
     }
 
@@ -79,7 +79,7 @@ public class ArmBow : MonoBehaviour
         AP_arm.completeCallback = null;
         this.pulling = false;
         this.canShoot = false;
-        if (DebugBowPower.ins != null) DebugBowPower.ins.Init();
+        if (DebugBowPower.ins) DebugBowPower.ins.Init();
     }
 
     public void idleToADS() {
@@ -93,7 +93,7 @@ public class ArmBow : MonoBehaviour
     void ADS_idle() {
         this.canShoot = true;
         this.pulling = false;
-        if (DebugBowPower.ins != null) DebugBowPower.ins.PullFinish();
+        if (DebugBowPower.ins) DebugBowPower.ins.PullFinish();
     }
 
     public void ADS_fire() {

+ 4 - 4
Assets/BowArrow/Scripts/Game/Arrow.cs

@@ -24,7 +24,7 @@ public class Arrow : MonoBehaviour
     }
 
     void OnDestroy() {
-        if (this.newRigidbody != null) 
+        if (this.newRigidbody) 
         {
             Destroy(this.newRigidbody);
         }
@@ -35,14 +35,14 @@ public class Arrow : MonoBehaviour
 
     void FixedUpdate()
     {
-        if (newRigidbody != null) {
+        if (newRigidbody) {
             transform.forward = newRigidbody.velocity.normalized;
         }
         if (!isHit && flyTime >= 0) {
             flyTime += Time.deltaTime;
             this.position = this.transform.position;
             this.rotation = this.transform.rotation;
-            if (flyTime > 20.0) {
+            if (flyTime > 6.0) {
                 Destroy(gameObject);
                 GameMgr.ins.hitTarget(0);
                 AudioMgr.ins.PlayCheer(false);
@@ -59,7 +59,7 @@ public class Arrow : MonoBehaviour
 
     public void Hit() {
         gameObject.GetComponent<BoxCollider>().enabled = false;
-        if (newRigidbody != null) {
+        if (newRigidbody) {
             newRigidbody.useGravity = false;
             newRigidbody.velocity = Vector3.zero;
             Destroy(newRigidbody);

+ 1 - 1
Assets/BowArrow/Scripts/Game/TargetBody.cs

@@ -4,7 +4,7 @@ public class TargetBody : MonoBehaviour
 {
     void OnCollisionEnter(Collision collision) {
         Arrow arrow = collision.transform.GetComponent<Arrow>();
-        if (arrow != null)
+        if (arrow)
         {
             arrow.transform.Find("Head").position = collision.contacts[0].point;
             arrow.Hit();

+ 1 - 1
Assets/BowArrow/Scripts/Game/TargetOutBound.cs

@@ -7,7 +7,7 @@ public class TargetOutBound : MonoBehaviour
     void OnCollisionEnter(Collision collision) 
     {
         Arrow arrow = collision.transform.GetComponent<Arrow>();
-        if (arrow != null)
+        if (arrow)
         {
             arrow.flyTime = 100;
         }

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

@@ -11,11 +11,11 @@ public class GameResultView : MonoBehaviour
 
     void Start()
     {
-        if (ChallengeGameView.ins != null)
+        if (ChallengeGameView.ins)
         {
             ChallengeGameView.ins.gameObject.SetActive(false);
         }
-        if (TimeLimitGameView.ins != null)
+        if (TimeLimitGameView.ins)
         {
             TimeLimitGameView.ins.gameObject.SetActive(false);
         }