Kaynağa Gözat

修改LOD逻辑

Void_F 7 ay önce
ebeveyn
işleme
1b008be5a9

+ 17 - 18
Assets/AIPagedLod/Scripts/WebGL/CameraBirdSec.cs

@@ -38,6 +38,7 @@ public class CameraBirdSec : MonoBehaviour
     public float max_Y;
 
     public bool fixMoveRange = false;
+    public bool detailLod = false;
     
     bool isRotate = false;
 
@@ -108,25 +109,23 @@ public class CameraBirdSec : MonoBehaviour
         // 鼠标滚轮控制摄像头远近
         if (Input.GetAxis("Mouse ScrollWheel") != 0 && !onUI)
         {
-            scrollSensitivity = math.clamp(currentDistance, 0, 10);
-            // 更新当前距离
-            currentDistance -= Input.GetAxis("Mouse ScrollWheel") * scrollSensitivity;
-            // 确保距离在允许的范围内
-            currentDistance = Mathf.Clamp(currentDistance, minDistance, maxDistance);
-
-            //this.GetComponent<DepthFog>().Height = 400000 / currentDistance;
-            OnDistanceChange?.Invoke(currentDistance);
+            if (detailLod)
+            {
+                scrollSensitivity = math.clamp(currentDistance, 0, 10);
+                // 更新当前距离
+                currentDistance -= Input.GetAxis("Mouse ScrollWheel") * scrollSensitivity;
+                // 确保距离在允许的范围内
+                currentDistance = Mathf.Clamp(currentDistance, minDistance, maxDistance);
+
+                //this.GetComponent<DepthFog>().Height = 400000 / currentDistance;
+                OnDistanceChange?.Invoke(currentDistance);
+            }
+            else
+            {
+                OnDistanceChange?.Invoke(Input.GetAxis("Mouse ScrollWheel"));
+            }
         }
-        //if (Input.GetMouseButton(2))
-        //{
-        //    rotateXAngle -= Input.GetAxis("Mouse Y") * rotateSpeed;
-        //    rotateXAngle = Mathf.Clamp(rotateXAngle, -36f, 36f);
-        //    isRotate = true;
-        //}
-        //else {
-        //    isRotate = false;
-        //}
-
+      
         // 鼠标左键拖拽平移摄像头
         if (Input.GetMouseButtonDown(0) && !onUI)
         {

+ 53 - 28
Assets/MapLodCtrl.cs

@@ -8,8 +8,7 @@ public class MapLodCtrl : MonoBehaviour
     public CameraBirdSec cameraBirdSec;
 
     public List<LodLayer> MapList = new List<LodLayer>();
-    public int currentMapIndex = 2;
-
+    private int currentMapIndex;
     public List<LodStayLayer> MapStayList = new List<LodStayLayer>();
     
     private void Awake()
@@ -19,7 +18,11 @@ public class MapLodCtrl : MonoBehaviour
 
     private void Start()
     {
+        currentMapIndex = MapList.Count - 1;
         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);
     }
 
     private void OnDestroy()
@@ -29,40 +32,62 @@ public class MapLodCtrl : MonoBehaviour
 
     private void OnCameraDistanceChange(float value)
     {
-        if (currentMapIndex>0&&value < MapList[currentMapIndex].cameraDistanceMin)
-        {
-            MapList[currentMapIndex-1].map.ShowMap();
-            MapList[currentMapIndex].map.Hide();
-            currentMapIndex--;
-        }
-        if (currentMapIndex < MapList.Count - 1 && value > MapList[currentMapIndex].cameraDistanceMax)
+        if (currentMapIndex == 0)
         {
-            MapList[currentMapIndex+1].map.ShowMap();
-            MapList[currentMapIndex].map.Hide();
-            currentMapIndex++;
-        }
+            if (value > MapList[currentMapIndex].cameraDistanceMax)
+            {
+                MapList[currentMapIndex+1].map.ShowMap();
+                MapList[currentMapIndex].map.Hide();
+                currentMapIndex++;
 
-        var currentLayer = MapList[currentMapIndex];
-        
-        float distanceRange = (value-currentLayer.cameraDistanceMin)/(currentLayer.cameraDistanceMax-currentLayer.cameraDistanceMin);//27-3
-        
-        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; 
-        
-//        Debug.Log($"dis:{value} disRange:{distanceRange} minX:{minX} maxX:{maxX} minY:{minY} maxY:{maxY}");
-        cameraBirdSec.SetRange(minX,maxX,minY,maxY);
-        for (int i = 0; i < MapStayList.Count; i++)
+                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);
+                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);
+            for (int i = 0; i < MapStayList.Count; i++)
+            {
+                if (value >= MapStayList[i].cameraDistanceMin && value < MapStayList[i].cameraDistanceMax)
+                {
+                    MapStayList[i].map.ShowMap();
+                }
+                else
+                {
+                    MapStayList[i].map.Hide();
+                }
+            }
+        }
+        else
         {
-            if (value >= MapStayList[i].cameraDistanceMin && value < MapStayList[i].cameraDistanceMax)
+            if (value>0)
             {
-                MapStayList[i].map.ShowMap();
+                MapList[currentMapIndex-1].map.ShowMap();
+                MapList[currentMapIndex].map.Hide();
+                currentMapIndex--;
+                if (currentMapIndex == 0)
+                {
+                    cameraBirdSec.detailLod = true;
+                }
             }
             else
             {
-                MapStayList[i].map.Hide();
+                if (currentMapIndex >= MapList.Count - 1)
+                {
+                    return;
+                }
+                MapList[currentMapIndex+1].map.ShowMap();
+                MapList[currentMapIndex].map.Hide();
+                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);
         }
     }
 }