地格编辑器优化指示信息添加方式

main
zhangaotian 2025-03-31 14:09:11 +08:00
parent 6a76baddc7
commit 8e5977a305
3 changed files with 78 additions and 34 deletions

View File

@ -37,8 +37,7 @@ public class MapBlockData
[Serializable]
public class TerrainTypeProperty
{
[HideInInspector]
public int id;
[HideInInspector] public int id;
public string name;
public bool selectable;
public bool banAttack;
@ -50,7 +49,8 @@ public class TerrainTypeProperty
[ShowIf("AddBuff")] public EGameUnitType buffUnitType;
[ShowIf("AddBuff")] public EBlockBuffSideType buffSideType;
[HideInInspector] public string buffObjectPath;
[JsonConverter(typeof(ColorJsonConverter))]
public Color Color;
}

View File

@ -146,7 +146,7 @@ namespace MapEditor
if (CanBrushTerrainType && _map != null)
{
CanEditorAreaType = false;
CanBrushBuffCellIndex = false;
// CanBrushBuffCellIndex = false;
}
}
@ -166,7 +166,7 @@ namespace MapEditor
window.Show();
}
[BoxGroup("指示信息")]
/*[BoxGroup("指示信息")]
[LabelText("刷指示信息"), Indent]
[OnValueChanged("OnCanBrushBuffCellIndexChanged")]
[LabelWidth(100)]
@ -187,7 +187,7 @@ namespace MapEditor
[PreviewField(150, ObjectFieldAlignment.Center)]
[LabelText("指示预览图"), ShowIf("CanBrushBuffCellIndex")]
[AssetList(Path = BuffPrefabPath)]
public GameObject buffObject;
public GameObject buffObject;*/
[BoxGroup("地区信息")]
[HorizontalGroup("地区信息/Region")]
@ -203,7 +203,7 @@ namespace MapEditor
if (CanEditorAreaType)
{
CanBrushTerrainType = false;
CanBrushBuffCellIndex = false;
// CanBrushBuffCellIndex = false;
}
else
{
@ -266,13 +266,8 @@ namespace MapEditor
var buffObjCells = _map.MapData.showBuffPoints;
foreach (var cell in buffObjCells)
{
var buffObj = AssetDatabase.LoadAssetAtPath<GameObject>(cell.path);
if (buffObj == null)
{
DebugUtil.LogError("读不到指示图标: {0}", cell.path);
}
_buffPrefabDic.Add(cell.cellIndex, CreateBuffObj(cell.cellIndex, buffObj));
var buffObj = CreateBuffObj(cell.cellIndex, cell.path);
_buffPrefabDic.Add(cell.cellIndex, buffObj);
_buffPathDic.Add(cell.cellIndex, cell.path);
}
}
@ -380,7 +375,7 @@ namespace MapEditor
private void OnCellOperation(TerrainGridSystem tgs, int cellIndex, bool isOpTrue)
{
if (!CanBrushTerrainType && !CanEditorAreaType && !CanBrushBuffCellIndex)
if (!CanBrushTerrainType && !CanEditorAreaType)
{
return;
}
@ -409,15 +404,6 @@ namespace MapEditor
{
_currEditRegionArea.RemovePosition(cellIndex);
}
if (isOpTrue && CanBrushBuffCellIndex)
{
AddBuffCell(cellIndex);
}
else if (!isOpTrue && CanBrushBuffCellIndex)
{
RemoveBuffCell(cellIndex);
}
}
private void SetCellBlockType(int cellIndex, int TerrainTypeIndex)
@ -435,6 +421,12 @@ namespace MapEditor
map.SetTerrainType(cellIndex, TerrainTypeIndex);
map.TerrainGridSystem.CellToggleRegionSurface(cellIndex, true, _terrainTypeConfig[TerrainTypeIndex].Color);
var buffPath = _terrainTypeConfig[TerrainTypeIndex].buffObjectPath;
if (!string.IsNullOrEmpty(buffPath))
{
AddBuffCell(cellIndex, buffPath);
}
Debug.Log(
$"Set Territory, cellIndex ({cellIndex}), terrain type ({TerrainTypeIndex}), name ({_terrainTypeConfig[TerrainTypeIndex].Color})");
}
@ -446,6 +438,11 @@ namespace MapEditor
map.TerrainGridSystem.CellHideRegionSurface(cellIndex);
_map.SetBlockColor(cellIndex, false, _terrainTypeConfig[TerrainTypeIndex].Color);
map?.SetTerrainType(cellIndex, -1);
var buffPath = _terrainTypeConfig[TerrainTypeIndex].buffObjectPath;
if (!string.IsNullOrEmpty(buffPath))
{
RemoveBuffCell(cellIndex);
}
Debug.Log($"Cell Clear Territory, cellIndex({cellIndex})");
}
@ -487,16 +484,16 @@ namespace MapEditor
}
}
private void AddBuffCell(int cellIndex)
private void AddBuffCell(int cellIndex, string path)
{
// 阵地buff指示
if (!_buffPrefabDic.ContainsKey(cellIndex) && buffObject != null)
if (!_buffPrefabDic.ContainsKey(cellIndex))
{
var buff = CreateBuffObj(cellIndex, buffObject);
var buff = CreateBuffObj(cellIndex, path);
if (buff == null) return;
_buffPrefabDic.Add(cellIndex, buff);
var path = "Assets/" + BuffPrefabPath + "/" + buffObject.name + ".prefab";
_buffPathDic.Add(cellIndex, path);
DebugUtil.Log("格子{0}添加指示图标,路径为{1}", cellIndex, path);
DebugUtil.LogError("格子{0}添加指示图标,路径为{1}", cellIndex, path);
}
}
@ -516,8 +513,15 @@ namespace MapEditor
}
}
private GameObject CreateBuffObj(int cellIndex, GameObject buffObj)
private GameObject CreateBuffObj(int cellIndex, string path)
{
var buffObj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
if (buffObj == null)
{
DebugUtil.LogError($"{path} 路径下无Buff指示预制体 ");
return null;
}
var posV3 = _map.TGSCellIndex2WorldPosition(cellIndex);
var buff = Instantiate(buffObj, posV3, buffObj.transform.rotation);
buff.SetActive(true);

View File

@ -1,13 +1,44 @@
using System;
using Gameplay;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using System.Collections.Generic;
using Framework;
using UnityEditor;
using UnityEngine;
namespace MapEditor
{
public class TerrainTypeConfigWindow : OdinEditorWindow
{
[Serializable]
public class EditTerrainType
{
private const string BuffPrefabPath = "Art/Other/hud";
public TerrainTypeProperty TerrainTypeProperty;
[PreviewField(50, ObjectFieldAlignment.Center)]
[LabelText("指示预览图"), OnValueChanged("OnBuffObjectValueChanged")]
[AssetList(Path = BuffPrefabPath)]
public GameObject buffObject;
private void OnBuffObjectValueChanged()
{
if (buffObject != null)
{
TerrainTypeProperty.buffObjectPath = "Assets/" + BuffPrefabPath + "/" + buffObject.name + ".prefab";;
}
}
public EditTerrainType(TerrainTypeProperty terrainTypeProperty)
{
TerrainTypeProperty = terrainTypeProperty;
buffObject = AssetDatabase.LoadAssetAtPath<GameObject>(terrainTypeProperty.buffObjectPath);
}
}
[LabelText("编辑")]
public bool isEditing;
@ -15,14 +46,18 @@ namespace MapEditor
[LabelText("注意,只能添加,不能删除和修改顺序,会影响已经编辑好的地图数据")]
[EnableIf("isEditing")]
[TableList(AlwaysExpanded = true, DrawScrollView = false, ShowIndexLabels = true)]
public List<TerrainTypeProperty> terrainTypeProperties;
public List<EditTerrainType> terrainTypeProperties;
[EnableIf("isEditing")]
[Button("保存")]
private void Save()
{
// VersionControlSystem.Checkout(Constants.TERRAIN_TYPE_CONFIG_PATH);
TerrainTypeConfig.Save(terrainTypeProperties);
var terrainTypes = new List<TerrainTypeProperty>();
foreach (var terrainType in terrainTypeProperties)
{
terrainTypes.Add(terrainType.TerrainTypeProperty);
}
TerrainTypeConfig.Save(terrainTypes);
CustomPopUpWindow.PopUp($"保存地块属性成功");
}
@ -30,7 +65,12 @@ namespace MapEditor
protected override void OnEnable()
{
TerrainTypeConfig.Load();
terrainTypeProperties = TerrainTypeConfig.TerrainTypeProperties;
var editTerrainTypes = new List<EditTerrainType>();
foreach (var terrainType in TerrainTypeConfig.TerrainTypeProperties)
{
editTerrainTypes.Add(new EditTerrainType(terrainType));
}
terrainTypeProperties = editTerrainTypes;
base.OnEnable();
}
}