Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / mapEditor / TileView / EditorTileMap.cs
@lijincheng lijincheng on 17 Jul 2023 22 KB 小修改
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.Json;
  6. using Godot;
  7. using Godot.Collections;
  8.  
  9. namespace UI.MapEditor;
  10.  
  11. public partial class EditorTileMap : TileMap
  12. {
  13. /// <summary>
  14. /// 自动图块地板层
  15. /// </summary>
  16. public const int AutoFloorLayer = 0;
  17. /// <summary>
  18. /// 自定义图块地板层
  19. /// </summary>
  20. public const int CustomFloorLayer = 1;
  21. /// <summary>
  22. /// 自动图块中间层
  23. /// </summary>
  24. public const int AutoMiddleLayer = 2;
  25. /// <summary>
  26. /// 自定义图块中间层
  27. /// </summary>
  28. public const int CustomMiddleLayer = 3;
  29. /// <summary>
  30. /// 自动图块顶层
  31. /// </summary>
  32. public const int AutoTopLayer = 4;
  33. /// <summary>
  34. /// 自定义图块顶层
  35. /// </summary>
  36. public const int CustomTopLayer = 5;
  37. /// <summary>
  38. /// 所属地图编辑器UI
  39. /// </summary>
  40. public MapEditorPanel MapEditorPanel { get; set; }
  41. //鼠标坐标
  42. private Vector2 _mousePosition;
  43. //鼠标所在的cell坐标
  44. private Vector2I _mouseCellPosition;
  45. //上一帧鼠标所在的cell坐标
  46. private Vector2I _prevMouseCellPosition = new Vector2I(-99999, -99999);
  47. //单次绘制是否改变过tile数据
  48. private bool _changeFlag = false;
  49. //左键开始按下时鼠标所在的坐标
  50. private Vector2I _mouseStartCellPosition;
  51. //鼠标中建是否按下
  52. private bool _isMiddlePressed = false;
  53. private Vector2 _moveOffset;
  54. //左键是否按下
  55. private bool _isLeftPressed = false;
  56. //右键是否按下
  57. private bool _isRightPressed = false;
  58. //绘制填充区域
  59. private bool _drawFullRect = false;
  60. //负责存储自动图块数据
  61. private Grid<bool> _autoCellLayerGrid = new Grid<bool>();
  62. //用于生成导航网格
  63. private DungeonTileMap _dungeonTileMap;
  64. //停止绘制多久后开始执行生成操作
  65. private float _generateInterval = 3f;
  66. //生成自动图块和导航网格的计时器
  67. private float _generateTimer = -1;
  68. //检测地形结果
  69. private bool _checkTerrainFlag = true;
  70. //错误地形位置
  71. private Vector2I _checkTerrainErrorPosition = Vector2I.Zero;
  72. //是否执行生成地形成功
  73. private bool _isGenerateTerrain = false;
  74.  
  75. private bool _initLayer = false;
  76. //--------- 配置数据 -------------
  77. private int _sourceId = 0;
  78. private int _terrainSet = 0;
  79. private int _terrain = 0;
  80. private AutoTileConfig _autoTileConfig = new AutoTileConfig();
  81.  
  82. private string _groupName = "testGroup1";
  83. private string _fileName = "Room2";
  84. private Vector2I _roomPosition;
  85. private Vector2I _roomSize;
  86. private List<DoorAreaInfo> _doorConfigs = new List<DoorAreaInfo>();
  87. private DungeonRoomType _roomType = DungeonRoomType.Battle;
  88. private int _weight = 100;
  89. //-------------------------------
  90.  
  91. public override void _Ready()
  92. {
  93. InitLayer();
  94. }
  95.  
  96. public override void _Process(double delta)
  97. {
  98. var newDelta = (float)delta;
  99. _drawFullRect = false;
  100. var position = GetLocalMousePosition();
  101. _mouseCellPosition = LocalToMap(position);
  102. _mousePosition = new Vector2(
  103. _mouseCellPosition.X * GameConfig.TileCellSize,
  104. _mouseCellPosition.Y * GameConfig.TileCellSize
  105. );
  106.  
  107. if (!MapEditorPanel.ToolsPanel.S_HBoxContainer.Instance.IsPositionOver(GetGlobalMousePosition())) //不在Ui节点上
  108. {
  109. //左键绘制
  110. if (_isLeftPressed)
  111. {
  112. if (Input.IsKeyPressed(Key.Shift)) //按住shift绘制矩形
  113. {
  114. _drawFullRect = true;
  115. }
  116. else if (_prevMouseCellPosition != _mouseCellPosition || !_changeFlag) //鼠标位置变过
  117. {
  118. _changeFlag = true;
  119. _prevMouseCellPosition = _mouseCellPosition;
  120. //绘制自动图块
  121. SetSingleAutoCell(_mouseCellPosition);
  122. }
  123. }
  124. else if (_isRightPressed) //右键擦除
  125. {
  126. if (Input.IsKeyPressed(Key.Shift)) //按住shift擦除矩形
  127. {
  128. _drawFullRect = true;
  129. }
  130. else if (_prevMouseCellPosition != _mouseCellPosition || !_changeFlag) //鼠标位置变过
  131. {
  132. _changeFlag = true;
  133. _prevMouseCellPosition = _mouseCellPosition;
  134. EraseSingleAutoCell(_mouseCellPosition);
  135. }
  136. }
  137. else if (_isMiddlePressed) //中建移动
  138. {
  139. //GD.Print("移动...");
  140. Position = GetGlobalMousePosition() + _moveOffset;
  141. }
  142. }
  143.  
  144. //绘制停止指定时间后, 生成导航网格
  145. if (_generateTimer > 0)
  146. {
  147. _generateTimer -= newDelta;
  148. if (_generateTimer <= 0)
  149. {
  150. //计算区域
  151. CalcRect();
  152. GD.Print("开始检测是否可以生成地形...");
  153. if (CheckTerrain())
  154. {
  155. GD.Print("开始绘制导航网格...");
  156. if (GenerateNavigation())
  157. {
  158. GD.Print("开始绘制自动贴图...");
  159. GenerateTerrain();
  160. _isGenerateTerrain = true;
  161. }
  162. }
  163. else
  164. {
  165. SetErrorCell(_checkTerrainErrorPosition);
  166. }
  167. }
  168. }
  169. }
  170.  
  171. /// <summary>
  172. /// 绘制辅助线
  173. /// </summary>
  174. public void DrawGuides(CanvasItem canvasItem)
  175. {
  176. //轴线
  177. canvasItem.DrawLine(new Vector2(0, 2000), new Vector2(0, -2000), Colors.Green);
  178. canvasItem.DrawLine(new Vector2(2000, 0), new Vector2( -2000, 0), Colors.Red);
  179. //绘制房间区域
  180. if (_roomSize.X != 0 && _roomSize.Y != 0)
  181. {
  182. var size = TileSet.TileSize;
  183. canvasItem.DrawRect(new Rect2((_roomPosition - Vector2I.One) * size, (_roomSize + new Vector2I(2, 2)) * size),
  184. Colors.Aqua, false, 5f / Scale.X);
  185. }
  186. if (_checkTerrainFlag) //已经通过地形检测
  187. {
  188. //绘制导航网格
  189. var result = _dungeonTileMap.GetGenerateNavigationResult();
  190. if (result != null && result.Success)
  191. {
  192. var polygonData = _dungeonTileMap.GetPolygonData();
  193. Utils.DrawNavigationPolygon(canvasItem, polygonData, 3f / Scale.X);
  194. }
  195. }
  196.  
  197. if (_drawFullRect) //绘制填充矩形
  198. {
  199. var size = TileSet.TileSize;
  200. var cellPos = _mouseStartCellPosition;
  201. var temp = size;
  202. if (_mouseStartCellPosition.X > _mouseCellPosition.X)
  203. {
  204. cellPos.X += 1;
  205. temp.X -= size.X;
  206. }
  207. if (_mouseStartCellPosition.Y > _mouseCellPosition.Y)
  208. {
  209. cellPos.Y += 1;
  210. temp.Y -= size.Y;
  211. }
  212.  
  213. var pos = cellPos * size;
  214. canvasItem.DrawRect(new Rect2(pos, _mousePosition - pos + temp), Colors.White, false, 2f / Scale.X);
  215. }
  216. else //绘制单格
  217. {
  218. canvasItem.DrawRect(new Rect2(_mousePosition, TileSet.TileSize), Colors.White, false, 2f / Scale.X);
  219. }
  220. }
  221.  
  222. public override void _Input(InputEvent @event)
  223. {
  224. if (@event is InputEventMouseButton mouseButton)
  225. {
  226. if (mouseButton.ButtonIndex == MouseButton.Left) //左键
  227. {
  228. if (mouseButton.Pressed) //按下
  229. {
  230. _mouseStartCellPosition = LocalToMap(GetLocalMousePosition());
  231. }
  232. else
  233. {
  234. _changeFlag = false;
  235. if (_drawFullRect) //松开, 提交绘制的矩形区域
  236. {
  237. SetRectAutoCell(_mouseStartCellPosition, _mouseCellPosition);
  238. _drawFullRect = false;
  239. }
  240. }
  241.  
  242. _isLeftPressed = mouseButton.Pressed;
  243. }
  244. else if (mouseButton.ButtonIndex == MouseButton.Right) //右键
  245. {
  246. if (mouseButton.Pressed) //按下
  247. {
  248. _mouseStartCellPosition = LocalToMap(GetLocalMousePosition());
  249. }
  250. else
  251. {
  252. _changeFlag = false;
  253. if (_drawFullRect) //松开, 提交擦除的矩形区域
  254. {
  255. EraseRectAutoCell(_mouseStartCellPosition, _mouseCellPosition);
  256. _drawFullRect = false;
  257. }
  258. }
  259. _isRightPressed = mouseButton.Pressed;
  260. }
  261. else if (mouseButton.ButtonIndex == MouseButton.WheelDown)
  262. {
  263. //缩小
  264. Shrink();
  265. }
  266. else if (mouseButton.ButtonIndex == MouseButton.WheelUp)
  267. {
  268. //放大
  269. Magnify();
  270. }
  271. else if (mouseButton.ButtonIndex == MouseButton.Middle)
  272. {
  273. _isMiddlePressed = mouseButton.Pressed;
  274. if (_isMiddlePressed)
  275. {
  276. _moveOffset = Position - mouseButton.GlobalPosition;
  277. }
  278. }
  279. }
  280. else if (@event is InputEventKey eventKey)
  281. {
  282. if (eventKey.Pressed && eventKey.Keycode == Key.M)
  283. {
  284. GD.Print("测试保存地牢房间数据...");
  285. TriggerSave();
  286. }
  287. }
  288. }
  289.  
  290. //将指定层数据存入list中
  291. private void PushLayerDataToList(int layer, int sourceId, List<int> list)
  292. {
  293. var layerArray = GetUsedCellsById(layer, sourceId);
  294. foreach (var pos in layerArray)
  295. {
  296. var atlasCoords = GetCellAtlasCoords(layer, pos);
  297. list.Add(pos.X);
  298. list.Add(pos.Y);
  299. list.Add(_sourceId);
  300. list.Add(atlasCoords.X);
  301. list.Add(atlasCoords.Y);
  302. }
  303. }
  304.  
  305. private void SetLayerDataFromList(int layer, List<int> list)
  306. {
  307. for (var i = 0; i < list.Count; i += 5)
  308. {
  309. var pos = new Vector2I(list[i], list[i + 1]);
  310. var sourceId = list[i + 2];
  311. var atlasCoords = new Vector2I(list[i + 3], list[i + 4]);
  312. SetCell(layer, pos, sourceId, atlasCoords);
  313. if (layer == AutoFloorLayer)
  314. {
  315. _autoCellLayerGrid.Set(pos, true);
  316. }
  317. }
  318. }
  319.  
  320. //保存地牢
  321. private void TriggerSave()
  322. {
  323. SaveRoomInfoConfig();
  324. SaveTileInfoConfig();
  325. }
  326.  
  327. //加载地牢
  328. public void LoadTile(string roomName)
  329. {
  330. InitLayer();
  331. var path = GetConfigPath();
  332. var tileInfoConfigPath = path + "/" + GetTileInfoConfigName(_fileName);
  333. var text = ResourceManager.LoadText("D:\\GameProject\\DungeonShooting\\DungeonShooting_Godot\\resource\\map\\tileMaps\\testGroup1\\battle\\Room2\\Room2_tileInfo.json");
  334. var tileInfo = JsonSerializer.Deserialize<DungeonTileInfo>(text);
  335.  
  336. //地块数据
  337. SetLayerDataFromList(AutoFloorLayer, tileInfo.Floor);
  338. SetLayerDataFromList(AutoMiddleLayer, tileInfo.Middle);
  339. SetLayerDataFromList(AutoTopLayer, tileInfo.Top);
  340. //导航网格数据
  341. _dungeonTileMap.SetPolygonData(tileInfo.NavigationList);
  342. }
  343.  
  344. private void InitLayer()
  345. {
  346. if (_initLayer)
  347. {
  348. return;
  349. }
  350.  
  351. _initLayer = true;
  352. //初始化层级数据
  353. AddLayer(CustomFloorLayer);
  354. SetLayerZIndex(CustomFloorLayer, CustomFloorLayer);
  355. AddLayer(AutoMiddleLayer);
  356. SetLayerZIndex(AutoMiddleLayer, AutoMiddleLayer);
  357. AddLayer(CustomMiddleLayer);
  358. SetLayerZIndex(CustomMiddleLayer, CustomMiddleLayer);
  359. AddLayer(AutoTopLayer);
  360. SetLayerZIndex(AutoTopLayer, AutoTopLayer);
  361. AddLayer(CustomTopLayer);
  362. SetLayerZIndex(CustomTopLayer, CustomTopLayer);
  363.  
  364. _dungeonTileMap = new DungeonTileMap(this);
  365. _dungeonTileMap.SetFloorAtlasCoords(new List<Vector2I>(new []{ _autoTileConfig.Floor.AutoTileCoord }));
  366. }
  367.  
  368. //缩小
  369. private void Shrink()
  370. {
  371. var pos = GetLocalMousePosition();
  372. var scale = Scale / 1.1f;
  373. if (scale.LengthSquared() >= 0.5f)
  374. {
  375. Scale = scale;
  376. Position += pos * 0.1f * scale;
  377. }
  378. else
  379. {
  380. GD.Print("太小了");
  381. }
  382. }
  383. //放大
  384. private void Magnify()
  385. {
  386. var pos = GetLocalMousePosition();
  387. var prevScale = Scale;
  388. var scale = prevScale * 1.1f;
  389. if (scale.LengthSquared() <= 2000)
  390. {
  391. Scale = scale;
  392. Position -= pos * 0.1f * prevScale;
  393. }
  394. else
  395. {
  396. GD.Print("太大了");
  397. }
  398. }
  399.  
  400. //绘制单个自动贴图
  401. private void SetSingleAutoCell(Vector2I position)
  402. {
  403. SetCell(GetFloorLayer(), position, _sourceId, _autoTileConfig.Floor.AutoTileCoord);
  404. if (!_autoCellLayerGrid.Contains(position.X, position.Y))
  405. {
  406. ResetGenerateTimer();
  407. _autoCellLayerGrid.Set(position.X, position.Y, true);
  408. }
  409. }
  410. //绘制区域自动贴图
  411. private void SetRectAutoCell(Vector2I start, Vector2I end)
  412. {
  413. ResetGenerateTimer();
  414. if (start.X > end.X)
  415. {
  416. var temp = end.X;
  417. end.X = start.X;
  418. start.X = temp;
  419. }
  420. if (start.Y > end.Y)
  421. {
  422. var temp = end.Y;
  423. end.Y = start.Y;
  424. start.Y = temp;
  425. }
  426.  
  427. var width = end.X - start.X + 1;
  428. var height = end.Y - start.Y + 1;
  429. for (var i = 0; i < width; i++)
  430. {
  431. for (var j = 0; j < height; j++)
  432. {
  433. SetCell(GetFloorLayer(), new Vector2I(start.X + i, start.Y + j), _sourceId, _autoTileConfig.Floor.AutoTileCoord);
  434. }
  435. }
  436.  
  437. _autoCellLayerGrid.SetRect(start, new Vector2I(width, height), true);
  438. }
  439.  
  440. //擦除单个自动图块
  441. private void EraseSingleAutoCell(Vector2I position)
  442. {
  443. EraseCell(GetFloorLayer(), position);
  444. if (_autoCellLayerGrid.Remove(position.X, position.Y))
  445. {
  446. ResetGenerateTimer();
  447. }
  448. }
  449. //擦除一个区域内的自动贴图
  450. private void EraseRectAutoCell(Vector2I start, Vector2I end)
  451. {
  452. ResetGenerateTimer();
  453. if (start.X > end.X)
  454. {
  455. var temp = end.X;
  456. end.X = start.X;
  457. start.X = temp;
  458. }
  459. if (start.Y > end.Y)
  460. {
  461. var temp = end.Y;
  462. end.Y = start.Y;
  463. start.Y = temp;
  464. }
  465.  
  466. var width = end.X - start.X + 1;
  467. var height = end.Y - start.Y + 1;
  468. for (var i = 0; i < width; i++)
  469. {
  470. for (var j = 0; j < height; j++)
  471. {
  472. EraseCell(GetFloorLayer(), new Vector2I(start.X + i, start.Y + j));
  473. }
  474. }
  475. _autoCellLayerGrid.RemoveRect(start, new Vector2I(width, height));
  476. }
  477.  
  478. //重置计时器
  479. private void ResetGenerateTimer()
  480. {
  481. _generateTimer = _generateInterval;
  482. _isGenerateTerrain = false;
  483. _dungeonTileMap.ClearPolygonData();
  484. ClearLayer(AutoTopLayer);
  485. ClearLayer(AutoMiddleLayer);
  486. }
  487.  
  488. //从新计算房间区域
  489. private void CalcRect()
  490. {
  491. var rect = GetUsedRect();
  492. _roomPosition = rect.Position;
  493. _roomSize = rect.Size;
  494. }
  495. //检测是否有不合规的图块, 返回true表示图块正常
  496. private bool CheckTerrain()
  497. {
  498. var x = _roomPosition.X;
  499. var y = _roomPosition.Y;
  500. var w = _roomSize.X;
  501. var h = _roomSize.Y;
  502.  
  503. for (var i = 0; i < w; i++)
  504. {
  505. for (var j = 0; j < h; j++)
  506. {
  507. var pos = new Vector2I(x + i, y + j);
  508. if (GetCellSourceId(AutoFloorLayer, pos) == -1)
  509. {
  510. //先检测对角是否有地板
  511. var left = _autoCellLayerGrid.Get(pos.X - 1, pos.Y);
  512. var right = _autoCellLayerGrid.Get(pos.X + 1, pos.Y);
  513. var top = _autoCellLayerGrid.Get(pos.X, pos.Y + 1);
  514. var down = _autoCellLayerGrid.Get(pos.X, pos.Y - 1);
  515. if ((left && right) || (top && down))
  516. {
  517. _checkTerrainFlag = false;
  518. _checkTerrainErrorPosition = pos;
  519. return false;
  520. }
  521. }
  522. }
  523. }
  524.  
  525. _checkTerrainFlag = true;
  526. return true;
  527. }
  528. //生成自动图块 (地形)
  529. private void GenerateTerrain()
  530. {
  531. ClearLayer(AutoFloorLayer);
  532. var list = new List<Vector2I>();
  533. _autoCellLayerGrid.ForEach((x, y, data) =>
  534. {
  535. if (data)
  536. {
  537. list.Add(new Vector2I(x, y));
  538. }
  539. });
  540. var arr = new Array<Vector2I>(list);
  541. SetCellsTerrainConnect(AutoFloorLayer, arr, _terrainSet, _terrain, false);
  542. MoveTerrainCell();
  543. }
  544.  
  545. //将自动生成的图块从 AutoFloorLayer 移动到指定图层中
  546. private void MoveTerrainCell()
  547. {
  548. ClearLayer(AutoTopLayer);
  549. ClearLayer(AutoMiddleLayer);
  550. var x = _roomPosition.X;
  551. var y = _roomPosition.Y;
  552. var w = _roomSize.X;
  553. var h = _roomSize.Y;
  554.  
  555. for (var i = 0; i < w; i++)
  556. {
  557. for (var j = 0; j < h; j++)
  558. {
  559. var pos = new Vector2I(x + i, y + j);
  560. if (!_autoCellLayerGrid.Contains(pos) && GetCellSourceId(AutoFloorLayer, pos) != -1)
  561. {
  562. var atlasCoords = GetCellAtlasCoords(AutoFloorLayer, pos);
  563. var layer = _autoTileConfig.GetLayer(atlasCoords);
  564. if (layer == GameConfig.MiddleMapLayer)
  565. {
  566. layer = AutoMiddleLayer;
  567. }
  568. else if (layer == GameConfig.TopMapLayer)
  569. {
  570. layer = AutoTopLayer;
  571. }
  572. else
  573. {
  574. GD.PrintErr($"异常图块: {pos}, 这个图块的图集坐标'{atlasCoords}'不属于'MiddleMapLayer'和'TopMapLayer'!");
  575. continue;
  576. }
  577. EraseCell(AutoFloorLayer, pos);
  578. SetCell(layer, pos, _sourceId, atlasCoords);
  579. }
  580. }
  581. }
  582. }
  583.  
  584. //生成导航网格
  585. private bool GenerateNavigation()
  586. {
  587. _dungeonTileMap.GenerateNavigationPolygon(AutoFloorLayer);
  588. var result = _dungeonTileMap.GetGenerateNavigationResult();
  589. if (result.Success)
  590. {
  591. CloseErrorCell();
  592. }
  593. else
  594. {
  595. SetErrorCell(result.Exception.Point);
  596. }
  597.  
  598. return result.Success;
  599. }
  600.  
  601. //设置显示的错误cell, 会标记上红色的闪烁动画
  602. private void SetErrorCell(Vector2I pos)
  603. {
  604. MapEditorPanel.S_ErrorCell.Instance.Position = pos * CellQuadrantSize;
  605. MapEditorPanel.S_ErrorCellAnimationPlayer.Instance.Play(AnimatorNames.Show);
  606. }
  607.  
  608. //关闭显示的错误cell
  609. private void CloseErrorCell()
  610. {
  611. MapEditorPanel.S_ErrorCellAnimationPlayer.Instance.Stop();
  612. }
  613.  
  614. private int GetFloorLayer()
  615. {
  616. return AutoFloorLayer;
  617. }
  618.  
  619. private int GetMiddleLayer()
  620. {
  621. return AutoMiddleLayer;
  622. }
  623.  
  624. private int GetTopLayer()
  625. {
  626. return AutoTopLayer;
  627. }
  628.  
  629. /// <summary>
  630. /// 选中拖拽功能
  631. /// </summary>
  632. public void OnSelectHandTool()
  633. {
  634. }
  635. /// <summary>
  636. /// 选中画笔攻击
  637. /// </summary>
  638. public void OnSelectPenTool()
  639. {
  640. }
  641.  
  642. /// <summary>
  643. /// 选中绘制区域功能
  644. /// </summary>
  645. public void OnSelectRectTool()
  646. {
  647. }
  648.  
  649. /// <summary>
  650. /// 聚焦
  651. /// </summary>
  652. public void OnClickCenterTool()
  653. {
  654. Position = MapEditorPanel.S_SubViewport.Instance.Size / 2;
  655. }
  656. //保存房间配置
  657. private void SaveRoomInfoConfig()
  658. {
  659. //存入本地
  660. var path = GetConfigPath();
  661. if (!Directory.Exists(path))
  662. {
  663. Directory.CreateDirectory(path);
  664. }
  665. var roomInfo = new DungeonRoomInfo();
  666. roomInfo.Position = new SerializeVector2(_roomPosition);
  667. roomInfo.Size = new SerializeVector2(_roomSize);
  668. roomInfo.DoorAreaInfos = _doorConfigs;
  669. roomInfo.RoomType = _roomType;
  670. roomInfo.GroupName = _groupName;
  671. roomInfo.FileName = _fileName;
  672. roomInfo.Weight = _weight;
  673.  
  674. path += "/" + GetRoomInfoConfigName(_fileName);
  675. var jsonStr = JsonSerializer.Serialize(roomInfo);
  676. File.WriteAllText(path, jsonStr);
  677. }
  678.  
  679. //保存地块数据
  680. public void SaveTileInfoConfig()
  681. {
  682. //存入本地
  683. var path = GetConfigPath();
  684. if (!Directory.Exists(path))
  685. {
  686. Directory.CreateDirectory(path);
  687. }
  688. var tileInfo = new DungeonTileInfo();
  689. tileInfo.NavigationList = _dungeonTileMap.GetPolygonData().ToList();
  690. tileInfo.Floor = new List<int>();
  691. tileInfo.Middle = new List<int>();
  692. tileInfo.Top = new List<int>();
  693.  
  694. PushLayerDataToList(AutoFloorLayer, _sourceId, tileInfo.Floor);
  695. PushLayerDataToList(AutoMiddleLayer, _sourceId, tileInfo.Middle);
  696. PushLayerDataToList(AutoTopLayer, _sourceId, tileInfo.Top);
  697. path += "/" + GetTileInfoConfigName(_fileName);
  698. var jsonStr = JsonSerializer.Serialize(tileInfo);
  699. File.WriteAllText(path, jsonStr);
  700. }
  701.  
  702. public string GetConfigPath()
  703. {
  704. return GameConfig.RoomTileDir + _groupName + "/" +
  705. DungeonManager.DungeonRoomTypeToString(_roomType) + "/" + _fileName;
  706. }
  707.  
  708. public string GetTileInfoConfigName(string roomName)
  709. {
  710. return roomName + "_tileInfo.json";
  711. }
  712. public string GetRoomInfoConfigName(string roomName)
  713. {
  714. return roomName + "_roomInfo.json";
  715. }
  716. }