using System.Collections.Generic; using UnityEngine; using System.Linq; using Unity.Mathematics; publicclassMapManager : MonoBehaviour { publicstatic MapManager Instance; private GameObject _player; privatebool _playerLive; privateint _mapX; privateint _mapY; public GameObject mapPrefabs; public Transform grid;
public List<MapData> mapList = new List<MapData>();
///<summary> /// 自动检查玩家身边的地图,并自动加载未加载地图 ///</summary> publicvoidConrtolAutoMap() { var x = _player.transform.position.x; var y = _player.transform.position.y; int X = (int)x / _mapX; int Y = (int)y / _mapY; int XX = x > 0 ? X + 1 : X - 1; int YY = y > 0 ? Y + 1 : Y - 1; if (!CheckMapLive(X, Y)) { var newMap = Instantiate(mapPrefabs, new Vector3(X * _mapX, Y * _mapY), quaternion.identity,grid); newMap.GetComponent<MapUnit>().GetMyData(X, Y); }
if (!CheckMapLive(XX, Y)) { var newMap = Instantiate(mapPrefabs, new Vector3((XX) * _mapX, Y * _mapY), quaternion.identity,grid); newMap.GetComponent<MapUnit>().GetMyData(XX, Y); }
if (!CheckMapLive(X, YY)) { var newMap = Instantiate(mapPrefabs, new Vector3(X * _mapX, (YY) * _mapY), quaternion.identity,grid); newMap.GetComponent<MapUnit>().GetMyData(X, YY);
}
if (!CheckMapLive(XX, YY)) { var newMap = Instantiate(mapPrefabs, new Vector3((XX) * _mapX, (YY) * _mapY), quaternion.identity,grid); newMap.GetComponent<MapUnit>().GetMyData(XX, YY);