using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class MapLodCtrl : MonoBehaviour { public CameraBirdSec cameraBirdSec; public List MapList = new List(); private int currentMapIndex; public List MapStayList = new List(); private void Awake() { cameraBirdSec.OnDistanceChange += OnCameraDistanceChange; } private void Start() { currentMapIndex = MapList.Count - 1; MapList[currentMapIndex].map.ShowMap(); //cameraBirdSec.detailLod = false; cameraBirdSec.currentDistance = MapList[currentMapIndex].cameraDistanceMax; SetCameraRange(cameraBirdSec.currentDistance); } private void OnDestroy() { cameraBirdSec.OnDistanceChange -= OnCameraDistanceChange; } private void OnCameraDistanceChange(float value) { SetCameraRange(value); // if (currentMapIndex == 0) // { // if (value > MapList[currentMapIndex].cameraDistanceMax) // { // MapList[currentMapIndex+1].map.ShowMap(); // MapList[currentMapIndex].map.Hide(); // currentMapIndex++; // // cameraBirdSec.detailLod = false; // cameraBirdSec.currentDistance = MapList[currentMapIndex].cameraDistanceMax; // SetCameraRange(MapList[currentMapIndex].cameraDistanceMax); // return; // } // SetCameraRange(value); for (int i = 0; i < MapStayList.Count; i++) { if (value < MapStayList[i].cameraDistanceMax) { MapStayList[i].map.ShowMap(); } else { MapStayList[i].map.Hide(); } } // } // else // { // if (value>0) // { // MapList[currentMapIndex-1].map.ShowMap(); // MapList[currentMapIndex].map.Hide(); // currentMapIndex--; // // if (currentMapIndex == 0) // // { // // cameraBirdSec.detailLod = true; // // } // } // else // { // if (currentMapIndex >= MapList.Count - 1) // { // return; // } // MapList[currentMapIndex+1].map.ShowMap(); // MapList[currentMapIndex].map.Hide(); // currentMapIndex++; // } // cameraBirdSec.currentDistance = MapList[currentMapIndex].cameraDistanceMax; // 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; //Debug.Log(minX); //Debug.Log(maxX); //Debug.Log(minY); //Debug.Log(maxY); cameraBirdSec.SetRange(minX,maxX,minY,maxY); } } [Serializable] public class LodLayer { public MapGenerator map; public float cameraDistanceMin; public float cameraDistanceMax; public Vector2 min_X_Range;//最短距离时候的X范围 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; }