改了格子大小

This commit is contained in:
tangbin
2025-07-25 15:36:10 +08:00
parent 5d63e4878c
commit f88a2e9504
1009 changed files with 69967 additions and 81 deletions

View File

@@ -29,9 +29,9 @@ public class GridSelector : MonoBehaviour
public int moveNum;
private ComputeBuffer inputbuffer;
private RenderData[] dataArray;
public RenderData[] dataArray;
private List<int> selectedGridIndex = new List<int>();
public List<int> selectedGridIndex = new List<int>();
private int shiftBeginIndex;
private List<Vector2> lassoPos = new List<Vector2>();
@@ -456,10 +456,11 @@ public class GridSelector : MonoBehaviour
for (int i = 0; i < dataArray.Length; i++)
{
CellType cell = (CellType)dataArray[i].barrier;
if (!cell.HasFlag(UICellEditor.Instance.editorGrid))
if (cell.HasFlag(CellType.Move))
{
dataArray[i].barrier |= (int)UICellEditor.Instance.editorGrid;
dataArray[i].barrier &= ~(int)CellType.Move;
}
dataArray[i].barrier |= (int)CellType.Obstacle;
}
RefreshPlaneRender();
}
@@ -468,10 +469,11 @@ public class GridSelector : MonoBehaviour
for (int i = 0; i < dataArray.Length; i++)
{
CellType cell = (CellType)dataArray[i].barrier;
if (cell.HasFlag(UICellEditor.Instance.editorGrid))
if (cell.HasFlag(CellType.Obstacle))
{
dataArray[i].barrier &= ~(int)UICellEditor.Instance.editorGrid;
dataArray[i].barrier &= ~(int)CellType.Obstacle;
}
dataArray[i].barrier |= (int)CellType.Move;
}
RefreshPlaneRender();
}
@@ -490,7 +492,7 @@ public class GridSelector : MonoBehaviour
inputbuffer.SetData(dataArray);
mapRenderer.material.SetBuffer("_InputData", inputbuffer);
}
private void GetXyByIndex(int index,out int x,out int y)
public void GetXyByIndex(int index,out int x,out int y)
{
x = index % horizontalNumber;
y = index / horizontalNumber;

View File

@@ -118,6 +118,7 @@ public class CellTypeColors
if (cellType.HasFlag(CellType.Obstacle)) areaStr += "|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
if (cellType.HasFlag(CellType.Safe)) areaStr += "|<7C><>ȫ<EFBFBD><C8AB>";
if (cellType.HasFlag(CellType.Stall)) areaStr += "|<7C><>̯<EFBFBD><CCAF>";
if (cellType.HasFlag(CellType.Hide)) areaStr += "|<7C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return areaStr;
}
}

View File

@@ -30,7 +30,7 @@ public partial class MapManager : MonoBehaviour
Vector3 newPosition = Camera.main.transform.position + move;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>Χ<EFBFBD><CEA7><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ͼ<EFBFBD>߽磩
newPosition.x = Mathf.Clamp(newPosition.x, 0, mapRealWidth);
newPosition.x = Mathf.Clamp(newPosition.x, 0, mapRealWidth * 1.5f);
newPosition.y = Mathf.Clamp(newPosition.y, 0, mapRealHeight);
Camera.main.transform.position = newPosition;
@@ -49,7 +49,7 @@ public partial class MapManager : MonoBehaviour
public void MoveToCamera(float x, float y)
{
Vector3 newPosition;
newPosition.x = Mathf.Clamp(x, 0, mapRealWidth);
newPosition.x = Mathf.Clamp(x, 0, mapRealWidth * 1.5f);
newPosition.y = Mathf.Clamp(y, 0, mapRealHeight);
Camera.main.transform.position = new Vector3(x, y, -10);
}
@@ -59,7 +59,7 @@ public partial class MapManager : MonoBehaviour
Vector2Int pos = new Vector2Int();
pos.x = (int)Camera.main.transform.position.x;
pos.y = (int)Camera.main.transform.position.y;
pos.x = Mathf.Clamp(pos.x, 0, (int)mapRealWidth);
pos.x = Mathf.Clamp(pos.x, 0, (int)(mapRealWidth * 1.5f));
pos.y = Mathf.Clamp(pos.y, 0, (int)mapRealHeight);
pos.x = (int)(pos.x / map.sideWidth);
pos.y = (int)(pos.y / map.sideHeight);

