Browse Source

修改bug

Void_F 7 months ago
parent
commit
56d9d16fe0
2 changed files with 16 additions and 19 deletions
  1. 0 8
      Assets/AIPagedLod/Scripts/WebGL/CameraBirdSec.cs
  2. 16 11
      Assets/MapLodCtrl.cs

+ 0 - 8
Assets/AIPagedLod/Scripts/WebGL/CameraBirdSec.cs

@@ -45,16 +45,8 @@ public class CameraBirdSec : MonoBehaviour
     bool onUI = false;
     void Start()
     {
-
-        // 初始化当前距离为初始偏移量的距离
-        currentDistance = Vector3.Distance(transform.position, target.position);
-        Debug.Log(currentDistance);
-        // 确保初始距离在允许的范围内
-        currentDistance = Mathf.Clamp(currentDistance, minDistance, maxDistance);
         // 计算偏移量
         offset = transform.position - target.position;
-
-        OnDistanceChange?.Invoke(currentDistance);
     }
 
     private bool GetPointerOverUIElement(out GameObject uiElement)

+ 16 - 11
Assets/MapLodCtrl.cs

@@ -22,7 +22,7 @@ public class MapLodCtrl : MonoBehaviour
         MapList[currentMapIndex].map.ShowMap();
         cameraBirdSec.detailLod = false;
         cameraBirdSec.currentDistance = MapList[currentMapIndex].cameraDistanceMax;
-        cameraBirdSec.SetRange(MapList[currentMapIndex].max_X_Range.x,MapList[currentMapIndex].max_X_Range.y,MapList[currentMapIndex].max_Y_Range.x,MapList[currentMapIndex].max_Y_Range.y);
+        SetCameraRange(cameraBirdSec.currentDistance);
     }
 
     private void OnDestroy()
@@ -42,16 +42,10 @@ public class MapLodCtrl : MonoBehaviour
 
                 cameraBirdSec.detailLod = false;
                 cameraBirdSec.currentDistance = MapList[currentMapIndex].cameraDistanceMax;
-                cameraBirdSec.SetRange(MapList[currentMapIndex].max_X_Range.x,MapList[currentMapIndex].max_X_Range.y,MapList[currentMapIndex].max_Y_Range.x,MapList[currentMapIndex].max_Y_Range.y);
+                SetCameraRange(MapList[currentMapIndex].cameraDistanceMax);
                 return;
             }
-            var currentLayer = MapList[currentMapIndex];
-            float distanceRange = (value-currentLayer.cameraDistanceMin)/(currentLayer.cameraDistanceMax-currentLayer.cameraDistanceMin);
-            float minX =currentLayer.min_X_Range.x+Mathf.Abs(currentLayer.min_X_Range.x-currentLayer.max_X_Range.x)*distanceRange; 
-            float maxX =currentLayer.min_X_Range.y-Mathf.Abs(currentLayer.min_X_Range.y-currentLayer.max_X_Range.y)*distanceRange; 
-            float minY =currentLayer.min_Y_Range.y+Mathf.Abs(currentLayer.min_Y_Range.y-currentLayer.max_Y_Range.y)*distanceRange; 
-            float maxY =currentLayer.min_Y_Range.x-Mathf.Abs(currentLayer.min_Y_Range.x-currentLayer.max_Y_Range.x)*distanceRange; 
-            cameraBirdSec.SetRange(minX,maxX,minY,maxY);
+            SetCameraRange(value);
             for (int i = 0; i < MapStayList.Count; i++)
             {
                 if (value >= MapStayList[i].cameraDistanceMin && value < MapStayList[i].cameraDistanceMax)
@@ -87,11 +81,22 @@ public class MapLodCtrl : MonoBehaviour
                 currentMapIndex++;
             }
             cameraBirdSec.currentDistance = MapList[currentMapIndex].cameraDistanceMax;
-            cameraBirdSec.SetRange(MapList[currentMapIndex].max_X_Range.x,MapList[currentMapIndex].max_X_Range.y,MapList[currentMapIndex].max_Y_Range.x,MapList[currentMapIndex].max_Y_Range.y);
+            SetCameraRange(MapList[currentMapIndex].cameraDistanceMax);
         }
     }
-}
 
+    private void SetCameraRange(float cameraDistance)
+    {
+        var currentLayer = MapList[currentMapIndex];
+        float distanceRange = (cameraDistance-currentLayer.cameraDistanceMin)/(currentLayer.cameraDistanceMax-currentLayer.cameraDistanceMin);
+        float minX =currentLayer.min_X_Range.x+Mathf.Abs(currentLayer.min_X_Range.x-currentLayer.max_X_Range.x)*distanceRange; 
+        float maxX =currentLayer.min_X_Range.y-Mathf.Abs(currentLayer.min_X_Range.y-currentLayer.max_X_Range.y)*distanceRange; 
+        float minY =currentLayer.min_Y_Range.y+Mathf.Abs(currentLayer.min_Y_Range.y-currentLayer.max_Y_Range.y)*distanceRange; 
+        float maxY =currentLayer.min_Y_Range.x-Mathf.Abs(currentLayer.min_Y_Range.x-currentLayer.max_Y_Range.x)*distanceRange; 
+        cameraBirdSec.SetRange(minX,maxX,minY,maxY);
+    }
+    
+}
 
 [Serializable]
 public class LodLayer