|
|
@@ -4,11 +4,21 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using UnityEngine.UI;
|
|
|
using Newtonsoft.Json;
|
|
|
-using o0Aien;
|
|
|
|
|
|
public class AimHandler : MonoBehaviour
|
|
|
{
|
|
|
- [SerializeField] Transform controlObj;
|
|
|
+ Transform controlObj {
|
|
|
+ get {
|
|
|
+ CameraToLook ctl = CameraToLook.ins;
|
|
|
+ if (ctl && ctl.isNew)
|
|
|
+ {
|
|
|
+ ctl.isNew = false;
|
|
|
+ InitAutoIdentity();
|
|
|
+ }
|
|
|
+ if (ctl) return ctl.transform;
|
|
|
+ else return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
[SerializeField] Button SetIdentityButton;
|
|
|
[SerializeField] Button MagCalibrationButton;
|
|
|
[SerializeField] Button GyrCalibrationButton;
|
|
|
@@ -285,56 +295,42 @@ public class AimHandler : MonoBehaviour
|
|
|
}
|
|
|
// 记录一些旋转角---end
|
|
|
|
|
|
- receiveDataCount++;
|
|
|
- if (!hasAutoIdentity && receiveDataCount == 5) {
|
|
|
- doIdentity = true;
|
|
|
- }
|
|
|
+ checkAutoIdentity();
|
|
|
}
|
|
|
|
|
|
- void DoIdentity()
|
|
|
- {
|
|
|
- if (hasAutoIdentity)
|
|
|
- {
|
|
|
- doIdentity = true;
|
|
|
- Debug.Log("reset identity");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public void Update()
|
|
|
{
|
|
|
- if (hasAutoIdentity && controlObj)
|
|
|
+ if (controlObj && hasAutoIdentity)
|
|
|
{
|
|
|
// 最终结果进行lerp
|
|
|
controlObj.localRotation = Quaternion.Lerp(controlObj.localRotation, newRotation, Time.deltaTime * 8);
|
|
|
// controlObj.localRotation = newRotation;
|
|
|
}
|
|
|
- if (doIdentity)
|
|
|
- {
|
|
|
- _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()
|
|
|
+ void InitAutoIdentity()
|
|
|
{
|
|
|
receiveDataCount = 0;
|
|
|
- doIdentity = false;
|
|
|
hasAutoIdentity = false;
|
|
|
}
|
|
|
|
|
|
- public void SetControlObject(Transform obj)
|
|
|
+ void checkAutoIdentity()
|
|
|
+ {
|
|
|
+ receiveDataCount++;
|
|
|
+ if (!hasAutoIdentity && receiveDataCount == 5) {
|
|
|
+ hasAutoIdentity = true;
|
|
|
+ DoIdentity();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void DoIdentity()
|
|
|
{
|
|
|
- controlObj = obj;
|
|
|
- if (controlObj) InitAutoIdentity();
|
|
|
+ if (!hasAutoIdentity) return;
|
|
|
+ _9Axis.SetIdentity();
|
|
|
+ if (controlObj) controlObj.localRotation = _9Axis.States.Last().Qua;
|
|
|
}
|
|
|
}
|