View File

@@ -1,23 +1,13 @@
using Cysharp.Threading.Tasks;
using HxGame;
using HxGame.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Security.Policy;
using System.Threading;
using System.Xml;
using System.Xml.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;
using UnityEngine.UIElements;
using static MapManager;
using static UnityEngine.Rendering.DebugUI.Table;
using System.Linq;
public partial class MapManager : MonoBehaviour
{
@@ -50,8 +40,112 @@ public partial class MapManager : MonoBehaviour
return;
}
_curMapRegions?.SaveXML(mapId);
}
public void SaveAtlasToFile()
{
int atlasWidth = _curMapRegions.regionRowNum * (int)_curMapRegions.regionWidth;
int atlasHeight = _curMapRegions.regionColNum * (int)_curMapRegions.regionHeight;
if (atlasWidth < 8192)
{
SaveAtlasToFileSmall();
return;
}
// ʹ<><CAB9><EFBFBD>ڴ<EFBFBD><DAB4>Ż<EFBFBD><C5BB><EFBFBD>Bitmap<61><70><EFBFBD><EFBFBD>
Bitmap atlas = new Bitmap(atlasWidth, atlasHeight, PixelFormat.Format24bppRgb);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(atlas))
{
g.Transform = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, atlas.Height);
for (int row = 0; row < _curMapRegions.regionRowNum; row++)
{
for (int col = 0; col < _curMapRegions.regionColNum; col++)
{
Texture2D tileTex = _curMapRegions.regions[row, col].texture;
if (tileTex == null) continue;
Bitmap tileBitmap = TextureToBitmap(tileTex);
g.DrawImage(
tileBitmap,
row * (int)_curMapRegions.regionWidth,
col * (int)_curMapRegions.regionHeight
);
tileBitmap.Dispose();
}
}
}
// <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>JPG<50><47><EFBFBD><EFBFBD>Alphaʱ<61><CAB1>
string outputPath = $"{PathUtil.GetBigMapPath(_curOpenMapId)}/map_{_curOpenMapId}.jpg";
atlas.Save(outputPath, ImageFormat.Jpeg);
atlas.Dispose();
Debug.Log($"<22><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ߴ<EFBFBD>: {atlasWidth}x{atlasHeight}");
UIWindow.Instance.ShowMessage("<22><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>");
}
private Bitmap TextureToBitmap(Texture2D texture)
{
bool hasAlpha = texture.GetPixels().Any(c => c.a < 1f);
Bitmap bitmap = new Bitmap(
texture.width,
texture.height,
hasAlpha ? PixelFormat.Format32bppArgb : PixelFormat.Format24bppRgb
);
BitmapData data = bitmap.LockBits(
new Rectangle(0, 0, texture.width, texture.height),
ImageLockMode.WriteOnly,
bitmap.PixelFormat
);
byte[] bytes = new byte[texture.width * texture.height * (hasAlpha ? 4 : 3)];
UnityEngine.Color[] pixels = texture.GetPixels();
for (int i = 0; i < pixels.Length; i++)
{
bytes[i * (hasAlpha ? 4 : 3)] = (byte)(pixels[i].b * 255); // B
bytes[i * (hasAlpha ? 4 : 3) + 1] = (byte)(pixels[i].g * 255); // G
bytes[i * (hasAlpha ? 4 : 3) + 2] = (byte)(pixels[i].r * 255); // R
if (hasAlpha) bytes[i * 4 + 3] = (byte)(pixels[i].a * 255); // A
}
System.Runtime.InteropServices.Marshal.Copy(bytes, 0, data.Scan0, bytes.Length);
bitmap.UnlockBits(data);
return bitmap;
}
public void SaveAtlasToFileSmall()
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>ijߴ<C4B3>
int atlasWidth = _curMapRegions.regionRowNum * (int)_curMapRegions.regionWidth;
int atlasHeight = _curMapRegions.regionColNum * (int)_curMapRegions.regionHeight;
// <20><><EFBFBD><EFBFBD><EFBFBD>յĴ<D5B5>ͼ
Texture2D atlas = new Texture2D(atlasWidth, atlasHeight);
atlas.filterMode = FilterMode.Bilinear; // <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сͼ<D0A1><CDBC><EFBFBD>ϲ<EFBFBD>
for (int row = 0; row < _curMapRegions.regionRowNum; row++)
{
for (int col = 0; col < _curMapRegions.regionColNum; col++)
{
HxGame.Data.Region region = _curMapRegions.regions[row, col];
Texture2D tileTex = region.texture; // <20><><EFBFBD><EFBFBD>Сͼ<D0A1><CDBC><EFBFBD><EFBFBD>
atlas.SetPixels(
row * (int)_curMapRegions.regionWidth,
col * (int)_curMapRegions.regionHeight,
(int)_curMapRegions.regionWidth,
(int)_curMapRegions.regionHeight,
tileTex.GetPixels()
);
}
}
atlas.Apply(); // Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD>
byte[] pngData = atlas.EncodeToJPG();
File.WriteAllBytes($"{PathUtil.GetBigMapPath(_curOpenMapId)}/map_{_curOpenMapId}.jpg", pngData);
UIWindow.Instance.ShowMessage("<22><>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>");
}
public void LoadMapRegionSprites(int mapId)
{
if (!allMaps.TryGetValue(mapId.ToString(),out var mapInfo))
@@ -69,7 +163,7 @@ public partial class MapManager : MonoBehaviour
_curMapRegions.regionHeight = PicMapPixel;
_curMapRegions.cellWidthPixel = widthPixel;
_curMapRegions.cellHeightPixel = heightPixel;
_curMapRegions.regions = new Region[mapRownum, mapColumn];
_curMapRegions.regions = new HxGame.Data.Region[mapRownum, mapColumn];
int maxRow = mapColumn;
int maxCol = mapRownum;
@@ -87,10 +181,10 @@ public partial class MapManager : MonoBehaviour
float x = row * jpgscenew;
float y = col * jpgscenew;
obj.transform.position = new Vector2(x, y);
_curMapRegions.regions[row, col] = new Region();
_curMapRegions.regions[row, col] = new HxGame.Data.Region();
_curMapRegions.regions[row, col].indexX = row;
_curMapRegions.regions[row, col].indexY = col;
multithreadLoadTextrue(spPath, sr);
multithreadLoadTextrue(spPath, sr, _curMapRegions.regions[row, col]);
_curMapRegions.regions[row, col].regionName = filename;
}
}
@@ -111,13 +205,14 @@ public partial class MapManager : MonoBehaviour
float jpgscenew = PicMapPixel / 100.0f;
MapManager.Instance.GenerateMap(mapid, jpgscenew * _curMapRegions.regionRowNum, jpgscenew * _curMapRegions.regionColNum, _curMapRegions.cellWidthPixel / 100.0f, _curMapRegions.cellHeightPixel / 100.0f);
}
private async void multithreadLoadTextrue(string fullPath,SpriteRenderer sr)
private async void multithreadLoadTextrue(string fullPath,SpriteRenderer sr, HxGame.Data.Region region)
{
var texture = await loadASyncTexture2D(fullPath, this.GetCancellationTokenOnDestroy());
if (texture != null)
{
sr.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 100f);
}
region.texture = texture;
}
private UniTask<Texture2D> loadASyncTexture2D(string fullPath,CancellationToken token)

View File

@@ -17,7 +17,7 @@ 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;
public const int widthPixel = 64;
//<2F><><EFBFBD>Ӹ<EFBFBD><D3B8><EFBFBD><EFBFBD><EFBFBD>
public const int heightPixel = 32;
//<2F><><EFBFBD>ŵ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>