2023-11-16 18:27:03 +08:00
|
|
|
|
using Gameplay;
|
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
|
using Sirenix.OdinInspector.Editor;
|
|
|
|
|
|
using Sirenix.Utilities;
|
|
|
|
|
|
using Sirenix.Utilities.Editor;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
2025-06-25 14:29:40 +08:00
|
|
|
|
using System.Linq;
|
2023-11-16 18:27:03 +08:00
|
|
|
|
using TGS;
|
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.InputSystem.EnhancedTouch;
|
2025-06-09 19:55:01 +08:00
|
|
|
|
using ObjectFieldAlignment = Sirenix.OdinInspector.ObjectFieldAlignment;
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
|
|
|
|
|
namespace MapEditor
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MapGridWindow : OdinEditorWindow
|
|
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
#region Fields And Properties
|
|
|
|
|
|
|
|
|
|
|
|
private static MapGridWindow thisWindow;
|
|
|
|
|
|
|
2025-06-25 14:45:41 +08:00
|
|
|
|
private static Dictionary<int, TerrainTypeProperty> _terrainTypeConfig;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
|
|
|
|
|
|
private MapData _currentMapData;
|
|
|
|
|
|
|
|
|
|
|
|
private MapManager _currMapManager;
|
|
|
|
|
|
|
|
|
|
|
|
private Map _map;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 刷地块信息
|
|
|
|
|
|
|
|
|
|
|
|
[BoxGroup("地块信息")]
|
|
|
|
|
|
[LabelText("刷地块"), Indent]
|
|
|
|
|
|
[OnValueChanged("OnCanBrushTerrainTypeChanged")]
|
|
|
|
|
|
[LabelWidth(100)]
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
[ShowIf("@!canEditorArea")]
|
|
|
|
|
|
private bool canBrushTerrainType;
|
|
|
|
|
|
|
|
|
|
|
|
private void OnCanBrushTerrainTypeChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (canBrushTerrainType && _map != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
canEditorArea = false;
|
|
|
|
|
|
canEditorBlockArea = false;
|
|
|
|
|
|
canEditorDefenseArea = false;
|
|
|
|
|
|
ClearBlockRegionColor();
|
|
|
|
|
|
ClearRegionColor();
|
|
|
|
|
|
ClearDefenseRegionColor();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HorizontalGroup("地块信息/Territory")]
|
|
|
|
|
|
[ValueDropdown("GetTerrainTypeProperties")]
|
|
|
|
|
|
[Indent]
|
|
|
|
|
|
[LabelText("选择地块")]
|
|
|
|
|
|
[ShowIf("canBrushTerrainType")]
|
|
|
|
|
|
public int TerrainTypeIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private static IEnumerable GetTerrainTypeProperties()
|
|
|
|
|
|
{
|
2025-06-27 17:46:23 +08:00
|
|
|
|
ValueDropdownList<int> list = new();
|
|
|
|
|
|
foreach (TerrainTypeProperty terrainTypeProperty in TerrainTypeConfig.DicTerrainTypePropertie.Values)
|
2025-05-29 12:43:26 +08:00
|
|
|
|
{
|
2025-06-27 17:46:23 +08:00
|
|
|
|
list.Add(terrainTypeProperty.name, terrainTypeProperty.id);
|
2025-05-29 12:43:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ShowIf("canBrushTerrainType")]
|
|
|
|
|
|
[HorizontalGroup("地块信息/Territory")]
|
|
|
|
|
|
[Button(SdfIconType.GearFill, "编辑地块")]
|
|
|
|
|
|
public void EditTerrainTypeConfig()
|
|
|
|
|
|
{
|
|
|
|
|
|
var window = GetWindow<TerrainTypeConfigWindow>();
|
|
|
|
|
|
window.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetCellBlockType(int cellIndex, int TerrainTypeIndex)
|
|
|
|
|
|
{
|
2025-06-25 14:45:41 +08:00
|
|
|
|
if (!_terrainTypeConfig.TryGetValue(TerrainTypeIndex, out TerrainTypeProperty terrainTypeProperty))
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"没有取到地格属性,id:{TerrainTypeIndex}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
var map = _map;
|
|
|
|
|
|
// Key: TerrainTypeIndex Value: tgs.territories.index
|
|
|
|
|
|
if (!map.TerrainTypeIndexDic.ContainsKey(TerrainTypeIndex))
|
|
|
|
|
|
map.TerrainTypeIndexDic.Add(TerrainTypeIndex, map.TerrainTypeIndexDic.Count);
|
|
|
|
|
|
|
2025-06-25 14:46:57 +08:00
|
|
|
|
map.TerrainGridSystem.CellSetBorderVisible(cellIndex, false);
|
2025-05-29 12:43:26 +08:00
|
|
|
|
|
|
|
|
|
|
map.SetTerrainType(cellIndex, TerrainTypeIndex);
|
2025-06-25 14:45:41 +08:00
|
|
|
|
map.TerrainGridSystem.CellToggleRegionSurface(cellIndex, true, terrainTypeProperty.Color);
|
|
|
|
|
|
var buffPath = terrainTypeProperty.buffObjectPath;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(buffPath))
|
|
|
|
|
|
AddBuffCell(cellIndex, buffPath);
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log(
|
2025-06-25 14:45:41 +08:00
|
|
|
|
$"Set Territory, cellIndex ({cellIndex}), terrain type ({TerrainTypeIndex}), name ({terrainTypeProperty.Color})");
|
2025-05-29 12:43:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ClearCellBlockType(int cellIndex)
|
|
|
|
|
|
{
|
2025-06-25 14:45:41 +08:00
|
|
|
|
if (!_terrainTypeConfig.TryGetValue(TerrainTypeIndex, out TerrainTypeProperty terrainTypeProperty))
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"没有取到地格属性,id:{TerrainTypeIndex}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
var map = _map;
|
|
|
|
|
|
map.TerrainGridSystem.CellSetBorderVisible(cellIndex, true);
|
|
|
|
|
|
map.TerrainGridSystem.CellHideRegionSurface(cellIndex);
|
2025-06-25 14:45:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_map.SetBlockColor(cellIndex, false, terrainTypeProperty.Color);
|
2025-05-29 12:43:26 +08:00
|
|
|
|
map?.SetTerrainType(cellIndex, -1);
|
2025-06-25 14:45:41 +08:00
|
|
|
|
var buffPath = terrainTypeProperty.buffObjectPath;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(buffPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
RemoveBuffCell(cellIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"Cell Clear Territory, cellIndex({cellIndex})");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 地块指示物
|
|
|
|
|
|
|
|
|
|
|
|
private Dictionary<int, GameObject> _buffPrefabDic;
|
|
|
|
|
|
|
|
|
|
|
|
private GameObject buffRoot;
|
|
|
|
|
|
|
|
|
|
|
|
private void AddBuffCell(int cellIndex, string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 阵地buff指示
|
|
|
|
|
|
if (!_buffPrefabDic.ContainsKey(cellIndex))
|
|
|
|
|
|
{
|
|
|
|
|
|
var buff = CreateBuffObj(cellIndex, path);
|
|
|
|
|
|
if (buff == null) return;
|
|
|
|
|
|
_buffPrefabDic.Add(cellIndex, buff);
|
|
|
|
|
|
DebugUtil.Log("格子{0}添加指示图标,路径为{1}", cellIndex, path);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RemoveBuffCell(int cellIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_buffPrefabDic.TryGetValue(cellIndex, out var buff))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (buff != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DestroyImmediate(buff);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_buffPrefabDic.Remove(cellIndex);
|
|
|
|
|
|
|
|
|
|
|
|
DebugUtil.Log("格子{0}移除指示图标", cellIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private GameObject CreateBuffObj(int cellIndex, string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
var buffObj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
|
|
|
|
|
if (buffObj == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"{path} 路径下无Buff指示预制体 ");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (buffRoot == null)
|
|
|
|
|
|
buffRoot = new GameObject("buffRoot");
|
|
|
|
|
|
var posV3 = _map.TGSCellIndex2WorldPosition(cellIndex);
|
|
|
|
|
|
var buff = Instantiate(buffObj, posV3, buffObj.transform.rotation, buffRoot.transform);
|
|
|
|
|
|
buff.SetActive(true);
|
|
|
|
|
|
|
|
|
|
|
|
return buff;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 地区信息
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Color regionColor = MapUtils.GetRGBAColor("FF960072");
|
|
|
|
|
|
|
|
|
|
|
|
private static bool canEditorSingleRegion = false;
|
|
|
|
|
|
|
|
|
|
|
|
private RegionArea _currEditRegionArea;
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
2023-11-17 18:16:53 +08:00
|
|
|
|
public class RegionArea
|
|
|
|
|
|
{
|
2024-10-09 13:38:54 +08:00
|
|
|
|
[HorizontalGroup("1")] [ReadOnly] public int id;
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
2024-10-09 13:38:54 +08:00
|
|
|
|
[HorizontalGroup("1")] [ReadOnly] [LabelText("数量")]
|
2023-11-17 18:16:53 +08:00
|
|
|
|
public int regionCount;
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
2025-06-12 12:41:07 +08:00
|
|
|
|
[LabelText("备注"), HorizontalGroup("1")] [OnValueChanged("OnNoteValueChanged")]
|
|
|
|
|
|
public string note;
|
|
|
|
|
|
|
|
|
|
|
|
private void OnNoteValueChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
_region.note = note;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-19 14:01:26 +08:00
|
|
|
|
public List<int> positions => _region.positions;
|
|
|
|
|
|
|
|
|
|
|
|
private MapData.Region _region;
|
|
|
|
|
|
|
|
|
|
|
|
public RegionArea(MapData.Region region)
|
|
|
|
|
|
{
|
|
|
|
|
|
_region = region;
|
2025-06-12 12:41:07 +08:00
|
|
|
|
note = _region.note;
|
2023-11-19 14:01:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Button("编辑"), HorizontalGroup("1")]
|
2023-11-17 18:16:53 +08:00
|
|
|
|
private void EditorRegion()
|
|
|
|
|
|
{
|
|
|
|
|
|
var map = thisWindow._map;
|
2023-11-19 14:01:26 +08:00
|
|
|
|
thisWindow._currEditRegionArea = this;
|
|
|
|
|
|
var regionslist = map.MapData.regions;
|
2023-11-17 18:16:53 +08:00
|
|
|
|
for (int i = 0; i < regionslist.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.SetRegionColor(i, false, regionColor);
|
|
|
|
|
|
}
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
|
|
|
|
|
map.SetRegionColor(_region, true, regionColor);
|
2025-05-28 14:50:34 +08:00
|
|
|
|
canEditorSingleRegion = true;
|
2023-11-17 18:16:53 +08:00
|
|
|
|
}
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
2025-06-12 12:41:07 +08:00
|
|
|
|
|
2023-11-19 14:01:26 +08:00
|
|
|
|
public void AddPosition(int cellIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (positions.Contains(cellIndex))
|
|
|
|
|
|
return;
|
|
|
|
|
|
positions.Add(cellIndex);
|
|
|
|
|
|
regionCount++;
|
|
|
|
|
|
thisWindow._map.TerrainGridSystem.CellToggleRegionSurface(cellIndex, true, regionColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemovePosition(int cellIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!positions.Contains(cellIndex))
|
|
|
|
|
|
return;
|
|
|
|
|
|
positions.Remove(cellIndex);
|
|
|
|
|
|
regionCount--;
|
|
|
|
|
|
thisWindow._map.TerrainGridSystem.CellHideRegionSurface(cellIndex);
|
|
|
|
|
|
}
|
2023-11-17 18:16:53 +08:00
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[BoxGroup("地区信息")]
|
|
|
|
|
|
[HorizontalGroup("地区信息/Region")]
|
|
|
|
|
|
[LabelText("编辑地区"), Indent]
|
|
|
|
|
|
[OnValueChanged("OnCanEditorAreaTypeChanged")]
|
|
|
|
|
|
[LabelWidth(100)]
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private bool canEditorArea;
|
|
|
|
|
|
|
|
|
|
|
|
private void OnCanEditorAreaTypeChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (canEditorArea)
|
|
|
|
|
|
{
|
|
|
|
|
|
canBrushTerrainType = false;
|
|
|
|
|
|
canEditorBlockArea = false;
|
|
|
|
|
|
canEditorDefenseArea = false;
|
2025-06-04 15:24:42 +08:00
|
|
|
|
canEditorSingleBlockRegion = false;
|
|
|
|
|
|
canEditorSingleDefenseRegion = false;
|
|
|
|
|
|
ClearDefenseRegionColor();
|
|
|
|
|
|
ClearBlockRegionColor();
|
2025-05-29 12:43:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearRegionColor();
|
|
|
|
|
|
SceneView.RepaintAll();
|
|
|
|
|
|
canEditorSingleRegion = false;
|
2025-06-04 15:24:42 +08:00
|
|
|
|
_currEditRegionArea = null;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[LabelText("地区列表")]
|
|
|
|
|
|
[ShowIf("canEditorArea")]
|
|
|
|
|
|
[VerticalGroup("地区信息/RegionInfo"), Indent]
|
|
|
|
|
|
[ListDrawerSettings(CustomAddFunction = "CustomAddRegion", CustomRemoveIndexFunction = "CustomRemoveRegion",
|
|
|
|
|
|
DraggableItems = false)]
|
|
|
|
|
|
public List<RegionArea> RegionList = new();
|
|
|
|
|
|
|
|
|
|
|
|
private void CustomAddRegion()
|
|
|
|
|
|
{
|
|
|
|
|
|
var region = new MapData.Region();
|
|
|
|
|
|
_currentMapData.regions.Add(region);
|
|
|
|
|
|
UpdateRegion();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CustomRemoveRegion(int index)
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearRegionColor();
|
|
|
|
|
|
_currentMapData.regions.RemoveAt(index);
|
|
|
|
|
|
UpdateRegion();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateRegion()
|
|
|
|
|
|
{
|
|
|
|
|
|
RegionList.Clear();
|
|
|
|
|
|
if (_currentMapData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
foreach (var region in _currentMapData.regions)
|
|
|
|
|
|
{
|
|
|
|
|
|
RegionArea ra = new RegionArea(region);
|
|
|
|
|
|
ra.id = index;
|
|
|
|
|
|
ra.regionCount = ra.positions.Count;
|
|
|
|
|
|
RegionList.Add(ra);
|
|
|
|
|
|
index++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ClearRegionColor()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_map == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
for (int i = 0; i < _map.MapData.regions.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
_map.SetRegionColor(i, false, regionColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 阻挡区信息
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly Color BlockRegionColor = Color.blue;
|
|
|
|
|
|
|
|
|
|
|
|
private BlockRegionArea _currEditBlockRegion;
|
|
|
|
|
|
|
|
|
|
|
|
private static bool canEditorSingleBlockRegion = false;
|
|
|
|
|
|
|
2025-06-09 19:55:01 +08:00
|
|
|
|
private Dictionary<int, GameObject> _blockPrefabDic;
|
|
|
|
|
|
|
|
|
|
|
|
private GameObject blockRoot;
|
|
|
|
|
|
|
2025-05-28 14:50:34 +08:00
|
|
|
|
[Serializable]
|
|
|
|
|
|
public class BlockRegionArea
|
|
|
|
|
|
{
|
2025-06-09 19:55:01 +08:00
|
|
|
|
private const string BuffPrefabPath = "Art_Out/Other/BuffPoint";
|
|
|
|
|
|
|
2025-05-28 14:50:34 +08:00
|
|
|
|
[HorizontalGroup("1")] [ReadOnly] public int id;
|
|
|
|
|
|
|
|
|
|
|
|
[HorizontalGroup("1")] [ReadOnly] [LabelText("数量")]
|
|
|
|
|
|
public int regionCount;
|
2025-06-12 12:41:07 +08:00
|
|
|
|
|
|
|
|
|
|
[LabelText("备注"), HorizontalGroup("1")] [OnValueChanged("OnNoteValueChanged")]
|
|
|
|
|
|
public string note;
|
|
|
|
|
|
|
|
|
|
|
|
private void OnNoteValueChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
_region.note = note;
|
|
|
|
|
|
}
|
2025-05-28 14:50:34 +08:00
|
|
|
|
|
|
|
|
|
|
[Button("编辑"), HorizontalGroup("1")]
|
|
|
|
|
|
private void EditorRegion()
|
|
|
|
|
|
{
|
|
|
|
|
|
var map = thisWindow._map;
|
|
|
|
|
|
thisWindow._currEditBlockRegion = this;
|
|
|
|
|
|
var regionsList = map.MapData.blockRegions;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
foreach (var blockRegion in regionsList)
|
2025-05-28 14:50:34 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
map.SetBlocksColor(blockRegion.positions, false, BlockRegionColor);
|
2025-05-28 14:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
map.SetBlocksColor(_region.positions, true, BlockRegionColor);
|
2025-05-28 14:50:34 +08:00
|
|
|
|
canEditorSingleBlockRegion = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-09 19:55:01 +08:00
|
|
|
|
|
|
|
|
|
|
[HorizontalGroup("3")]
|
|
|
|
|
|
[PreviewField(50, ObjectFieldAlignment.Center)]
|
|
|
|
|
|
[LabelText("指示预览图"), OnValueChanged("OnObjectValueChanged")]
|
|
|
|
|
|
[AssetList(Path = BuffPrefabPath)]
|
|
|
|
|
|
public GameObject buffObject;
|
|
|
|
|
|
|
|
|
|
|
|
private void OnObjectValueChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (buffObject != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_region.path = "Assets/" + BuffPrefabPath + "/" + buffObject.name + ".prefab";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[HorizontalGroup("2")] [LabelText("指示位置"), OnValueChanged("OnPosValueChanged")]
|
|
|
|
|
|
public Vector3 pos = Vector3.zero;
|
|
|
|
|
|
|
|
|
|
|
|
private void OnPosValueChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
_region.centerPos = pos;
|
|
|
|
|
|
if (obj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
obj.transform.position = pos;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Button("添加至场景"), HorizontalGroup("3")]
|
|
|
|
|
|
[ShowIf("NeedAdd")]
|
|
|
|
|
|
private void AddToScene()
|
|
|
|
|
|
{
|
|
|
|
|
|
obj = thisWindow.CreateBlockObj(_region.path, pos);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Button("更换指示"), HorizontalGroup("3")]
|
|
|
|
|
|
[HideIf("NeedAdd")]
|
|
|
|
|
|
private void ChangeObj()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (obj) DestroyImmediate(obj);
|
|
|
|
|
|
obj = thisWindow.CreateBlockObj(_region.path, pos);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool NeedAdd => obj == null;
|
|
|
|
|
|
[HideInInspector] public GameObject obj;
|
|
|
|
|
|
|
|
|
|
|
|
public List<int> Positions => _region.positions;
|
|
|
|
|
|
|
|
|
|
|
|
[HideInInspector] public MapData.BlockRegion _region;
|
|
|
|
|
|
|
|
|
|
|
|
public BlockRegionArea(MapData.BlockRegion region)
|
2025-05-29 12:43:26 +08:00
|
|
|
|
{
|
2025-06-09 19:55:01 +08:00
|
|
|
|
_region = region;
|
|
|
|
|
|
pos = _region.centerPos;
|
2025-06-12 12:41:07 +08:00
|
|
|
|
note = _region.note;
|
2025-06-09 19:55:01 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(region.path))
|
|
|
|
|
|
{
|
|
|
|
|
|
obj = thisWindow.CreateBlockObj(_region.path, _region.centerPos);
|
|
|
|
|
|
buffObject = AssetDatabase.LoadAssetAtPath<GameObject>(_region.path);
|
|
|
|
|
|
}
|
2025-05-29 12:43:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-28 14:50:34 +08:00
|
|
|
|
public void AddPosition(int cellIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Positions.Contains(cellIndex))
|
|
|
|
|
|
return;
|
|
|
|
|
|
Positions.Add(cellIndex);
|
|
|
|
|
|
DebugUtil.Log($"{id}阻挡区添加地格{cellIndex}");
|
|
|
|
|
|
regionCount++;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
thisWindow._map.TerrainGridSystem.CellToggleRegionSurface(cellIndex, true, BlockRegionColor);
|
2025-05-28 14:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemovePosition(int cellIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Positions.Contains(cellIndex))
|
|
|
|
|
|
return;
|
|
|
|
|
|
Positions.Remove(cellIndex);
|
2025-05-29 12:43:26 +08:00
|
|
|
|
|
2025-05-28 14:50:34 +08:00
|
|
|
|
DebugUtil.Log($"{id}阻挡区移除地格{cellIndex}");
|
|
|
|
|
|
regionCount--;
|
|
|
|
|
|
thisWindow._map.TerrainGridSystem.CellHideRegionSurface(cellIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[BoxGroup("阻挡区信息")]
|
|
|
|
|
|
[HorizontalGroup("阻挡区信息/Region")]
|
|
|
|
|
|
[LabelText("编辑阻挡区"), Indent]
|
|
|
|
|
|
[OnValueChanged("OnCanEditorBlockAreaChanged")]
|
|
|
|
|
|
[LabelWidth(100)]
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
|
private bool canEditorBlockArea;
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private void OnCanEditorBlockAreaChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (canEditorBlockArea)
|
|
|
|
|
|
{
|
|
|
|
|
|
canEditorArea = false;
|
|
|
|
|
|
canBrushTerrainType = false;
|
|
|
|
|
|
canEditorDefenseArea = false;
|
2025-06-04 15:24:42 +08:00
|
|
|
|
canEditorSingleRegion = false;
|
|
|
|
|
|
canEditorSingleDefenseRegion = false;
|
|
|
|
|
|
ClearDefenseRegionColor();
|
|
|
|
|
|
ClearRegionColor();
|
2025-05-29 12:43:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearBlockRegionColor();
|
|
|
|
|
|
SceneView.RepaintAll();
|
2025-06-04 15:24:42 +08:00
|
|
|
|
_currEditBlockRegion = null;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
canEditorSingleBlockRegion = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[LabelText("阻挡区列表")]
|
|
|
|
|
|
[ShowIf("canEditorBlockArea")]
|
|
|
|
|
|
[VerticalGroup("阻挡区信息/RegionInfo"), Indent]
|
|
|
|
|
|
[ListDrawerSettings(CustomAddFunction = "CustomAddBlockRegion",
|
2025-06-09 19:55:01 +08:00
|
|
|
|
CustomRemoveIndexFunction = "CustomRemoveBlockRegionIndex",
|
2025-05-29 12:43:26 +08:00
|
|
|
|
DraggableItems = false)]
|
|
|
|
|
|
public List<BlockRegionArea> blockRegionList = new();
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private void CustomAddBlockRegion()
|
|
|
|
|
|
{
|
|
|
|
|
|
var region = new MapData.BlockRegion();
|
|
|
|
|
|
_currentMapData.blockRegions.Add(region);
|
|
|
|
|
|
UpdateBlockRegion();
|
|
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-06-09 19:55:01 +08:00
|
|
|
|
private void CustomRemoveBlockRegionIndex(int index)
|
2025-05-29 12:43:26 +08:00
|
|
|
|
{
|
2025-06-09 19:55:01 +08:00
|
|
|
|
if (index < blockRegionList.Count)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (blockRegionList[index].obj != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"删除{blockRegionList[index].id}的指示");
|
|
|
|
|
|
DestroyImmediate(blockRegionList[index].obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
ClearBlockRegionColor();
|
|
|
|
|
|
_currentMapData.blockRegions.RemoveAt(index);
|
|
|
|
|
|
UpdateBlockRegion();
|
|
|
|
|
|
}
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private void UpdateBlockRegion()
|
|
|
|
|
|
{
|
|
|
|
|
|
blockRegionList.Clear();
|
|
|
|
|
|
if (_currentMapData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var index = 0;
|
|
|
|
|
|
foreach (var region in _currentMapData.blockRegions)
|
|
|
|
|
|
{
|
|
|
|
|
|
var blockRegion = new BlockRegionArea(region)
|
|
|
|
|
|
{
|
|
|
|
|
|
id = index,
|
|
|
|
|
|
regionCount = region.positions.Count,
|
|
|
|
|
|
};
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
blockRegionList.Add(blockRegion);
|
|
|
|
|
|
index++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private void ClearBlockRegionColor()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_map == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
foreach (var blockRegion in _map.MapData.blockRegions)
|
|
|
|
|
|
{
|
|
|
|
|
|
_map.SetBlocksColor(blockRegion.positions, false, BlockRegionColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-06-09 19:55:01 +08:00
|
|
|
|
private GameObject CreateBlockObj(string path, Vector3 pos)
|
|
|
|
|
|
{
|
|
|
|
|
|
var blockObj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
|
|
|
|
|
if (blockObj == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"{path} 路径下无Block指示预制体 ");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (blockRoot == null)
|
|
|
|
|
|
blockRoot = new GameObject("BlockRoot");
|
|
|
|
|
|
var obj = Instantiate(blockObj, pos, blockObj.transform.rotation, blockRoot.transform);
|
|
|
|
|
|
obj.SetActive(true);
|
|
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DestroyAllBlockObj()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (blockRoot)
|
|
|
|
|
|
DestroyImmediate(blockRoot);
|
|
|
|
|
|
foreach (var blockRegion in blockRegionList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (blockRegion.obj)
|
|
|
|
|
|
DestroyImmediate(blockRegion.obj);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
#endregion
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
#region 防守区信息
|
2025-05-28 14:50:34 +08:00
|
|
|
|
|
2025-06-04 15:24:42 +08:00
|
|
|
|
private static readonly Color DefenseRegionColor = Color.magenta;
|
2023-11-19 22:57:17 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private DefenseRegionArea _currEditDefenseRegion;
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private static bool canEditorSingleDefenseRegion = false;
|
2024-10-09 13:38:54 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[Serializable]
|
|
|
|
|
|
public class DefenseRegionArea
|
|
|
|
|
|
{
|
|
|
|
|
|
[HorizontalGroup("1")] [ReadOnly] public int id;
|
2025-04-02 16:04:07 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[HorizontalGroup("1")] [ReadOnly] [LabelText("数量")]
|
|
|
|
|
|
public int regionCount;
|
2025-06-12 12:41:07 +08:00
|
|
|
|
|
|
|
|
|
|
[LabelText("备注"), HorizontalGroup("1")] [OnValueChanged("OnNoteValueChanged")]
|
|
|
|
|
|
public string note;
|
|
|
|
|
|
|
|
|
|
|
|
private void OnNoteValueChanged()
|
|
|
|
|
|
{
|
|
|
|
|
|
_region.note = note;
|
|
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
public List<int> Positions => _region.positions;
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private MapData.Region _region;
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
public DefenseRegionArea(MapData.Region region)
|
2023-11-21 15:04:56 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
_region = region;
|
2025-06-12 12:41:07 +08:00
|
|
|
|
note = _region.note;
|
2024-10-09 13:38:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[Button("编辑"), HorizontalGroup("1")]
|
|
|
|
|
|
private void EditorRegion()
|
|
|
|
|
|
{
|
|
|
|
|
|
var map = thisWindow._map;
|
|
|
|
|
|
thisWindow._currEditDefenseRegion = this;
|
|
|
|
|
|
var regionsList = map.MapData.defenseRegions;
|
|
|
|
|
|
foreach (var defenseRegion in regionsList)
|
|
|
|
|
|
{
|
|
|
|
|
|
map.SetBlocksColor(defenseRegion.positions, false, DefenseRegionColor);
|
|
|
|
|
|
}
|
2025-05-28 14:50:34 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
map.SetBlocksColor(_region.positions, true, DefenseRegionColor);
|
|
|
|
|
|
canEditorSingleDefenseRegion = true;
|
|
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
public void AddPosition(int cellIndex)
|
2023-11-16 18:27:03 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
if (Positions.Contains(cellIndex))
|
|
|
|
|
|
return;
|
|
|
|
|
|
Positions.Add(cellIndex);
|
|
|
|
|
|
DebugUtil.Log($"{id}防守区添加地格{cellIndex}");
|
|
|
|
|
|
regionCount++;
|
|
|
|
|
|
thisWindow._map.TerrainGridSystem.CellToggleRegionSurface(cellIndex, true, DefenseRegionColor);
|
2023-11-16 18:27:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
public void RemovePosition(int cellIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Positions.Contains(cellIndex))
|
|
|
|
|
|
return;
|
|
|
|
|
|
Positions.Remove(cellIndex);
|
2024-10-09 14:18:50 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
DebugUtil.Log($"{id}防守区移除地格{cellIndex}");
|
|
|
|
|
|
regionCount--;
|
|
|
|
|
|
thisWindow._map.TerrainGridSystem.CellHideRegionSurface(cellIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-09 15:07:23 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[BoxGroup("防守区信息")]
|
|
|
|
|
|
[HorizontalGroup("防守区信息/Region")]
|
|
|
|
|
|
[LabelText("编辑防守区"), Indent]
|
|
|
|
|
|
[OnValueChanged("OnCanEditorDefenseAreaChanged")]
|
2023-11-16 18:27:03 +08:00
|
|
|
|
[LabelWidth(100)]
|
|
|
|
|
|
[SerializeField]
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private bool canEditorDefenseArea;
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private void OnCanEditorDefenseAreaChanged()
|
2023-11-16 18:27:03 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
if (canEditorDefenseArea)
|
2023-11-16 18:27:03 +08:00
|
|
|
|
{
|
2025-05-28 14:50:34 +08:00
|
|
|
|
canEditorBlockArea = false;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
canEditorArea = false;
|
|
|
|
|
|
canBrushTerrainType = false;
|
2025-06-04 15:24:42 +08:00
|
|
|
|
canEditorSingleRegion = false;
|
|
|
|
|
|
canEditorSingleBlockRegion = false;
|
|
|
|
|
|
ClearBlockRegionColor();
|
|
|
|
|
|
ClearRegionColor();
|
2023-11-16 18:27:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
ClearDefenseRegionColor();
|
2023-11-19 23:41:18 +08:00
|
|
|
|
SceneView.RepaintAll();
|
2025-06-04 15:24:42 +08:00
|
|
|
|
_currEditDefenseRegion = null;
|
2025-05-29 12:43:26 +08:00
|
|
|
|
canEditorSingleDefenseRegion = false;
|
2023-11-16 18:27:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[LabelText("防守区列表")]
|
|
|
|
|
|
[ShowIf("canEditorDefenseArea")]
|
|
|
|
|
|
[VerticalGroup("防守区信息/RegionInfo"), Indent]
|
|
|
|
|
|
[ListDrawerSettings(CustomAddFunction = "CustomAddDefenseRegion",
|
|
|
|
|
|
CustomRemoveIndexFunction = "CustomRemoveDefenseRegion",
|
2023-11-19 22:57:17 +08:00
|
|
|
|
DraggableItems = false)]
|
2025-05-29 12:43:26 +08:00
|
|
|
|
public List<DefenseRegionArea> defenseRegionList = new();
|
2023-11-19 14:01:26 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private void CustomAddDefenseRegion()
|
2023-11-19 14:01:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
var region = new MapData.Region();
|
2025-05-29 12:43:26 +08:00
|
|
|
|
_currentMapData.defenseRegions.Add(region);
|
|
|
|
|
|
UpdateDefenseRegion();
|
2023-11-19 14:01:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private void CustomRemoveDefenseRegion(int index)
|
2023-11-19 14:01:26 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
ClearDefenseRegionColor();
|
|
|
|
|
|
_currentMapData.defenseRegions.RemoveAt(index);
|
|
|
|
|
|
UpdateDefenseRegion();
|
2023-11-19 14:01:26 +08:00
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
private void UpdateDefenseRegion()
|
2025-05-28 14:50:34 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
defenseRegionList.Clear();
|
|
|
|
|
|
if (_currentMapData != null)
|
2025-05-28 14:50:34 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
var index = 0;
|
|
|
|
|
|
foreach (var region in _currentMapData.defenseRegions)
|
|
|
|
|
|
{
|
|
|
|
|
|
var defenseRegion = new DefenseRegionArea(region)
|
|
|
|
|
|
{
|
|
|
|
|
|
id = index,
|
|
|
|
|
|
regionCount = region.positions.Count,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
defenseRegionList.Add(defenseRegion);
|
|
|
|
|
|
index++;
|
|
|
|
|
|
}
|
2025-05-28 14:50:34 +08:00
|
|
|
|
}
|
2025-05-29 12:43:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ClearDefenseRegionColor()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_map == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
foreach (var defenseRegion in _map.MapData.defenseRegions)
|
2025-05-28 14:50:34 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
_map.SetBlocksColor(defenseRegion.positions, false, DefenseRegionColor);
|
2025-05-28 14:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
#endregion
|
2025-05-28 14:50:34 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
#region 功能
|
|
|
|
|
|
|
|
|
|
|
|
[Button("保存")]
|
|
|
|
|
|
private void RebuildPrefab()
|
2025-05-28 14:50:34 +08:00
|
|
|
|
{
|
2025-06-09 19:55:01 +08:00
|
|
|
|
foreach (var blockRegionArea in blockRegionList)
|
|
|
|
|
|
{
|
|
|
|
|
|
blockRegionArea._region.id = blockRegionArea.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
_currMapManager.SaveMapData();
|
2025-05-28 14:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
[Button("清除网格数据")]
|
|
|
|
|
|
private void ClearGridData()
|
2025-05-28 14:50:34 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
if (EditorUtility.DisplayDialog("清理网格数据", "您是否确认清理地图网格数据", "确认", "取消"))
|
|
|
|
|
|
{
|
|
|
|
|
|
_currentMapData.ClearGridData();
|
|
|
|
|
|
_map.TerrainGridSystem.TerritoryDestroyAll();
|
|
|
|
|
|
ClearRegionColor();
|
|
|
|
|
|
ClearBlockRegionColor();
|
|
|
|
|
|
ClearDefenseRegionColor();
|
|
|
|
|
|
UpdateRegion();
|
|
|
|
|
|
UpdateBlockRegion();
|
|
|
|
|
|
UpdateDefenseRegion();
|
|
|
|
|
|
_currMapManager.SaveMapData();
|
|
|
|
|
|
}
|
2025-05-28 14:50:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2023-11-16 18:27:03 +08:00
|
|
|
|
#region MainLife
|
|
|
|
|
|
|
2023-12-15 18:32:21 +08:00
|
|
|
|
public static void OpenWindow(MapManager mapSceneEditor)
|
2023-11-17 18:16:53 +08:00
|
|
|
|
{
|
|
|
|
|
|
MapEditorSettings.Init();
|
|
|
|
|
|
thisWindow = GetWindow<MapGridWindow>();
|
|
|
|
|
|
thisWindow.name = "MapGridWindow";
|
|
|
|
|
|
thisWindow.position = GUIHelper.GetEditorWindowRect().AlignCenter(800, 600);
|
2023-12-20 12:47:57 +08:00
|
|
|
|
thisWindow._currMapManager = mapSceneEditor;
|
2023-11-17 18:16:53 +08:00
|
|
|
|
thisWindow._currentMapData = null;
|
|
|
|
|
|
thisWindow.ShowTab();
|
2023-11-19 22:57:17 +08:00
|
|
|
|
thisWindow.LoadMap(mapSceneEditor.TGS, mapSceneEditor.MapData, mapSceneEditor.Map);
|
2024-10-09 13:38:54 +08:00
|
|
|
|
thisWindow.LoadBuffPrefab();
|
2023-11-19 22:57:17 +08:00
|
|
|
|
UnityEditor.Compilation.CompilationPipeline.compilationStarted += OnCompilationStart;
|
2023-11-17 18:16:53 +08:00
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2023-11-19 22:57:17 +08:00
|
|
|
|
private static void OnCompilationStart(object obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
thisWindow?.Close();
|
|
|
|
|
|
thisWindow = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-09 13:38:54 +08:00
|
|
|
|
private void LoadBuffPrefab()
|
|
|
|
|
|
{
|
|
|
|
|
|
DestroyBuffObj();
|
|
|
|
|
|
_buffPrefabDic.Clear();
|
2024-10-09 14:18:50 +08:00
|
|
|
|
var buffObjCells = _map.MapData.showBuffPoints;
|
|
|
|
|
|
foreach (var cell in buffObjCells)
|
2024-10-09 13:38:54 +08:00
|
|
|
|
{
|
2025-03-31 14:09:11 +08:00
|
|
|
|
var buffObj = CreateBuffObj(cell.cellIndex, cell.path);
|
2025-04-02 15:48:55 +08:00
|
|
|
|
_buffPrefabDic.TryAdd(cell.cellIndex, buffObj);
|
2024-10-09 13:38:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DestroyBuffObj()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_buffPrefabDic == null) return;
|
|
|
|
|
|
_buffPrefabDic.Clear();
|
2025-04-02 16:04:07 +08:00
|
|
|
|
DestroyImmediate(buffRoot);
|
|
|
|
|
|
buffRoot = null;
|
2024-10-09 13:38:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-19 22:57:17 +08:00
|
|
|
|
private void LoadMap(TerrainGridSystem tgs, MapData data, Map map)
|
2023-11-17 18:16:53 +08:00
|
|
|
|
{
|
|
|
|
|
|
_currentMapData = data;
|
2023-11-19 22:57:17 +08:00
|
|
|
|
_map = map;
|
2025-06-25 14:45:41 +08:00
|
|
|
|
_terrainTypeConfig = TerrainTypeConfig.DicTerrainTypePropertie;
|
2023-11-17 18:16:53 +08:00
|
|
|
|
_map.TerrainGridSystem.highlightEffect = HighlightEffect.Default;
|
2023-11-21 19:52:50 +08:00
|
|
|
|
tgs.OnMouseClickOnGrid += OnMouseClickCell;
|
2025-06-09 19:55:01 +08:00
|
|
|
|
DestroyAllBlockObj();
|
2023-11-19 14:01:26 +08:00
|
|
|
|
UpdateRegion();
|
2025-05-28 14:50:34 +08:00
|
|
|
|
UpdateBlockRegion();
|
2025-05-29 12:43:26 +08:00
|
|
|
|
UpdateDefenseRegion();
|
2023-11-17 18:16:53 +08:00
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2023-11-17 18:16:53 +08:00
|
|
|
|
protected override void OnEnable()
|
|
|
|
|
|
{
|
|
|
|
|
|
EnhancedTouchSupport.Enable();
|
|
|
|
|
|
TerrainTypeConfig.Load();
|
2024-10-09 13:38:54 +08:00
|
|
|
|
_buffPrefabDic = new Dictionary<int, GameObject>();
|
2025-06-09 19:55:01 +08:00
|
|
|
|
_blockPrefabDic = new Dictionary<int, GameObject>();
|
2023-11-17 18:16:53 +08:00
|
|
|
|
base.OnEnable();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnDisable()
|
|
|
|
|
|
{
|
2024-10-09 13:38:54 +08:00
|
|
|
|
DestroyBuffObj();
|
|
|
|
|
|
_buffPrefabDic = null;
|
2025-06-09 19:55:01 +08:00
|
|
|
|
_blockPrefabDic = null;
|
2023-11-17 18:16:53 +08:00
|
|
|
|
EnhancedTouchSupport.Disable();
|
|
|
|
|
|
base.OnDisable();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-20 12:25:41 +08:00
|
|
|
|
protected override void OnGUI()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnGUI();
|
2023-12-20 12:47:57 +08:00
|
|
|
|
if (_currMapManager == null || _currMapManager.MapData != _currentMapData)
|
2023-11-20 12:25:41 +08:00
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("地图数据变更,请重新点击编辑网格!");
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-19 14:01:26 +08:00
|
|
|
|
protected override void OnDestroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnDestroy();
|
2024-10-09 13:38:54 +08:00
|
|
|
|
DestroyBuffObj();
|
2025-06-09 19:55:01 +08:00
|
|
|
|
DestroyAllBlockObj();
|
2024-10-09 13:38:54 +08:00
|
|
|
|
if (_currMapManager != null)
|
2023-12-20 12:47:57 +08:00
|
|
|
|
_currMapManager.SaveMapData();
|
2023-11-20 12:25:41 +08:00
|
|
|
|
ClearRegionColor();
|
2025-05-29 12:43:26 +08:00
|
|
|
|
ClearBlockRegionColor();
|
|
|
|
|
|
ClearDefenseRegionColor();
|
2023-11-21 19:52:50 +08:00
|
|
|
|
_map.TerrainGridSystem.OnMouseClickOnGrid -= OnMouseClickCell;
|
2023-11-19 22:57:17 +08:00
|
|
|
|
UnityEditor.Compilation.CompilationPipeline.compilationStarted -= OnCompilationStart;
|
2023-11-19 14:01:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-16 18:27:03 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
#region 点击事件
|
2025-05-28 14:50:34 +08:00
|
|
|
|
|
2023-11-21 19:52:50 +08:00
|
|
|
|
private void OnMouseClickCell(TerrainGridSystem tgs, int cellIndex, int buttonIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
int leftButton = 0;
|
|
|
|
|
|
|
2024-10-09 13:38:54 +08:00
|
|
|
|
OnCellOperation(tgs, cellIndex, buttonIndex == leftButton);
|
2023-11-21 19:52:50 +08:00
|
|
|
|
}
|
2025-05-28 14:50:34 +08:00
|
|
|
|
|
2023-11-21 19:52:50 +08:00
|
|
|
|
private void OnCellOperation(TerrainGridSystem tgs, int cellIndex, bool isOpTrue)
|
2023-11-16 18:27:03 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
if (!canBrushTerrainType && !canEditorArea && !canEditorBlockArea && !canEditorDefenseArea) return;
|
2023-11-19 22:57:17 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
if (canEditorArea && _currEditRegionArea == null) return;
|
|
|
|
|
|
if (canEditorBlockArea && _currEditBlockRegion == null) return;
|
|
|
|
|
|
if (canEditorDefenseArea && _currEditDefenseRegion == null) return;
|
2023-11-16 18:27:03 +08:00
|
|
|
|
|
2025-05-28 14:50:34 +08:00
|
|
|
|
// 地块
|
|
|
|
|
|
if (isOpTrue && TerrainTypeIndex >= 0 && canBrushTerrainType)
|
2023-11-16 18:27:03 +08:00
|
|
|
|
{
|
2024-12-05 18:42:25 +08:00
|
|
|
|
SetCellBlockType(cellIndex, TerrainTypeIndex);
|
2023-11-16 18:27:03 +08:00
|
|
|
|
}
|
2025-05-28 14:50:34 +08:00
|
|
|
|
else if (!isOpTrue && canBrushTerrainType)
|
2023-11-16 18:27:03 +08:00
|
|
|
|
{
|
2023-12-21 16:07:20 +08:00
|
|
|
|
if (_currentMapData.BlocksData[cellIndex].TerrainTypeIndex == TerrainTypeIndex)
|
|
|
|
|
|
{
|
2024-12-05 18:42:25 +08:00
|
|
|
|
ClearCellBlockType(cellIndex);
|
2023-12-21 16:07:20 +08:00
|
|
|
|
}
|
2023-11-16 18:27:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-28 14:50:34 +08:00
|
|
|
|
// 普通地区
|
2025-06-04 15:24:42 +08:00
|
|
|
|
if (isOpTrue && canEditorSingleRegion && _currEditRegionArea != null)
|
2023-11-16 18:27:03 +08:00
|
|
|
|
{
|
2023-11-19 14:01:26 +08:00
|
|
|
|
_currEditRegionArea.AddPosition(cellIndex);
|
2023-11-16 18:27:03 +08:00
|
|
|
|
}
|
2025-06-04 15:24:42 +08:00
|
|
|
|
else if (!isOpTrue && canEditorSingleRegion && _currEditRegionArea != null)
|
2023-11-16 18:27:03 +08:00
|
|
|
|
{
|
2023-11-19 14:01:26 +08:00
|
|
|
|
_currEditRegionArea.RemovePosition(cellIndex);
|
2023-11-16 18:27:03 +08:00
|
|
|
|
}
|
2025-05-29 12:43:26 +08:00
|
|
|
|
|
2025-05-28 14:50:34 +08:00
|
|
|
|
// 阻挡区
|
2025-06-04 15:24:42 +08:00
|
|
|
|
if (isOpTrue && canEditorSingleBlockRegion && _currEditBlockRegion != null)
|
2025-05-28 14:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
_currEditBlockRegion.AddPosition(cellIndex);
|
|
|
|
|
|
}
|
2025-06-04 15:24:42 +08:00
|
|
|
|
else if (!isOpTrue && canEditorSingleBlockRegion && _currEditBlockRegion != null)
|
2025-05-28 14:50:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
_currEditBlockRegion.RemovePosition(cellIndex);
|
|
|
|
|
|
}
|
2024-10-09 14:18:50 +08:00
|
|
|
|
|
2025-05-29 12:43:26 +08:00
|
|
|
|
// 防守区
|
2025-06-04 15:24:42 +08:00
|
|
|
|
if (isOpTrue && canEditorSingleDefenseRegion && _currEditDefenseRegion != null)
|
2024-10-09 14:18:50 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
_currEditDefenseRegion.AddPosition(cellIndex);
|
2024-10-09 14:18:50 +08:00
|
|
|
|
}
|
2025-06-04 15:24:42 +08:00
|
|
|
|
else if (!isOpTrue && canEditorSingleDefenseRegion && _currEditDefenseRegion != null)
|
2025-03-31 14:09:11 +08:00
|
|
|
|
{
|
2025-05-29 12:43:26 +08:00
|
|
|
|
_currEditDefenseRegion.RemovePosition(cellIndex);
|
2025-03-31 14:09:11 +08:00
|
|
|
|
}
|
2024-10-09 13:38:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-16 18:27:03 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|