12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MapLodCtrl : MonoBehaviour
- {
- public CameraBirdSec cameraBirdSec;
- public List<LodLayer> MapList = new List<LodLayer>();
- public int currentMapIndex = 0;
- private void Awake()
- {
- cameraBirdSec.OnDistanceChange += OnCameraDistanceChange;
- }
- private void Start()
- {
- MapList[currentMapIndex].map.ShowMap();
- }
- private void OnDestroy()
- {
- cameraBirdSec.OnDistanceChange -= OnCameraDistanceChange;
- }
- 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)
- {
- 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);
- }
- }
- [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;
- }
|