lvjincheng 5 gadi atpakaļ
vecāks
revīzija
a511f0d738

+ 7 - 7
Assets/BowArrow/Scenes/Game.unity

@@ -264,7 +264,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 0, y: 1}
-  m_AnchoredPosition: {x: 3000, y: -206}
+  m_AnchoredPosition: {x: 10, y: -206}
   m_SizeDelta: {x: 380, y: 134}
   m_Pivot: {x: 0, y: 1}
 --- !u!114 &29012941
@@ -3117,7 +3117,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 1
+  m_IsActive: 0
 --- !u!224 &391527373
 RectTransform:
   m_ObjectHideFlags: 0
@@ -8182,7 +8182,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 0
+  m_IsActive: 1
 --- !u!224 &1105832656
 RectTransform:
   m_ObjectHideFlags: 0
@@ -8200,7 +8200,7 @@ RectTransform:
   m_AnchorMin: {x: 1, y: 1}
   m_AnchorMax: {x: 1, y: 1}
   m_AnchoredPosition: {x: -30, y: -265}
-  m_SizeDelta: {x: 192, y: 35.333332}
+  m_SizeDelta: {x: 0, y: 0}
   m_Pivot: {x: 1, y: 1}
 --- !u!114 &1105832657
 MonoBehaviour:
@@ -10664,7 +10664,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 0
+  m_IsActive: 1
 --- !u!224 &1478558956
 RectTransform:
   m_ObjectHideFlags: 0
@@ -12143,7 +12143,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 0
+  m_IsActive: 1
 --- !u!4 &1680053129
 Transform:
   m_ObjectHideFlags: 0
@@ -14720,7 +14720,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 0
+  m_IsActive: 1
 --- !u!224 &1990278317
 RectTransform:
   m_ObjectHideFlags: 0

+ 4 - 70
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -171,71 +171,7 @@ class AimHandler
     Vector3 Acc = default;
     Vector3 Gyr = default;
     Vector3 Mag = default;
-
-    static Vector3 AccIdentity = new Vector3(0, -1, 0);
-    static Vector3 MagIdentity = new Vector3(-1, 2, 0).normalized;
-    public class State
-    {
-        public long TimeGap;
-        public Vector3 Acc = AccIdentity;
-        public Vector3 Gyr;
-        public Vector3 Mag = MagIdentity;
-        public Quaternion Qua;
-        public float Variance = 1;
-    }
-    List<State> States = new List<State>();
-
-    long TimeGapOld;
-    Vector3 AccOld;
-    Vector3 GyrOld;
-    Vector3 MagOld;
-
-    Quaternion o06DOFUpdate(Vector3 AccOld, Vector3 GyrOld, Vector3 MagOld, long TimeGapOld)
-    {
-        var Acc = this.AccOld;
-        var Gyr = this.GyrOld;
-        var Mag = this.MagOld;
-        float TimeGap = (TimeGapOld + this.TimeGapOld) / 2;
-        this.AccOld = AccOld;
-        this.GyrOld = GyrOld;
-        this.MagOld = MagOld;
-        this.TimeGapOld = TimeGapOld;
-
-        var Last = States.LastOrDefault() ?? new State();
-        States.Add(new State());
-        if (States.Count > 10)
-            States.RemoveAt(0);
-        var state = States.Last();
-        state.Acc = Acc;
-        state.Gyr = Gyr;
-        state.Mag = Mag;
-
-        var LastQuaternion = Last.Qua;
-
-        var newQua = new Quaternion();
-        newQua.eulerAngles = Gyr * TimeGap;
-        var quaGyr = LastQuaternion * newQua;
-
-        float AccLengthToAngle = 180;//1倍引力差相当于多少度方差
-        float MagLengthToAngle = 180;//1倍磁力差相当于多少度方差
-
-        float GyrVariance = Last.Variance + (Gyr * TimeGap).magnitude * 0.05f;
-        float AccVariance = Mathf.Max(TimeGap / 1, Mathf.Sqrt(Mathf.Pow((Acc.magnitude - 9.8f) / 9.8f * AccLengthToAngle, 2)+ Mathf.Pow(Vector3.Angle(Acc,Last.Acc) * 0.8f, 2)));
-        float MagVariance = Mathf.Max(TimeGap / 0.2f,Mathf.Sqrt(Mathf.Pow((Mag.magnitude - 1) / 1 * MagLengthToAngle, 2) + Mathf.Pow(Vector3.Angle(Mag, Last.Mag) * 0.05f, 2)));
-        state.Variance = state.Variance * AccVariance / (state.Variance + AccVariance);
-        state.Variance = state.Variance * MagVariance / (state.Variance + MagVariance);
-
-        var quaAccMag = o0Project.o0.FormQuaternion(AccIdentity, MagIdentity, Acc, Mag, AccVariance / (AccVariance + MagVariance));
-
-        var quaMinRate = GyrVariance / (GyrVariance + Mathf.Max(AccVariance, MagVariance));
-        var quaMaxRate = GyrVariance / (GyrVariance + Mathf.Min(AccVariance, MagVariance));
-        Quaternion quaFirst = Quaternion.Slerp(quaGyr, quaAccMag, quaMinRate).normalized;
-
-        float quaSecondRate = (quaMaxRate - quaMinRate) / (1 - quaMinRate);
-        state.Qua = AccVariance < MagVariance ? o0Project.o0.FormQuaternion(quaFirst, AccIdentity, Acc, quaSecondRate): o0Project.o0.FormQuaternion(quaFirst, MagIdentity, Mag, quaSecondRate);
-
-        return state.Qua;
-    }
+    o09Axis _9Axis = new o09Axis();
 
 
     //转换读取的数据,无符号->有符号
