Bläddra i källkod

根据屏幕距离切换闯关场景视野大小

lvjincheng 3 år sedan
förälder
incheckning
8e1be15b14

+ 2 - 1
Assets/BowArrow/Scripts/Game/BowCamera.cs

@@ -67,7 +67,8 @@ public class BowCamera : MonoBehaviour
         localEulerAngles = transform.localEulerAngles;
         if (CommonConfig.SpecialVersion1) {
             if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.Equals("GameChallenge")) {
-                this.cameraComp.fieldOfView = 25;
+                // this.cameraComp.fieldOfView = 25;
+                this.cameraComp.fieldOfView = UserSettings.ins.bowRotateConvert.GetFieldOfView();
             }
         }
         RecordDefaultCameraFieldOfView();

+ 40 - 25
Assets/BowArrow/Scripts/Manager/LoginMgr/LoginMgr.cs

@@ -118,11 +118,11 @@ public class UserSettings {
                     _ins = new UserSettings();
                 }
                 if (CommonConfig.SpecialVersion1) {
-                    if (PlayerPrefs.GetInt("sv1_UserSettings_1", 0) == 0) {
-                        PlayerPrefs.SetInt("sv1_UserSettings_1", 1);
+                    if (PlayerPrefs.GetInt("sv1_UserSettings_2", 0) == 0) {
+                        PlayerPrefs.SetInt("sv1_UserSettings_2", 1);
                         UserSettings us = _ins;
                         us.bowRotateConvert.screenSize = 60;
-                        us.bowRotateConvert.screenDistance = 0.5f;
+                        us.bowRotateConvert.screenDistance = 1.5f;
                         us.Save();
                     }
                 }
@@ -162,29 +162,44 @@ public class BowRotateConvert {
     public float screenSize = 60; //屏幕尺寸(英寸)
     public float screenDistance = 2.5f; //玩家距离屏幕多远(米)
 
-    // 游戏旋转角度 : 实际旋转角度
-    public float GetRate() {
-        double w = 16;
-        double h = 9;
-        double s = Convert.ToDouble(screenSize);
-        double d = Convert.ToDouble(screenDistance);
-        double r = 27.3 / 180 * Math.PI;
-        double q = get_q();
-        double s1 = s * 0.0254;
-        double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
-        double e = Math.Atan(q * unit / d);
-        return (float) (r / e);
+    //获取合适的视野大小
+    public float GetFieldOfView() {
+        float w = 16;
+        float h = 9;
+        float s1 = screenSize * 0.0254f;
+        float unit = s1 / Mathf.Sqrt(w * w + h * h);
+        float screenHeight = 9 * unit;
+        return 2 * Mathf.Atan(screenHeight * 0.5f / screenDistance) * Mathf.Rad2Deg;
     }
 
-    private double get_q() {
-        double w = 16;
-        double h = 9;
-        double s = 60.11;
-        double d = 2.5;
-        double e = 5.56 / 180 * Math.PI;
-        double s1 = s * 0.0254;
-        double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
-        double q = Math.Tan(e) * d / unit;
-        return q;
+    // 游戏旋转角度 : 实际旋转角度 (这个版本丢弃掉这个功能-所以直接返回1)
+    public float GetRate() {
+        return 1;
     }
+
+    // 游戏旋转角度 : 实际旋转角度
+    // public float GetRate() {
+    //     double w = 16;
+    //     double h = 9;
+    //     double s = Convert.ToDouble(screenSize);
+    //     double d = Convert.ToDouble(screenDistance);
+    //     double r = 27.3 / 180 * Math.PI;
+    //     double q = get_q();
+    //     double s1 = s * 0.0254;
+    //     double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
+    //     double e = Math.Atan(q * unit / d);
+    //     return (float) (r / e);
+    // }
+
+    // private double get_q() {
+    //     double w = 16;
+    //     double h = 9;
+    //     double s = 60.11;
+    //     double d = 2.5;
+    //     double e = 5.56 / 180 * Math.PI;
+    //     double s1 = s * 0.0254;
+    //     double unit = Math.Sqrt(Math.Pow(s1, 2) / (Math.Pow(w, 2) + Math.Pow(h, 2)));
+    //     double q = Math.Tan(e) * d / unit;
+    //     return q;
+    // }
 }

+ 4 - 2
Assets/BowArrow/Scripts/View/SetUpView.cs

@@ -38,7 +38,8 @@ public class SetUpView : MonoBehaviour
             //save
             UserSettings.ins.bowRotateConvert.screenSize = v;
             UserSettings.ins.Save();
-            PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("转化比率 = ") + UserSettings.ins.bowRotateConvert.GetRate());
+            PopupMgr.ins.ShowTip("闯关场景视野大小=" + UserSettings.ins.bowRotateConvert.GetFieldOfView());
+            // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("转化比率 = ") + UserSettings.ins.bowRotateConvert.GetRate());
         };
         UnityAction<string> onEndEdit_inputDistance = (string str) => {
             inputDistance.SetTextWithoutNotify("");
@@ -51,7 +52,8 @@ public class SetUpView : MonoBehaviour
             //save
             UserSettings.ins.bowRotateConvert.screenDistance = v;
             UserSettings.ins.Save();
-            PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("转化比率 = ") + UserSettings.ins.bowRotateConvert.GetRate());
+            PopupMgr.ins.ShowTip("闯关场景视野大小=" + UserSettings.ins.bowRotateConvert.GetFieldOfView());
+            // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("转化比率 = ") + UserSettings.ins.bowRotateConvert.GetRate());
         };
         inputSize.onEndEdit.AddListener(onEndEdit_inputSize);
         inputDistance.onEndEdit.AddListener(onEndEdit_inputDistance);