关卡编辑器支持显示多种区域颜色

main
zhangaotian 2025-12-12 19:11:47 +08:00
parent 9acafa898a
commit 22801a8829
2 changed files with 88 additions and 17 deletions

View File

@ -19,20 +19,36 @@ public partial class LevelEditorWindow
{
#region 地区显示相关
[Flags]
public enum ShowRegionType
{
/// <summary>
/// 默认显示地格
/// </summary>
[LabelText("无")] None,
[LabelText("占领区")] CaptureRegion,
[LabelText("撤退区")] RetreatRegion,
[LabelText("敌人撤退区")] EnemyRetreatRegion,
[LabelText("扛旗起点")] FlagStratRegion,
[LabelText("扛旗终点")] FlagEndRegion,
[LabelText("雷区")] MinesRegion,
[LabelText("刷怪触发区")] DefenseRegion,
[LabelText("阻挡区")] BlockRegion,
[LabelText("无")] None = 0,
[LabelText("占领区")] CaptureRegion = 1 << 0,
[LabelText("撤退区")] RetreatRegion = 1 << 1,
[LabelText("敌人撤退区")] EnemyRetreatRegion = 1 << 2,
[LabelText("扛旗起点")] FlagStratRegion = 1 << 3,
[LabelText("扛旗终点")] FlagEndRegion = 1 << 4,
[LabelText("雷区")] MinesRegion = 1 << 5,
[LabelText("刷怪触发区")] DefenseRegion = 1 << 6,
[LabelText("阻挡区")] BlockRegion = 1 << 7,
/// <summary>
/// 显示全部地区
/// </summary>
[LabelText("全部")]
All = CaptureRegion | RetreatRegion | EnemyRetreatRegion | FlagStratRegion |
FlagEndRegion | MinesRegion | DefenseRegion | BlockRegion,
}
#endregion
@ -545,6 +561,14 @@ public partial class LevelEditorWindow
allCells.Add(i);
}
if (ShowRegionTypeColors != null && ShowRegionTypeColors.Count > 0)
{
foreach (var color in ShowRegionTypeColors.Values.Distinct())
{
_curMap.SetBlocksColor(allCells, false, color);
}
}
_curMap.SetBlocksColor(allCells, false, ShowRegionColor);
}
}

View File

@ -208,11 +208,30 @@ public partial class LevelEditorWindow : OdinEditorWindow
#region 地区相关
[FoldoutGroup("地区相关")] [LabelText("显示地区颜色")] [OnValueChanged(nameof(OnShowRegionTypeChanged))]
/// <summary>
/// 每种地区对应的显示颜色
/// </summary>
private static readonly Dictionary<ShowRegionType, Color> ShowRegionTypeColors =
new Dictionary<ShowRegionType, Color>
{
{ ShowRegionType.CaptureRegion, CaptureRegionColor },
{ ShowRegionType.RetreatRegion, RetreatRegionColor },
{ ShowRegionType.EnemyRetreatRegion, Color.green },
{ ShowRegionType.FlagStratRegion, new Color(1f, 0.5f, 0f) },
{ ShowRegionType.FlagEndRegion, new Color(1f, 0.3f, 0.3f) },
{ ShowRegionType.MinesRegion, Color.black },
{ ShowRegionType.DefenseRegion, Color.magenta },
{ ShowRegionType.BlockRegion, Color.blue },
};
[FoldoutGroup("地区相关")]
[LabelText("显示地区颜色")]
[EnumToggleButtons]
[OnValueChanged(nameof(OnShowRegionTypeChanged))]
public ShowRegionType showRegionType;
/// <summary>
/// 根据当前枚举选择,高亮对应的地区格子,颜色使用 ShowRegionColor。
/// 根据当前选择的地区类型集合,高亮对应的地区格子,每种地区使用独立颜色。
/// </summary>
private void OnShowRegionTypeChanged()
{
@ -222,11 +241,43 @@ public partial class LevelEditorWindow : OdinEditorWindow
ClearShowRegionColor();
if (showRegionType == ShowRegionType.None)
{
SceneView.RepaintAll();
return;
}
var mask = showRegionType;
if (mask.HasFlag(ShowRegionType.All))
{
mask |= ShowRegionType.All;
}
foreach (var kv in ShowRegionTypeColors)
{
var type = kv.Key;
var color = kv.Value;
if (!mask.HasFlag(type))
continue;
var points = GetRegionPoints(type);
if (points == null || points.Count == 0)
continue;
_curMap.SetBlocksColor(points, true, color);
}
SceneView.RepaintAll();
}
/// <summary>
/// 按地区类型获取需要高亮的格子索引列表
/// </summary>
private List<int> GetRegionPoints(ShowRegionType type)
{
var points = new HashSet<int>();
switch (showRegionType)
switch (type)
{
case ShowRegionType.CaptureRegion:
if (captureEditorInfos != null)
@ -333,11 +384,7 @@ public partial class LevelEditorWindow : OdinEditorWindow
break;
}
if (points.Count > 0)
{
_curMap.SetBlocksColor(points.ToList(), true, ShowRegionColor);
SceneView.RepaintAll();
}
return points.ToList();
}
#region 撤离相关