Browse Source

修改两个脚本

Void_F 9 months ago
parent
commit
3eeee22d94
2 changed files with 40 additions and 8 deletions
  1. 18 8
      Assets/MapGenerator.cs
  2. 22 0
      Assets/MapLodCtrl.cs

+ 18 - 8
Assets/MapGenerator.cs

@@ -14,6 +14,7 @@ public class MapGenerator : MonoBehaviour
     private List<GameObject> quadList = new List<GameObject>();
 
     private bool isInit = false;
+    private bool isShow = false;
 
     public void ShowMap()
     {
@@ -23,18 +24,26 @@ public class MapGenerator : MonoBehaviour
         }
         else
         {
-            foreach (var mapQuad in quadList)
+            if (!isShow)
             {
-                mapQuad.SetActive(true);
+                isShow = true;
+                foreach (var mapQuad in quadList)
+                {
+                    mapQuad.SetActive(true);
+                }
             }
         }
     }
 
     public void Hide()
     {
-        foreach (var mapQuad in quadList)
+        if (isShow)
         {
-            mapQuad.SetActive(false);
+            isShow = false;
+            foreach (var mapQuad in quadList)
+            {
+                mapQuad.SetActive(false);
+            }
         }
     }
 
@@ -48,20 +57,21 @@ public class MapGenerator : MonoBehaviour
             {
                 GeneratorQuad(i, j, new Vector2(1, 1));
             }
+
             yield return wait;
         }
     }
 
     private void GeneratorQuad(int _x, int _y, Vector2 _size)
     {
-        string texName =$"{nameHeard}{_x}_{_y}";
+        string texName = $"{nameHeard}{_x}_{_y}";
         GameObject tempQuad = new GameObject(texName);
         MeshFilter meshFilter = tempQuad.AddComponent<MeshFilter>();
         MeshRenderer meshRenderer = tempQuad.AddComponent<MeshRenderer>();
-        Material tempMat=new Material(Shader.Find("Unlit/Texture"));
+        Material tempMat = new Material(Shader.Find("Unlit/Texture"));
         meshRenderer.material = tempMat;
 
-        TextureLoadHelp._Instance.LoadTexFromUrl_AB(ab_Name+"_"+_x,texName + ".jpg",tempMat);
+        TextureLoadHelp._Instance.LoadTexFromUrl_AB(ab_Name + "_" + _x, texName + ".jpg", tempMat);
 
         Mesh mesh = new Mesh();
         mesh.vertices = new Vector3[]
@@ -86,7 +96,7 @@ public class MapGenerator : MonoBehaviour
         tempQuad.transform.localScale = Vector3.one;
         var x = (-x_Count * 0.5f) + (_y * _size.x) + 0.5f;
         var y = (y_Count * 0.5f) - (_x * _size.y) - 0.5f;
-        tempQuad.transform.localPosition = new Vector3(x,y,0);
+        tempQuad.transform.localPosition = new Vector3(x, y, 0);
         quadList.Add(tempQuad);
     }
 }

+ 22 - 0
Assets/MapLodCtrl.cs

@@ -9,6 +9,9 @@ public class MapLodCtrl : MonoBehaviour
 
     public List<LodLayer> MapList = new List<LodLayer>();
     public int currentMapIndex = 0;
+
+    public List<LodStayLayer> MapStayList = new List<LodStayLayer>();
+    
     private void Awake()
     {
         cameraBirdSec.OnDistanceChange += OnCameraDistanceChange;
@@ -52,6 +55,17 @@ public class MapLodCtrl : MonoBehaviour
         
 //        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++)
+        {
+            if (value >= MapStayList[i].cameraDistanceMin && value < MapStayList[i].cameraDistanceMax)
+            {
+                MapStayList[i].map.ShowMap();
+            }
+            else
+            {
+                MapStayList[i].map.Hide();
+            }
+        }
     }
 }
 
@@ -66,4 +80,12 @@ public class LodLayer
     public Vector2 max_X_Range;//最大距离时候的X范围
     public Vector2 min_Y_Range;
     public Vector2 max_Y_Range;
+}
+
+[Serializable]
+public class LodStayLayer
+{
+    public MapGenerator map;
+    public float cameraDistanceMin;
+    public float cameraDistanceMax;
 }