@@ -300,7 +236,7 @@ class AimHandler
 
     public void OnDataReceived(byte[] bytes)
     {
-        Debug.Log("瞄准模块数据长度" + bytes.Length);
+        // Debug.Log("瞄准模块数据长度" + bytes.Length);
         if (bytes.Length != 26)
         {
             if (bytes[3] == 125)
@@ -354,7 +290,7 @@ class AimHandler
         TimeGap = ms - msOld;
         msOld = ms;
 
-        newRotation = o06DOFUpdate(Acc * 10, Gyr, Mag, TimeGap);
+        newRotation = _9Axis.Update(Acc * 10, Gyr, Mag, TimeGap);
         
         receiveDataCount++;
         if (!hasAutoIdentity && receiveDataCount == 5) {
@@ -379,9 +315,7 @@ class AimHandler
         }
         if (doIdentity)
         {
-            AccIdentity = AccOld;
-            MagIdentity = MagOld;
-            States.Last().Qua = Quaternion.identity;
+            _9Axis.SetIdentity();
             if (controlObj != null)
             {
                 controlObj.transform.localRotation = Quaternion.identity;

+ 141 - 50
Assets/BowArrow/Scripts/Bluetooth/o09DOF.cs → Assets/BowArrow/Scripts/Bluetooth/o09Axis.cs

@@ -3,6 +3,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
+using UnityEngine.UI;
 
 public class o0Vector3Filter
 {
@@ -22,11 +23,105 @@ public class o0Vector3Filter
         return state;
     }
 }
+public class o0MagneticCalibraterSimple//默认在无磁干扰环境下,有磁干扰则无法保证效果
+{
+
+    public Vector3 _Center = Vector3.zero;
+    //Vector3 Center = new Vector3(0,0,0);
+    public Vector3 _Radius = new Vector3(2, 2, 2);
+
+    public o0Project.Vector3f Center
+    {
+        get
+        {
+            return new o0Project.Vector3f(_Center.x, _Center.y, _Center.z);
+        }
+        set
+        {
+            _Center = new Vector3(value.x, value.y, value.z);
+        }
+    }
+    public o0Project.Vector3f Radius
+    {
+        get
+        {
+            return new o0Project.Vector3f(_Radius.x, _Radius.y, _Radius.z);
+        }
+        set
+        {
+            _Radius = new Vector3(value.x, value.y, value.z);
+        }
+    }
+
+    public o0MagneticCalibraterSimple()
+    {
+        //Calibration = true;
+    }
+    public o0MagneticCalibraterSimple(o0Project.Vector3f Center, o0Project.Vector3f Radius)
+    {
+        this.Center = Center;
+        this.Radius = Radius;
+    }
+
+    Vector3 Min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
+    Vector3 Max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
+    public bool Calibration
+    {
+        get
+        {
+            return Min != default && Max != default;
+        }
+        set
+        {
+            if (value == true)
+            {
+                Min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
+                Max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
+            }
+            else
+            {
+                Min = default;
+                Max = default;
+            }
+        }
+    }
+    public System.Random r = new System.Random();
+    public Vector3 Update(Vector3 v)
+    {
+        if (v.magnitude > 30)
+            Debug.Log(v);
+        if (Calibration)
+        {
+            if (Min.x > v.x)
+                Min.x = v.x;
+            if (Min.y > v.y)
+                Min.y = v.y;
+            if (Min.z > v.z)
+                Min.z = v.z;
+            if (Max.x < v.x)
+                Max.x = v.x;
+            if (Max.y < v.y)
+                Max.y = v.y;
+            if (Max.z < v.z)
+                Max.z = v.z;
+            _Center = (Max + Min) / 2;
+            _Radius = (Max - Min) / 2;
+        }
+        v -= _Center;
+        v = new Vector3(v.x / _Radius.x, v.y / _Radius.y, v.z / _Radius.z);
+        return v;
+    }
+    public float CalibratCompletionPercentage()
+    {
+        return 0;
+    }
+}
 public class o0MagneticCalibrater//默认在无磁干扰环境下,有磁干扰则无法保证效果
 {
+
     public Vector3 _Center = Vector3.zero;
     //Vector3 Center = new Vector3(0,0,0);
-    public Vector3 _Radius = new Vector3(2,2,2);
+    public Vector3 _Radius = new Vector3(2, 2, 2);
 
     public o0Project.Vector3f Center
     {
@@ -55,7 +150,6 @@ public class o0MagneticCalibrater//默认在无磁干扰环境下,有磁干扰
     {
         //Calibration = true;
     }
-
     public o0MagneticCalibrater(o0Project.Vector3f Center, o0Project.Vector3f Radius)
     {
         this.Center = Center;
@@ -90,7 +184,8 @@ public class o0MagneticCalibrater//默认在无磁干扰环境下,有磁干扰
             {
                 t += Distance[(i, v)];
                 continue;
-            }else if (Distance.ContainsKey((v, i)))
+            }
+            else if (Distance.ContainsKey((v, i)))
             {
                 t += Distance[(v, i)];
                 continue;
@@ -132,16 +227,17 @@ public class o0MagneticCalibrater//默认在无磁干扰环境下,有磁干扰
             if (max.z < i.z)
                 max.z = i.z;
         }
-        return (max - min)/2;
+        return (max - min) / 2;
     }
-    public bool Calibration {
+    public bool Calibration
+    {
         get
         {
             return Distance != null;
         }
         set
         {
-            if(value == true)
+            if (value == true)
             {
                 Point = new HashSet<Vector3>();
                 Distance = new Dictionary<(Vector3, Vector3), float>();
@@ -155,12 +251,12 @@ public class o0MagneticCalibrater//默认在无磁干扰环境下,有磁干扰
     public System.Random r = new System.Random();
     public Vector3 Update(Vector3 v)
     {
-        if(v.magnitude > 30)
+        if (v.magnitude > 30)
             Debug.Log(v);
         if (Calibration)
         {
             AddPoint(v);
-            if (Point.Count > 60)
+            if (Point.Count > 100)
             {
                 RemovePoint(MinDistancePoint());
                 _Radius = RadiusScale();
@@ -201,7 +297,7 @@ public class o0MagneticCalibrater//默认在无磁干扰环境下,有磁干扰
             var v = i - _Center;
             ScaleDistance.Add(new Vector3(v.x / _Radius.x, v.y / _Radius.y, v.z / _Radius.z).magnitude);
         }
-        while (ScaleDistance.Count < 60)
+        while (ScaleDistance.Count < 100)
             ScaleDistance.Add(0);
         float average = 0;
         foreach (var i in ScaleDistance)
@@ -211,13 +307,12 @@ public class o0MagneticCalibrater//默认在无磁干扰环境下,有磁干扰
         foreach (var i in ScaleDistance)
             variance += Mathf.Pow(average - i, 2);
         variance /= ScaleDistance.Count;
-        return Mathf.Pow((1 - variance / average),10) * 100;
+        return Mathf.Pow((1 - variance / average), 10) * 100;
         //return variance;
     }
 }
-public class o09DOF 
+public class o09Axis
 {
-
     static Vector3 AccIdentity = new Vector3(0, -1, 0);
     static Vector3 MagIdentity = new Vector3(-1, 2, 0).normalized;
     public class State
@@ -227,9 +322,13 @@ public class o09DOF
         public Vector3 Gyr;
         public Vector3 Mag = MagIdentity;
         public Quaternion Qua;
-        public float Variance = 1;
+        public double Variance = 1;
     }
 
+    o0Project.Variance HardwareVarianceGyr = new o0Project.Variance(1000);
+    o0Project.Variance HardwareVarianceAcc = new o0Project.Variance(1000);
+    o0Project.Variance HardwareVarianceMag = new o0Project.Variance(1000);
+
     List<State> States = new List<State>();
 
     Vector3 AccOld;
@@ -237,9 +336,8 @@ public class o09DOF
     Vector3 MagOld;
     long TimeGapOld;
     /////////////////////g       degree/ms         
-    public Quaternion o06DOFUpdate(Vector3 AccOld, Vector3 GyrOld, Vector3 MagOld, long TimeGapOld)
+    public Quaternion Update(Vector3 AccOld, Vector3 GyrOld, Vector3 MagOld, long TimeGapOld)
     {
-        //Debug.Log(TimeGapOld);
         var Acc = this.AccOld;
         var Gyr = this.GyrOld;
         var Mag = this.MagOld;
@@ -248,61 +346,54 @@ public class o09DOF
         this.GyrOld = GyrOld;
         this.MagOld = MagOld;
         this.TimeGapOld = TimeGapOld;
-        if (this.TimeGapOld <= 0)
-            return Quaternion.identity;
         var Last = States.LastOrDefault() ?? new State();
+        if (this.TimeGapOld <= 0)
+            return Last.Qua;
         States.Add(new State());
-        if (States.Count > 10)
+        if (States.Count > 2)
             States.RemoveAt(0);
         var state = States.Last();
         state.Acc = Acc;
         state.Gyr = Gyr;
         state.Mag = Mag;
-        //Debug.Log(TimeGap);
 
-        /*
-        var Accwit = GameObject.Find("Accwit");
-        var Gyrwit = GameObject.Find("Gyrwit");
-        var Magwit = GameObject.Find("Magwit");/**/
+        HardwareVarianceGyr.Update((Gyr).magnitude);//每毫秒方差2.331017E-09 度左右   0.00000002331017
+        HardwareVarianceAcc.Update(Vector3.Angle(state.Acc, Last.Acc));//方差0.0012度左右
+        HardwareVarianceMag.Update(Vector3.Angle(state.Mag, Last.Mag));//方差3.5度左右
+
         var LastQuaternion = Last.Qua;
-        //var LastQuaternion = Gyrwit.transform.localRotation;
 
         var newQua = new Quaternion();
         newQua.eulerAngles = Gyr * TimeGap;
         var quaGyr = LastQuaternion * newQua;
 
+        double AccLengthToAngle = 5;//1倍引力差相当于多少度方差
+        double MagLengthToAngle = 5;//1倍磁力差相当于多少度方差
 
+        double GyrVariance = Last.Variance + 0.00000002331017 * TimeGap + Math.Pow((Gyr * TimeGap).magnitude * 0.03, 2);// 指数4 = 方差2 * 欧拉角旋转误差2     移动导致累计误差
+        double AccVariance = Math.Max(0.01, Math.Pow((Acc.magnitude - 9.8) / 9.8 * AccLengthToAngle, 4) + Math.Pow(Math.Max(Gyr.magnitude, Vector3.Angle(Acc, Last.Acc) / TimeGap) * 20, 2));
+        double MagVariance = Math.Max(3.5, Math.Pow((Mag.magnitude - 1) / 1 * MagLengthToAngle, 4) + Math.Pow(Vector3.Angle(Mag, Last.Mag) * 0.07, 2));
 
-        float AccLengthToAngle = 180;//1倍引力差相当于多少度方差
-        float MagLengthToAngle = 180;//1倍磁力差相当于多少度方差
-
-
-        /*
-         * 
-        float GyrVariance = state.Variance + TimeGap/200 + Mathf.Pow((Gyr * TimeGap).magnitude * 0.03f,2);
-        float AccVariance = TimeGap / 30 + Mathf.Pow((Acc.magnitude - 9.8f) / 9.8f * AccLengthToAngle, 2)+ Mathf.Pow(Vector3.Angle(Acc,Last.Acc) * 0.5f, 2);
-        //Debug.Log(Mag.magnitude);
-        float MagVariance = TimeGap / 100 + Mathf.Pow((Mag.magnitude - 500) / 500 * MagLengthToAngle, 2) + Mathf.Pow(Vector3.Angle(Mag, Last.Mag) * 0.1f, 2);
-        /**/
-
-        float GyrVariance = state.Variance + TimeGap / 1000 + (Gyr * TimeGap).magnitude * 0.05f;
-        float AccVariance = Mathf.Max(TimeGap / 10, Mathf.Sqrt(Mathf.Pow((Acc.magnitude - 9.8f) / 9.8f * AccLengthToAngle, 2) + Mathf.Pow(Vector3.Angle(Acc, Last.Acc) * 0.8f, 2)));
-        //Debug.Log(AccVariance);
-        float MagVariance = Mathf.Max(TimeGap / 1, Mathf.Sqrt(Mathf.Pow((Mag.magnitude - 1) / 1 * MagLengthToAngle, 2) + Mathf.Pow(Vector3.Angle(Mag, Last.Mag) * 0.05f, 2)));
-        state.Variance = state.Variance * AccVariance / (state.Variance + AccVariance);
-        state.Variance = state.Variance * MagVariance / (state.Variance + MagVariance);
-
-        var quaAccMag = o0Project.o0.FormQuaternion(AccIdentity, MagIdentity, Acc, Mag, AccVariance / (AccVariance + MagVariance));
+        state.Variance = GyrVariance;
+        state.Variance = state.Variance * (AccVariance+ MagVariance) / (state.Variance + (AccVariance + MagVariance));
 
-        var quaMinRate = GyrVariance / (GyrVariance + Mathf.Max(AccVariance, MagVariance));
-        var quaMaxRate = GyrVariance / (GyrVariance + Mathf.Min(AccVariance, MagVariance));
-        Quaternion quaFirst = Quaternion.Slerp(quaGyr, quaAccMag, quaMinRate).normalized;
+        var quaAccMag = o0Project.o0.FormQuaternion(AccIdentity, MagIdentity, Acc, Mag, (float)(AccVariance / (AccVariance + MagVariance)));
 
-        float quaSecondRate = (quaMaxRate - quaMinRate) / (1 - quaMinRate);
-        state.Qua = AccVariance < MagVariance ? o0Project.o0.FormQuaternion(quaFirst, AccIdentity, Acc, quaSecondRate) : o0Project.o0.FormQuaternion(quaFirst, MagIdentity, Mag, quaSecondRate);
+        var quaMinRate = GyrVariance / (GyrVariance + Math.Max(AccVariance, MagVariance));
+        var quaMaxRate = GyrVariance / (GyrVariance + Math.Min(AccVariance, MagVariance));
+        Quaternion quaFirst = Quaternion.Slerp(quaGyr, quaAccMag, (float)quaMinRate).normalized;
 
+        var quaSecondRate = (quaMaxRate - quaMinRate) / (1 - quaMinRate);
 
+        state.Qua = AccVariance < MagVariance ? o0Project.o0.FormQuaternion(quaFirst, AccIdentity, Acc, (float)quaSecondRate) : o0Project.o0.FormQuaternion(quaFirst, MagIdentity, Mag, (float)quaSecondRate);
+        
         return state.Qua;
-        //Image1.DrawLine();
+    }
+
+    public void SetIdentity()
+    {
+        AccIdentity = AccOld;
+        MagIdentity = MagOld;
+        States.Last().Qua = Quaternion.identity;
     }
 }

+ 1 - 1
Assets/BowArrow/Scripts/Bluetooth/o09DOF.cs.meta → Assets/BowArrow/Scripts/Bluetooth/o09Axis.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: d2357f513fb5e664685553c9031c0d23
+guid: edceb05b5e19ef246bd9baab469f907a
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 60
Assets/BowArrow/Scripts/Bluetooth/o0FilterVector3.cs

@@ -1,60 +0,0 @@
-using System;
-using UnityEngine;
-
-public class o0FilterVector3
-{
-    public o0FilterVector3(float noise)
-    {
-        this.noise = Mathf.Abs(noise);
-    }
-    //public Vector3 value { get; protected set; } = default;
-    float noise = 10;
-
-    public void Update(ref Vector3 value, Vector3 measuredValue)
-    {
-        if (value == default)
-        {
-            value = measuredValue;
-            return;
-        }
-        var noiseBuffer = noise / 10;
-        var differenceVector = measuredValue - value;
-        float sigmoidResult = SigmoidIntegration(differenceVector.magnitude / noiseBuffer - 5) * noiseBuffer;//处理value过大时为无穷
-        value += sigmoidResult * differenceVector.normalized;
-    }
-
-    public float SigmoidIntegration(float to)//计算优化过的sigmoid算法
-    {
-        if (to > 700)
-            return to - 0.00671534848911797f;
-        return (float)Math.Log(1 + Math.Pow(Math.E, to)) - 0.00671534848911797f;
-    }
-}
-
-public class o0FilterQuaternion
-{
-    public o0FilterQuaternion(float noise)
-    {
-        this.noise = Mathf.Abs(noise);
-    }
-    float noise = 10;
-
-    public Quaternion Update(Quaternion value, Quaternion measuredValue)
-    {
-        if (value == default)
-        {
-            return measuredValue;
-        }
-        var noiseBuffer = noise / 10;
-        var difference = Quaternion.Angle(measuredValue, value);
-        float sigmoidResult = SigmoidIntegration(difference / noiseBuffer - 5) * noiseBuffer;//处理value过大时为无穷
-        return Quaternion.Slerp(value, measuredValue, sigmoidResult);
-    }
-
-    public float SigmoidIntegration(float to)//计算优化过的sigmoid算法
-    {
-        if (to > 700)
-            return to - 0.00671534848911797f;
-        return (float)Math.Log(1 + Math.Pow(Math.E, to)) - 0.00671534848911797f;
-    }
-}

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

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

+ 38 - 0
Assets/BowArrow/Scripts/Bluetooth/o0Project.cs

@@ -7,6 +7,44 @@ using UnityEngine;
 
 namespace o0Project
 {
+    public class Variance
+    {
+        List<float> _Value = new List<float>();
+        int RecordCount;
+        public Variance(int RecordCount = 100)
+        {
+            this.RecordCount = RecordCount;
+        }
+        public void Update(float value)
+        {
+            if (_Value.Count >= RecordCount)
+                _Value.RemoveAt(0);
+            _Value.Add(value);
+        }
+        public float Value
+        {
+            get
+            {
+                float average = 0;
+                foreach (var i in _Value)
+                    average += i;
+                average /= _Value.Count;
+                float variance = 0;
+                foreach (var i in _Value)
+                    variance += Mathf.Pow(average - i, 2);
+                variance /= _Value.Count;
+                return variance;
+            }
+        }
+        public float StandardDeviation
+        {
+            get
+            {
+                return Mathf.Sqrt(Value);
+            }
+        }
+
+    }
     public class Vector3f
     {
         public float x;

+ 5 - 7
Assets/BowArrow/Scripts/Game/ArmBow.cs

@@ -30,7 +30,7 @@ public class ArmBow : MonoBehaviour
     {
         if (this.canShoot)
         {
-            DebugBowPower.ins.DoUpdate();
+            if (DebugBowPower.ins != null) DebugBowPower.ins.DoUpdate();
         }
     }
 
@@ -76,7 +76,7 @@ public class ArmBow : MonoBehaviour
         AP_arm.completeCallback = null;
         this.pulling = false;
         this.canShoot = false;
-        DebugBowPower.ins.Init();
+        if (DebugBowPower.ins != null) DebugBowPower.ins.Init();
     }
 
     public void idleToADS() {
@@ -90,7 +90,7 @@ public class ArmBow : MonoBehaviour
     void ADS_idle() {
         this.canShoot = true;
         this.pulling = false;
-        DebugBowPower.ins.PullFinish();
+        if (DebugBowPower.ins != null) DebugBowPower.ins.PullFinish();
     }
 
     public void ADS_fire() {
@@ -123,11 +123,9 @@ public class ArmBow : MonoBehaviour
 
         Arrow arrowComp = arrowCopy.AddComponent<Arrow>();
         arrowComp.armBow = this;
-        // arrowComp.calculateSpeed(rayHitPoint);
-        // Arrow.speed = BaseSpeedSlider.ins.getValue() * DebugBowPower.ins.getPowerPercent();
-        Arrow.speed = DebugBowPower.ins.getPowerPercent() * 100f;
+        // Arrow.speed = DebugBowPower.ins.getPowerPercent() * 100f;
         // Arrow.speed = BaseSpeedSlider.ins.getValue();
-        // Arrow.speed = Mathf.Pow(ShootCheck.ins.shootSpeed, ShootCheck.ins.shootSpeed < 13 ? 2f: (ShootCheck.ins.shootSpeed < 15 ? 2.5f : 3.0f));
+        Arrow.speed = Mathf.Pow(ShootCheck.ins.shootSpeed, ShootCheck.ins.shootSpeed < 13 ? 2f: (ShootCheck.ins.shootSpeed < 15 ? 2.5f : 3.0f));
 
         arrowCopy.SetActive(true);  
         arrow.SetActive(false);

+ 0 - 5
Assets/BowArrow/Scripts/Game/Arrow.cs

@@ -213,9 +213,4 @@ public class Arrow : MonoBehaviour
             ps1.maxParticleSize = ps1.minParticleSize;
         }
     }
-
-    public void calculateSpeed(Vector3 rayPoint) 
-    {
-        speed = Mathf.Clamp(Vector3.Distance(rayPoint, this.getHeadPosition()) / 2, 6.6f, 16);
-    }
 }

+ 22 - 22
Assets/BowArrow/Scripts/Game/BowCamera.cs

@@ -36,28 +36,28 @@ public class BowCamera : MonoBehaviour
                 ArmBow.ins.mouseUp();
             }
         } else {
-            // this.transform.LookAt(GameObject.Find("CameraToLook/Point").transform);
-            if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
-            {
-                if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
-                {
-                    this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
-                    this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -25, 25);   
-                    this.transform.eulerAngles = this.eualrAngles; 
-                }
-            }
-            if (Input.touches.Length > 0)
-            {
-                foreach (Touch touch in Input.touches)
-                {
-                    if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;
-                }
-                ArmBow.ins.mouseDown();
-            } 
-            if (Input.touches.Length == 0)
-            {
-                ArmBow.ins.mouseUp();
-            }
+            this.transform.LookAt(GameObject.Find("CameraToLook/Point").transform);
+            // if (Input.touches.Length == 1 && Input.touches[0].phase == TouchPhase.Moved)
+            // {
+            //     if (!EventSystem.current.IsPointerOverGameObject(Input.touches[0].fingerId))
+            //     {
+            //         this.eualrAngles.x = Mathf.Clamp(this.eualrAngles.x - Input.touches[0].deltaPosition.y * Time.deltaTime * 5, -36, 36);
+            //         this.eualrAngles.y = Mathf.Clamp(this.eualrAngles.y + Input.touches[0].deltaPosition.x * Time.deltaTime * 5, -25, 25);   
+            //         this.transform.eulerAngles = this.eualrAngles; 
+            //     }
+            // }
+            // if (Input.touches.Length > 0)
+            // {
+            //     foreach (Touch touch in Input.touches)
+            //     {
+            //         if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;
+            //     }
+            //     ArmBow.ins.mouseDown();
+            // } 
+            // if (Input.touches.Length == 0)
+            // {
+            //     ArmBow.ins.mouseUp();
+            // }
         }
     }
 

+ 3 - 3
Assets/BowArrow/Scripts/Manager/GameMgr.cs

@@ -2,7 +2,7 @@
 
 public class GameMgr : MonoBehaviour
 {
-    public static int gameMode = 2;
+    public static int gameMode = 1;
     public GameMode1 gameMode1;
     public GameMode2 gameMode2;
     public bool gameOver = false;
@@ -116,8 +116,8 @@ public class GameMode1 {
     }
 
     public void hitTarget(GameMgr gameMgr, int score) {
-        this.score += score;
-        this.arrowCount -= 1;
+        // this.score += score;
+        // this.arrowCount -= 1;
     }
 
     public bool checkFinish(GameMgr gameMgr) {

+ 3 - 3
ProjectSettings/EditorBuildSettings.asset

@@ -5,12 +5,12 @@ EditorBuildSettings:
   m_ObjectHideFlags: 0
   serializedVersion: 2
   m_Scenes:
-  - enabled: 1
-    path: Assets/BowArrow/Scenes/Login.unity
-    guid: 200a793b1fc5aac438c87e1b342a939a
   - enabled: 1
     path: Assets/BowArrow/Scenes/Game.unity
     guid: 3a346723748889946bfbc85eb35f7879
+  - enabled: 1
+    path: Assets/BowArrow/Scenes/Login.unity
+    guid: 200a793b1fc5aac438c87e1b342a939a
   - enabled: 1
     path: Assets/BowArrow/Scenes/Home.unity
     guid: 8aa5affa1b256294a8c908dbab6122d0