bao
This commit is contained in:
@@ -17,12 +17,18 @@ using UnityEngine.Rendering;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UIElements;
|
||||
using static MapManager;
|
||||
using static UnityEngine.Rendering.DebugUI.Table;
|
||||
|
||||
public partial class MapManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform mapRegion;
|
||||
public Dictionary<string, (int maxRow, int maxCol)> allMaps = new Dictionary<string, (int maxRow, int maxCol)>();
|
||||
public Dictionary<string, (int maxRow, int maxCol)> allMaps = new Dictionary<string, (int maxRow, int maxCol)>();
|
||||
|
||||
/// <summary>
|
||||
/// 当前地图区域
|
||||
/// </summary>
|
||||
private MapRegions _curMapRegions;
|
||||
public bool LoadObsXml()
|
||||
{
|
||||
if (_curOpenMapId < 0)
|
||||
@@ -90,53 +96,44 @@ public partial class MapManager : MonoBehaviour
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void LoadRegionXML(int mapId)
|
||||
/// <summary>
|
||||
/// 保存地图配置
|
||||
/// </summary>
|
||||
/// <param name="mapId"></param>
|
||||
public void SaveRegionXML()
|
||||
{
|
||||
Transform regionsTrans = UIWindow.Instance.mapTrans.Find("Regions");
|
||||
if (regionsTrans == null)
|
||||
int mapId = _curOpenMapId;
|
||||
if (!allMaps.TryGetValue(_curOpenMapId.ToString(), out var curMap))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("没有找到Regions节点");
|
||||
UIWindow.Instance.ShowMessage($"没有扫描到当前地图 [{_curOpenMapId}]");
|
||||
return;
|
||||
}
|
||||
|
||||
MapRegions mapRegions = new MapRegions();
|
||||
mapRegions.mapWidth = Convert.ToInt32(txtMapWidth.text);
|
||||
mapRegions.mapHeight = Convert.ToInt32(txtMapHeight.text);
|
||||
mapRegions.regionWidth = Convert.ToInt32(txtRegionWidth.text);
|
||||
mapRegions.regionHeight = Convert.ToInt32(txtRegionHeight.text);
|
||||
|
||||
int row = mapRegions.mapWidth / MapManager.CELLSCALE / mapRegions.regionWidth;
|
||||
int col = mapRegions.mapHeight / MapManager.CELLSCALE / mapRegions.regionHeight;
|
||||
|
||||
Transform trans = null;
|
||||
mapRegions.regions = new Region[row, col];
|
||||
for (int i = 0; i < row; i++)
|
||||
{
|
||||
for (int j = 0; j < col; j++)
|
||||
{
|
||||
mapRegions.regions[i, j] = new Region();
|
||||
mapRegions.regions[i, j].indexX = i;
|
||||
mapRegions.regions[i, j].indexY = j;
|
||||
|
||||
string regionName = $"{i}_{j}";
|
||||
trans = regionsTrans.Find(regionName);
|
||||
if (trans == null)
|
||||
{
|
||||
UIWindow.Instance.ShowMessage($"没有找到region节点 name={regionName}");
|
||||
return;
|
||||
}
|
||||
|
||||
//mapRegions.regions[i, j].regionName = trans.GetComponent<Image>().sprite.name;
|
||||
mapRegions.regions[i, j].regionName = trans.GetComponent<RawImage>().texture.name;
|
||||
}
|
||||
}
|
||||
|
||||
mapRegions.SaveXML(mapId);
|
||||
_curMapRegions?.SaveXML(mapId);
|
||||
//MapRegions mapRegions = new MapRegions();
|
||||
//mapRegions.regionRowNum = curMap.maxRow;
|
||||
//mapRegions.regionColNum = curMap.maxCol;
|
||||
//mapRegions.regionWidth = PicMapPixel;
|
||||
//mapRegions.regionHeight = PicMapPixel;
|
||||
//mapRegions.cellWidthPixel = widthPixel;
|
||||
//mapRegions.cellHeightPixel = heightPixel;
|
||||
//mapRegions.regions = new Region[mapRegions.regionRowNum, mapRegions.regionColNum];
|
||||
//for (int row = 0; row < mapRegions.regionRowNum; row++)
|
||||
//{
|
||||
// for (int col = 0; col < mapRegions.regionColNum; col++)
|
||||
// {
|
||||
// mapRegions.regions[row, col] = new Region();
|
||||
// mapRegions.regions[row, col].indexX = row;
|
||||
// mapRegions.regions[row, col].indexY = col;
|
||||
// int ldx = mapRegions.regionRowNum - row;
|
||||
// int ldy = col + 1;
|
||||
// mapRegions.regions[row, col].regionName = $"v{mapId}_r{ldx}_c{ldy}"; // 构造文件名,v1000_r1_c1.jpg
|
||||
// }
|
||||
//}
|
||||
//mapRegions.SaveXML(mapId);
|
||||
}
|
||||
|
||||
public void LoadMapRegions(int mapId)
|
||||
public void LoadMapRegionSprites(int mapId)
|
||||
{
|
||||
_curOpenMapId = mapId;
|
||||
if (!allMaps.TryGetValue(mapId.ToString(),out var mapInfo))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("µØÍ¼²»´æÔÚ¡£¡£¡£");
|
||||
@@ -144,10 +141,16 @@ public partial class MapManager : MonoBehaviour
|
||||
}
|
||||
int mapRownum = mapInfo.maxRow;
|
||||
int mapColumn = mapInfo.maxCol;
|
||||
//平铺;
|
||||
float jpgscenew = 512f / 100;
|
||||
MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum);
|
||||
MapManager.Instance.GenerateMap(jpgscenew * mapColumn, jpgscenew * mapRownum, 0.48f, 0.32f);
|
||||
_curMapRegions = new MapRegions();
|
||||
_curOpenMapId = mapId;
|
||||
_curMapRegions.regionRowNum = mapRownum;
|
||||
_curMapRegions.regionColNum = mapColumn;
|
||||
_curMapRegions.regionWidth = PicMapPixel;
|
||||
_curMapRegions.regionHeight = PicMapPixel;
|
||||
_curMapRegions.cellWidthPixel = widthPixel;
|
||||
_curMapRegions.cellHeightPixel = heightPixel;
|
||||
_curMapRegions.regions = new Region[mapRownum, mapColumn];
|
||||
float jpgscenew = PicMapPixel / 100;
|
||||
for (int row = 0; row < mapRownum; row++)
|
||||
{
|
||||
for (int col = 0; col < mapColumn; col++)
|
||||
@@ -160,9 +163,18 @@ public partial class MapManager : MonoBehaviour
|
||||
float x = col * jpgscenew;
|
||||
float y = (mapRownum - row - 1) * jpgscenew;
|
||||
obj.transform.position = new Vector2(x, y);
|
||||
multithreadLoadTextrue(spPath,sr);
|
||||
}
|
||||
_curMapRegions.regions[row, col] = new Region();
|
||||
_curMapRegions.regions[row, col].indexX = row;
|
||||
_curMapRegions.regions[row, col].indexY = col;
|
||||
multithreadLoadTextrue(spPath, sr);
|
||||
int ldx = mapRownum - row;
|
||||
int ldy = col + 1;
|
||||
_curMapRegions.regions[row, col].regionName = $"v{mapId}_r{ldx}_c{ldy}"; // 构造文件名,v1000_r1_c1.jpg
|
||||
}
|
||||
}
|
||||
MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum);
|
||||
MapManager.Instance.GenerateMap(jpgscenew * mapColumn, jpgscenew * mapRownum, widthPixel / 100.0f, heightPixel / 100.0f);
|
||||
|
||||
}
|
||||
public void ClearMapRegions()
|
||||
{
|
||||
@@ -244,8 +256,4 @@ public partial class MapManager : MonoBehaviour
|
||||
//}
|
||||
}
|
||||
|
||||
internal void SaveCellsXml()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,12 @@ public partial class MapManager : MonoBehaviour
|
||||
{
|
||||
//<2F><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public const int CELLSCALE = 100;
|
||||
//<2F><><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD>
|
||||
public const int widthPixel = 48;
|
||||
//<2F><><EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
public const int heightPixel = 32;
|
||||
//<2F><><EFBFBD>ŵ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
|
||||
public const int PicMapPixel = 512;
|
||||
|
||||
public delegate void LoadFinishedCallback();
|
||||
public LoadFinishedCallback onLoadFinishedCallback;
|
||||
|
||||
Reference in New Issue
Block a user