|
@@ -244,6 +244,21 @@ public class AimHandler : MonoBehaviour
|
|
|
if (bytes[19] == 0 && bytes[20] == 0 && bytes[21] == 0 && bytes[22] == 0 && bytes[23] == 0 && bytes[24] == 0)
|
|
if (bytes[19] == 0 && bytes[20] == 0 && bytes[21] == 0 && bytes[22] == 0 && bytes[23] == 0 && bytes[24] == 0)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
|
|
+ if (ban9AxisCalculate) //如果箭射出后禁止九轴计算,就缓存最新几帧九轴数据
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ if (cached9AxisFrames.Count < 3)
|
|
|
|
|
+ {
|
|
|
|
|
+ cached9AxisFrames.Enqueue(bytes);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ cached9AxisFrames.Dequeue();
|
|
|
|
|
+ cached9AxisFrames.Enqueue(bytes);
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
float ax = TwoByteToFloat(bytes[7], bytes[8]);
|
|
float ax = TwoByteToFloat(bytes[7], bytes[8]);
|
|
|
float ay = TwoByteToFloat(bytes[9], bytes[10]);
|
|
float ay = TwoByteToFloat(bytes[9], bytes[10]);
|
|
|
float az = TwoByteToFloat(bytes[11], bytes[12]);
|
|
float az = TwoByteToFloat(bytes[11], bytes[12]);
|
|
@@ -352,9 +367,20 @@ public class AimHandler : MonoBehaviour
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private bool ban9AxisCalculate = false;
|
|
private bool ban9AxisCalculate = false;
|
|
|
|
|
+ private Queue<byte[]> cached9AxisFrames = new Queue<byte[]>();
|
|
|
public void Ban9AxisCalculate(bool ban) {
|
|
public void Ban9AxisCalculate(bool ban) {
|
|
|
ban9AxisCalculate = ban;
|
|
ban9AxisCalculate = ban;
|
|
|
if (!ban) {
|
|
if (!ban) {
|
|
|
|
|
+ //恢复九轴计算时,把缓存的最新几帧计算了
|
|
|
|
|
+ while (cached9AxisFrames.Count > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ OnDataReceived(cached9AxisFrames.Dequeue());
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception) { }
|
|
|
|
|
+ }
|
|
|
|
|
+ //立马应用到控制物体中
|
|
|
if (controlObj) controlObj.localRotation = newRotation;
|
|
if (controlObj) controlObj.localRotation = newRotation;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|