完成阻隔点

This commit is contained in:
2025-06-19 01:31:00 +08:00
parent a5da5b6d9d
commit c9984c9055
11 changed files with 2122 additions and 1368 deletions

Binary file not shown.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 654e4d2fabdac1d45ac947a83db687f2
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -49,7 +49,7 @@ public class GridSelector : MonoBehaviour
//创建新的地图默认为全部是可行走区域 //创建新的地图默认为全部是可行走区域
for (int i = 0; i < totalNumber; i++) for (int i = 0; i < totalNumber; i++)
{ {
dataArray[i].barrier = (int)CellType.None; dataArray[i].barrier = (int)CellType.Move;
} }
RefreshPlaneRender(); RefreshPlaneRender();
} }
@@ -77,7 +77,7 @@ public class GridSelector : MonoBehaviour
} }
public int getdataByPos(Vector3 pos) public int getdataByPos(Vector3 pos)
{ {
int hitIndex = Mathf.FloorToInt(pos.x / map.sideLength) + Mathf.FloorToInt(pos.z / map.sideLength) * horizontalNumber; int hitIndex = Mathf.FloorToInt(pos.x / map.sideWidth) + Mathf.FloorToInt(pos.z / map.sideHeight) * horizontalNumber;
return hitIndex; return hitIndex;
} }
private void Awake() private void Awake()
@@ -366,7 +366,9 @@ public class GridSelector : MonoBehaviour
} }
private void setDataCellType(int index,bool IsCancel) private void setDataCellType(int index,bool IsCancel)
{ {
if (true) if (UICellEditor.Instance == null) return;
if (UICellEditor.Instance.editorGrid == CellType.Move ||
UICellEditor.Instance.editorGrid == CellType.Obstacle)
{ {
if (IsCancel) if (IsCancel)
{ {
@@ -385,7 +387,7 @@ public class GridSelector : MonoBehaviour
dataArray[index].barrier |= (int)CellType.Obstacle; dataArray[index].barrier |= (int)CellType.Obstacle;
} }
} }
else if (true) else if (UICellEditor.Instance.editorGrid == CellType.Safe)
{ {
if (IsCancel) if (IsCancel)
{ {
@@ -399,7 +401,7 @@ public class GridSelector : MonoBehaviour
dataArray[index].barrier |= (int)CellType.Safe; dataArray[index].barrier |= (int)CellType.Safe;
} }
} }
else if (true) else if (UICellEditor.Instance.editorGrid == CellType.Stall)
{ {
if (IsCancel) if (IsCancel)
{ {
@@ -413,12 +415,50 @@ public class GridSelector : MonoBehaviour
dataArray[index].barrier |= (int)CellType.Stall; dataArray[index].barrier |= (int)CellType.Stall;
} }
} }
else if (UICellEditor.Instance.editorGrid == CellType.Hide)
{
if (IsCancel)
{
if ((dataArray[index].barrier & (int)CellType.Hide) != 0)
{
dataArray[index].barrier &= ~(int)CellType.Hide;
} }
}
else
{
dataArray[index].barrier |= (int)CellType.Hide;
}
}
}
public void FullAllArea()
{
for (int i = 0; i < dataArray.Length; i++)
{
CellType cell = (CellType)dataArray[i].barrier;
if (!cell.HasFlag(UICellEditor.Instance.editorGrid))
{
dataArray[i].barrier |= (int)UICellEditor.Instance.editorGrid;
}
}
RefreshPlaneRender();
}
public void ClearSelectArea()
{
for (int i = 0; i < dataArray.Length; i++)
{
CellType cell = (CellType)dataArray[i].barrier;
if (cell.HasFlag(UICellEditor.Instance.editorGrid))
{
dataArray[i].barrier &= ~(int)UICellEditor.Instance.editorGrid;
}
}
RefreshPlaneRender();
}
public void RefreshPlaneRender() public void RefreshPlaneRender()
{ {
moveNum = 0; moveNum = 0;
for (int i = 0; i < dataArray.Length; i++) { for (int i = 0; i < dataArray.Length; i++) {
//int barrier = dataArray[i].barrier;
setDataColor(i); setDataColor(i);
CellType cell = (CellType)dataArray[i].barrier; CellType cell = (CellType)dataArray[i].barrier;
if (cell.HasFlag(CellType.Move)) if (cell.HasFlag(CellType.Move))
@@ -434,10 +474,11 @@ public class GridSelector : MonoBehaviour
x = index % horizontalNumber; x = index % horizontalNumber;
y = index / horizontalNumber; y = index / horizontalNumber;
} }
//TODO 这里有改动,应该是对的
private Vector2 GetCenterPosByIndex(int index) private Vector2 GetCenterPosByIndex(int index)
{ {
GetXyByIndex(index, out int x, out int y); GetXyByIndex(index, out int x, out int y);
return new Vector2(x + 0.5f, y + 0.5f) * map.sideLength; return new Vector2((x + 0.5f)*map.sideWidth, (y + 0.5f) * map.sideHeight);
} }
private bool Pnpoly(Vector2 gridPos, Vector2 pos0, Vector2 pos1) private bool Pnpoly(Vector2 gridPos, Vector2 pos0, Vector2 pos1)
{ {

View File

@@ -37,20 +37,25 @@ public enum CellType
/// <20><>̯<EFBFBD><CCAF><EFBFBD><EFBFBD> /// <20><>̯<EFBFBD><CCAF><EFBFBD><EFBFBD>
/// </summary> /// </summary>
Stall = 32, Stall = 32,
}
[Flags]
public enum CellLayer
{
Move = 1, //<2F>ƶ<EFBFBD>
Obstacle = 2, //<2F>
Hide = 4, //<2F><><EFBFBD><EFBFBD>
Safe = 16, //<2F><>ȫ<EFBFBD><C8AB>
Stall = 32, //<2F><>̯
Audio = 64, //<2F><>Ч Audio = 64, //<2F><>Ч
Trigger = 128, //<2F><><EFBFBD><EFBFBD> Trigger = 128, //<2F><><EFBFBD><EFBFBD>
Monster = 256 //<2F><><EFBFBD><EFBFBD> Monster = 256 //<2F><><EFBFBD><EFBFBD>
} }
//[Flags]
//public enum CellLayer
//{
// None = 0, //<2F><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
// Move = 1, //<2F>ƶ<EFBFBD>
// Obstacle = 2, //<2F>
// Hide = 4, //<2F><><EFBFBD><EFBFBD>
// Safe = 16, //<2F><>ȫ<EFBFBD><C8AB>
// Stall = 32, //<2F><>̯
// Audio = 64, //<2F><>Ч
// Trigger = 128, //<2F><><EFBFBD><EFBFBD>
// Monster = 256 //<2F><><EFBFBD><EFBFBD>
//}
/// <summary> /// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ /// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
/// </summary> /// </summary>
@@ -66,41 +71,38 @@ public class AreaColor
} }
public class CellTypeColors public class CellTypeColors
{ {
public static Color None = new Color(0x80 / 255f, 0x80 / 255f, 0x80 / 255f); // <20><>ɫ (#808080) public static Color None = new Color(0xb0 / 255f, 0xb0 / 255f, 0xb0 / 255f,0); // dz<EFBFBD><EFBFBD>ɫ (#b0b0b0)
public static Color Move = new Color(0x33 / 255f, 0xcc / 255f, 0x33 / 255f); // <20><>ɫ (#33cc33) public static Color Move = new Color(0x00 / 255f, 0xff / 255f, 0x00 / 255f); // <20><><EFBFBD><EFBFBD>ɫ (#00ff00)
public static Color Obstacle = new Color(0xff / 255f, 0x00 / 255f, 0x00 / 255f); // <20><>ɫ (#ff4d4d) public static Color Obstacle = new Color(0xff / 255f, 0x00 / 255f, 0x00 / 255f); // <20>ʺ<EFBFBD>ɫ (#ff0000)
public static Color Hide = new Color(0x33 / 255f, 0x33 / 255f, 0x33 / 255f); // <20><><EFBFBD><EFBFBD>ɫ (#333333) public static Color Hide = new Color(0x80 / 255f, 0x00 / 255f, 0xff / 255f); // <20><><EFBFBD><EFBFBD>ɫ (#8000ff)
public static Color HadRole = new Color(0xb3 / 255f, 0x33 / 255f, 0xb3 / 255f); // <20><>ɫ (#b333b3) public static Color Safe = new Color(0x00 / 255f, 0xff / 255f, 0xff / 255f); // <20><><EFBFBD><EFBFBD>ɫ (#00ffff)
public static Color Safe = new Color(0x00 / 255f, 0xff / 255f, 0xff / 255f); // <20><>ɫ (#00ffff) public static Color Stall = new Color(0xff / 255f, 0x80 / 255f, 0x00 / 255f); // <20>ʳ<EFBFBD>ɫ (#ff8000)
public static Color Stall = new Color(0xff / 255f, 0xff / 255f, 0x99 / 255f); // dz<><C7B3>ɫ (#ffff99)
public static Color Water = new Color(0x00 / 255f, 0x4c / 255f, 0xb3 / 255f); // ˮ<><CBAE>ɫ (#004cb3)
public static Color Snow = new Color(0xff / 255f, 0xff / 255f, 0xff / 255f); // <20><>ɫ (#ffffff)
public static Color Sand = new Color(0xff / 255f, 0xcc / 255f, 0x66 / 255f); // ɳ<><C9B3>ɫ (#ffcc66)
public static Color Stone = new Color(0x66 / 255f, 0x66 / 255f, 0x66 / 255f); // <20><><EFBFBD><EFBFBD>ɫ (#666666)
public static Color Wood = new Color(0x8B / 255f, 0x45 / 255f, 0x13 / 255f); // <20><>ɫ (#8B4513)
public static Color Grass = new Color(0x00 / 255f, 0xff / 255f, 0xff / 255f); // <20><>ɫ (#00ffff)
public static Color Dirt = new Color(0xff / 255f, 0x49 / 255f, 0x00 / 255f); // dz<><C7B3>ɫ (#FF4900)
public static Color GetColor(CellType cellType) public static Color GetColor(CellType cellType)
{ {
Color color = Color.clear; // <20><>ʼ<EFBFBD><CABC>Ϊ<EFBFBD><CEAA>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> Color color = Color.clear; // <20><>ʼ<EFBFBD><CABC>Ϊ<EFBFBD><CEAA>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
if (cellType == CellType.None) return CellTypeColors.None; if (cellType == CellType.None) return CellTypeColors.None;
if (true) if (cellType.HasFlag(CellType.Move)) color += CellTypeColors.Move * 0.6f;
if (cellType.HasFlag(CellType.Obstacle)) color += CellTypeColors.Obstacle * 0.6f;
if(UICellEditor.Instance == null) return color;
if (UICellEditor.Instance.editorGrid == CellType.Hide)
{ {
if (cellType.HasFlag(CellType.Move)) color += CellTypeColors.Move; if (cellType.HasFlag(CellType.Hide)) color += CellTypeColors.Hide * 0.8f;
} }
else if (true) else if (UICellEditor.Instance.editorGrid == CellType.Safe)
{ {
if (cellType.HasFlag(CellType.Safe)) color += CellTypeColors.Safe; if (cellType.HasFlag(CellType.Safe)) color += CellTypeColors.Safe * 0.8f;
} }
else if (true) else if (UICellEditor.Instance.editorGrid == CellType.Stall)
{ {
if (cellType.HasFlag(CellType.Stall)) color += CellTypeColors.Stall; if (cellType.HasFlag(CellType.Stall)) color += CellTypeColors.Stall * 0.8f;
} }
if (cellType.HasFlag(CellType.Obstacle)) color += CellTypeColors.Obstacle; // ȷ<><C8B7><EFBFBD><EFBFBD>ɫֵ<C9AB><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
// <20><><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ,<2C>Ȳ<EFBFBD><C8B2><EFBFBD>һ<EFBFBD><D2BB> color.r = Mathf.Clamp01(color.r);
//color /= 7.0f; // 7 <20><> CellType <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> color.g = Mathf.Clamp01(color.g);
color.b = Mathf.Clamp01(color.b);
color.a = 1f; // ȷ<><C8B7><EFBFBD><EFBFBD>͸<EFBFBD><CDB8>
return color; return color;
} }
public static string GetAreaStr(int barrier) public static string GetAreaStr(int barrier)

View File

@@ -80,7 +80,7 @@ public partial class MapManager : MonoBehaviour
public CellNode[] cellsNode; public CellNode[] cellsNode;
private Dictionary<CellLayer, List<GameObject>> _layCellsMap = new Dictionary<CellLayer, List<GameObject>>(); private Dictionary<CellType, List<GameObject>> _layCellsMap = new Dictionary<CellType, List<GameObject>>();
public void SetEditCellType(EditCellType type) public void SetEditCellType(EditCellType type)
{ {
@@ -688,7 +688,7 @@ public partial class MapManager : MonoBehaviour
} }
public int GetLayCellCount(CellLayer lay) public int GetLayCellCount(CellType lay)
{ {
if(!_layCellsMap.ContainsKey(lay)) if(!_layCellsMap.ContainsKey(lay))
return 0; return 0;
@@ -898,55 +898,55 @@ public partial class MapManager : MonoBehaviour
} }
//<2F><><EFBFBD><EFBFBD>layer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> //<2F><><EFBFBD><EFBFBD>layer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public void AddLayerCell(GameObject go, CellLayer layer) public void AddLayerCell(GameObject go, CellType layer)
{ {
List<GameObject> cells = null; List<GameObject> cells = null;
if (((CellLayer)layer & CellLayer.Move) == CellLayer.Move) if (((CellType)layer & CellType.Move) == CellType.Move)
{ {
cells = _layCellsMap[CellLayer.Move]; cells = _layCellsMap[CellType.Move];
cells.Add(go); cells.Add(go);
} }
if (((CellLayer)layer & CellLayer.Obstacle) == CellLayer.Obstacle) if (((CellType)layer & CellType.Obstacle) == CellType.Obstacle)
{ {
cells = _layCellsMap[CellLayer.Obstacle]; cells = _layCellsMap[CellType.Obstacle];
cells.Add(go); cells.Add(go);
} }
if (((CellLayer)layer & CellLayer.Hide) == CellLayer.Hide) if (((CellType)layer & CellType.Hide) == CellType.Hide)
{ {
cells = _layCellsMap[CellLayer.Hide]; cells = _layCellsMap[CellType.Hide];
cells.Add(go); cells.Add(go);
} }
if (((CellLayer)layer & CellLayer.Safe) == CellLayer.Safe) if (((CellType)layer & CellType.Safe) == CellType.Safe)
{ {
cells = _layCellsMap[CellLayer.Safe]; cells = _layCellsMap[CellType.Safe];
cells.Add(go); cells.Add(go);
} }
if (((CellLayer)layer & CellLayer.Stall) == CellLayer.Stall) if (((CellType)layer & CellType.Stall) == CellType.Stall)
{ {
cells = _layCellsMap[CellLayer.Stall]; cells = _layCellsMap[CellType.Stall];
cells.Add(go); cells.Add(go);
} }
if (((CellLayer)layer & CellLayer.Audio) == CellLayer.Audio) if (((CellType)layer & CellType.Audio) == CellType.Audio)
{ {
cells = _layCellsMap[CellLayer.Audio]; cells = _layCellsMap[CellType.Audio];
cells.Add(go); cells.Add(go);
} }
if (((CellLayer)layer & CellLayer.Trigger) == CellLayer.Trigger) if (((CellType)layer & CellType.Trigger) == CellType.Trigger)
{ {
cells = _layCellsMap[CellLayer.Trigger]; cells = _layCellsMap[CellType.Trigger];
cells.Add(go); cells.Add(go);
} }
if (((CellLayer)layer & CellLayer.Monster) == CellLayer.Monster) if (((CellType)layer & CellType.Monster) == CellType.Monster)
{ {
cells = _layCellsMap[CellLayer.Monster]; cells = _layCellsMap[CellType.Monster];
cells.Add(go); cells.Add(go);
} }
} }
@@ -956,13 +956,13 @@ public partial class MapManager : MonoBehaviour
if (layers == 0) if (layers == 0)
return; return;
if(layers < (int)CellLayer.Stall) if(layers < (int)CellType.Stall)
{ {
bool safeNoHide = ((CellLayer)layers & CellLayer.Safe) == CellLayer.Safe; bool safeNoHide = ((CellType)layers & CellType.Safe) == CellType.Safe;
foreach (var layerCells in _layCellsMap) foreach (var layerCells in _layCellsMap)
{ {
safeNoHide = (layerCells.Key & CellLayer.Safe) == CellLayer.Safe; safeNoHide = (layerCells.Key & CellType.Safe) == CellType.Safe;
if (((int)layerCells.Key & layers) != (int)layerCells.Key) if (((int)layerCells.Key & layers) != (int)layerCells.Key)
{ {
HideCellsWithLayer(layerCells.Key, layers, safeNoHide); HideCellsWithLayer(layerCells.Key, layers, safeNoHide);
@@ -982,22 +982,22 @@ public partial class MapManager : MonoBehaviour
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD> //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD>
HideCells(); HideCells();
if(((CellLayer)layers & CellLayer.Stall) == CellLayer.Stall) if(((CellType)layers & CellType.Stall) == CellType.Stall)
{ {
ShowSpecialPoint(EditCellType.SellArea); ShowSpecialPoint(EditCellType.SellArea);
} }
if (((CellLayer)layers & CellLayer.Audio) == CellLayer.Audio) if (((CellType)layers & CellType.Audio) == CellType.Audio)
{ {
ShowSpecialPoint(EditCellType.AudioTrigger); ShowSpecialPoint(EditCellType.AudioTrigger);
} }
if (((CellLayer)layers & CellLayer.Trigger) == CellLayer.Trigger) if (((CellType)layers & CellType.Trigger) == CellType.Trigger)
{ {
ShowSpecialPoint(EditCellType.TriggerCell); ShowSpecialPoint(EditCellType.TriggerCell);
} }
if (((CellLayer)layers & CellLayer.Monster) == CellLayer.Monster) if (((CellType)layers & CellType.Monster) == CellType.Monster)
{ {
ShowSpecialPoint(EditCellType.MonsterArea); ShowSpecialPoint(EditCellType.MonsterArea);
} }
@@ -1005,7 +1005,7 @@ public partial class MapManager : MonoBehaviour
} }
public void HideCellsWithLayer(CellLayer hideLayer, int showLayers, bool safeNoHide) public void HideCellsWithLayer(CellType hideLayer, int showLayers, bool safeNoHide)
{ {
var cells = _layCellsMap[hideLayer]; var cells = _layCellsMap[hideLayer];
foreach(var cell in cells) foreach(var cell in cells)
@@ -1052,7 +1052,7 @@ public partial class MapManager : MonoBehaviour
public void CleanSafe() public void CleanSafe()
{ {
var cells = _layCellsMap[CellLayer.Safe]; var cells = _layCellsMap[CellType.Safe];
if (cells == null) if (cells == null)
return; return;

View File

@@ -173,7 +173,6 @@ public partial class MapManager : MonoBehaviour
} }
} }
MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum); MapManager.Instance.ReseCamera(jpgscenew * mapColumn, jpgscenew * mapRownum);
MapManager.Instance.GenerateMap(jpgscenew * mapColumn, jpgscenew * mapRownum, widthPixel / 100.0f, heightPixel / 100.0f);
UICellInfo.Instance.ShowMapCellInfo(); UICellInfo.Instance.ShowMapCellInfo();
} }
@@ -185,6 +184,13 @@ public partial class MapManager : MonoBehaviour
Destroy(child.gameObject); Destroy(child.gameObject);
} }
} }
public void CreateObs()
{
if(_curMapRegions == null) return;
float jpgscenew = PicMapPixel / 100;
MapManager.Instance.GenerateMap(jpgscenew * _curMapRegions.regionColNum, jpgscenew * _curMapRegions.regionRowNum, _curMapRegions.cellWidthPixel / 100.0f, _curMapRegions.cellHeightPixel / 100.0f);
}
private async void multithreadLoadTextrue(string fullPath,SpriteRenderer sr) private async void multithreadLoadTextrue(string fullPath,SpriteRenderer sr)
{ {
var texture = await loadASyncTexture2D(fullPath, this.GetCancellationTokenOnDestroy()); var texture = await loadASyncTexture2D(fullPath, this.GetCancellationTokenOnDestroy());

View File

@@ -69,6 +69,7 @@ public partial class MapManager : MonoBehaviour
} }
/// <summary> /// <summary>
/// 获取地图位置的高度 /// 获取地图位置的高度
/// </summary> /// </summary>
@@ -79,6 +80,57 @@ public partial class MapManager : MonoBehaviour
int posIndex = Mathf.FloorToInt(pos.x + Mathf.FloorToInt(pos.z) * map.horizontalNumber); int posIndex = Mathf.FloorToInt(pos.x + Mathf.FloorToInt(pos.z) * map.horizontalNumber);
return map.selector.GetGridData()[posIndex].barrier; return map.selector.GetGridData()[posIndex].barrier;
} }
/// <summary>
/// 是否打开了地图
/// </summary>
/// <returns></returns>
public bool isOpenMap(bool isTips = true)
{
if (map == null || map.selector == null)
{
if (isTips) UIWindow.Instance.ShowMessage("当前没有可编辑地图,请打开地图!");
return false;
}
return true;
}
public void SaveMapObs()
{
if (!MapManager.Instance.isOpenMap()) return;
string path = PathUtil.GetObsPath(MapManager.Instance._curOpenMapId, "Obs");
string tmp = path.Substring(0, path.LastIndexOf('/'));
if (!Directory.Exists(tmp))
Directory.CreateDirectory(tmp);
if (File.Exists(path))
File.Delete(path);
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
{
BinaryWriter bw = new BinaryWriter(fs);
Map.Serialize(MapManager.Instance.map, bw);
bw.Close();
}
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
}
public bool LoadMapObs(int mapId)
{
string path = PathUtil.GetObsPath(MapManager.Instance._curOpenMapId, "Obs");
if (!File.Exists(path))
return false;
if (map != null)
{
map.Release();
map = null;
}
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
BinaryReader br = new BinaryReader(fs);
map = Map.Deserialize(br);
br.Close();
}
return true;
}
} }
public partial class Map public partial class Map
{ {
@@ -87,8 +139,6 @@ public partial class Map
public int mapId { get; private set; } public int mapId { get; private set; }
public float width { get; private set; } public float width { get; private set; }
public float height { get; private set; } public float height { get; private set; }
public float sideLength { get; private set; }
public float sideWidth { get; private set; } public float sideWidth { get; private set; }
public float sideHeight { get; private set; } public float sideHeight { get; private set; }
public int horizontalNumber { get { return (int)(width / sideWidth); } } public int horizontalNumber { get { return (int)(width / sideWidth); } }
@@ -98,8 +148,6 @@ public partial class Map
{ {
this.width = width; this.width = width;
this.height = height; this.height = height;
this.sideLength = sideLength;
this.sideWidth = sideWidth; this.sideWidth = sideWidth;
this.sideHeight = sideHeight; this.sideHeight = sideHeight;
mapGrid = CreateMapGrid(); mapGrid = CreateMapGrid();
@@ -164,11 +212,11 @@ public partial class Map
{ {
int width = map.selector.horizontalNumber; int width = map.selector.horizontalNumber;
int height = map.selector.verticalNumber; int height = map.selector.verticalNumber;
int sideLength = (int)(map.sideLength * 100);
bw.Write(map.mapId); bw.Write(map.mapId);
bw.Write(width); bw.Write(width);
bw.Write(height); bw.Write(height);
bw.Write(sideLength); bw.Write((int)Mathf.Round(map.sideWidth * 100)); // 四舍五入确保精度
bw.Write((int)Mathf.Round(map.sideHeight * 100)); // 四舍五入确保精度
GridSelector.RenderData[] data = map.selector.GetGridData(); GridSelector.RenderData[] data = map.selector.GetGridData();
for (int i = 0, length = data.Length; i < length; i++) for (int i = 0, length = data.Length; i < length; i++)
{ {
@@ -181,10 +229,9 @@ public partial class Map
int mapId = br.ReadInt32(); int mapId = br.ReadInt32();
int horizontalNumber = br.ReadInt32(); int horizontalNumber = br.ReadInt32();
int verticalNumber = br.ReadInt32(); int verticalNumber = br.ReadInt32();
//服务器那边是用的边长的100倍的int float sideWidth = br.ReadInt32() / 100f; // 读取时直接除以 100
float sideWidth = br.ReadInt32() / 100f; float sideHeight = br.ReadInt32() / 100f; // 读取时直接除以 100
float sideHeight = br.ReadInt32() / 100f; var map = MapManager.Instance.GenerateMap(horizontalNumber * sideWidth, verticalNumber * sideHeight, sideWidth, sideHeight);
var map = MapManager.Instance.GenerateMap((int)(horizontalNumber * sideWidth), (int)(verticalNumber * sideHeight), sideWidth, sideHeight);
map.SetMapId(mapId); map.SetMapId(mapId);
GridSelector.RenderData[] data = map.selector.GetGridData(); GridSelector.RenderData[] data = map.selector.GetGridData();
for (int i = 0; i < horizontalNumber * verticalNumber; i++) { for (int i = 0; i < horizontalNumber * verticalNumber; i++) {

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
@@ -19,6 +20,18 @@ public class UICellEditor : MonoBehaviour
public Button btnSetBrush; public Button btnSetBrush;
public Button btnSaveCells; public Button btnSaveCells;
/// <summary>
/// <20><><EFBFBD>ڱ༭<DAB1><E0BCAD><EFBFBD><EFBFBD>
/// </summary>
public CellType editorGrid { private set; get; }
public ToggleGroup editorAreaToggle;
public static UICellEditor Instance;
private void Awake()
{
Instance = this;
editorGrid = CellType.None;
}
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ· #region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ·
public Toggle togPathTest; public Toggle togPathTest;
public GameObject pathTestPanel; public GameObject pathTestPanel;
@@ -192,7 +205,7 @@ public class UICellEditor : MonoBehaviour
//ͼ<><CDBC><EFBFBD> //ͼ<><CDBC><EFBFBD>
public void OnShowLayerToggleChange() public void OnShowLayerToggleChange()
{ {
CellLayer[] layers = (CellLayer[])Enum.GetValues(typeof(CellLayer)); CellType[] layers = (CellType[])Enum.GetValues(typeof(CellType));
_layers = 0; _layers = 0;
for (int i= showgLayers.Length - 1; i>=0; i--) for (int i= showgLayers.Length - 1; i>=0; i--)
{ {
@@ -209,23 +222,72 @@ public class UICellEditor : MonoBehaviour
{ {
MapManager.Instance.HideCells(); MapManager.Instance.HideCells();
} }
public void EditorAreaToggleChange(Toggle t)
{
if (t.isOn)
{
switch (t.name)
{
case "MoveToggle":
editorGrid = CellType.Move;
break;
case "BlockToggle":
editorGrid = CellType.Obstacle;
break;
case "HideToggle":
editorGrid = CellType.Hide;
break;
case "SafeToggle":
editorGrid = CellType.Safe;
break;
case "StallToggle":
editorGrid = CellType.Stall;
break;
}
MapManager.Instance.map?.selector.RefreshPlaneRender();
}
if (editorAreaToggle.ActiveToggles().Count() == 0)
{
Debug.Log(<><C3BB>ѡ<EFBFBD>б<D0B1><E0BCAD><EFBFBD><EFBFBD>");
editorGrid = CellType.None;
}
}
public void SetBrush() /// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>
/// </summary>
public void CleanSelectArea()
{ {
if (!UIWindow.Instance.uiCellInfo.bMapOpened) if (editorGrid == CellType.None)
{ {
UIWindow.Instance.ShowMessage("<22><><EFBFBD>ȴ򿪵<EFBFBD>ͼ"); UIWindow.Instance.ShowMessage("<22><>ǰû<EFBFBD>пɱ༭<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
return; return;
} }
if (!MapManager.Instance.isOpenMap())
float brushRadius = Convert.ToSingle(txtBrushRadius.text); return;
CellType type = (CellType)(1 << dropCellType.value); MapManager.Instance.map.selector.ClearSelectArea();
MapManager.Instance.SetBrush(brushRadius, type);
MapManager.Instance.StartEditor();
} }
/// <summary>
public void CleanSafe() /// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>
/// </summary>
public void FullSelectArea()
{ {
MapManager.Instance.CleanSafe(); if (editorGrid == CellType.None)
{
UIWindow.Instance.ShowMessage("<22><>ǰû<C7B0>пɱ༭<C9B1><E0BCAD><EFBFBD><EFBFBD>");
return;
}
if (!MapManager.Instance.isOpenMap())
return;
MapManager.Instance.map.selector.FullAllArea();
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>
/// </summary>
public void SaveObs()
{
if (!MapManager.Instance.isOpenMap())
return;
MapManager.Instance.SaveMapObs();
} }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.Common;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using UnityEngine; using UnityEngine;
@@ -115,6 +116,7 @@ public class UIMapPanel : MonoBehaviour
int mapId = Convert.ToInt32(dropMap.options[dropMap.value].text); int mapId = Convert.ToInt32(dropMap.options[dropMap.value].text);
_curOpenMapId = mapId; _curOpenMapId = mapId;
MapManager.Instance.LoadMapRegionSprites(_curOpenMapId); MapManager.Instance.LoadMapRegionSprites(_curOpenMapId);
MapManager.Instance.LoadMapObs(_curOpenMapId);
//UIWindow.Instance.uiCellInfo.ShowCells(); //UIWindow.Instance.uiCellInfo.ShowCells();
//UIWindow.Instance.uiEditMapConfig.LoadMapConfig(mapId); //UIWindow.Instance.uiEditMapConfig.LoadMapConfig(mapId);
//UIWindow.Instance.uiMonstersPanel.LoadMonsterConfig(mapId); //UIWindow.Instance.uiMonstersPanel.LoadMonsterConfig(mapId);
@@ -123,6 +125,12 @@ public class UIMapPanel : MonoBehaviour
//UIWindow.Instance.uiFuBensPanel.LoadFuBenConfig(mapId); //UIWindow.Instance.uiFuBensPanel.LoadFuBenConfig(mapId);
//UIWindow.Instance.uiJuBaosPanel.LoadJuBaoConfig(mapId); //UIWindow.Instance.uiJuBaosPanel.LoadJuBaoConfig(mapId);
//<2F><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (MapManager.Instance.map == null)
{
MapManager.Instance.CreateObs();
}
} }
public void CloseMap() public void CloseMap()

View File

@@ -21,5 +21,10 @@ public class PathUtil
{ {
return $"{Application.dataPath}/GameAssets/Maps/{mapId}/XML/{fileName}.xml"; return $"{Application.dataPath}/GameAssets/Maps/{mapId}/XML/{fileName}.xml";
} }
public static string GetObsPath(int mapId, string fileName)
{
return $"{Application.dataPath}/GameAssets/Maps/{mapId}/XML/{fileName}.bytes";
}
#endregion #endregion
} }