From 8e5977a30573558718c6880b43c54a2ca3519037 Mon Sep 17 00:00:00 2001 From: zhangaotian <8474238@qq.com> Date: Mon, 31 Mar 2025 14:09:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E6=A0=BC=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8C=87=E7=A4=BA=E4=BF=A1=E6=81=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Code/Scripts/Gameplay/Map/MapBlockData.cs | 6 +- .../Assets/Editor/MapEditor/MapGridWindow.cs | 58 ++++++++++--------- .../MapEditor/TerrainTypeConfigWindow.cs | 48 +++++++++++++-- 3 files changed, 78 insertions(+), 34 deletions(-) diff --git a/ProjectNLD/Assets/Code/Scripts/Gameplay/Map/MapBlockData.cs b/ProjectNLD/Assets/Code/Scripts/Gameplay/Map/MapBlockData.cs index f0c8938e8ab..9195985f9cf 100644 --- a/ProjectNLD/Assets/Code/Scripts/Gameplay/Map/MapBlockData.cs +++ b/ProjectNLD/Assets/Code/Scripts/Gameplay/Map/MapBlockData.cs @@ -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; - } \ No newline at end of file diff --git a/ProjectNLD/Assets/Editor/MapEditor/MapGridWindow.cs b/ProjectNLD/Assets/Editor/MapEditor/MapGridWindow.cs index 916f3a81982..fbe8af49166 100644 --- a/ProjectNLD/Assets/Editor/MapEditor/MapGridWindow.cs +++ b/ProjectNLD/Assets/Editor/MapEditor/MapGridWindow.cs @@ -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(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(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); diff --git a/ProjectNLD/Assets/Editor/MapEditor/TerrainTypeConfigWindow.cs b/ProjectNLD/Assets/Editor/MapEditor/TerrainTypeConfigWindow.cs index dfa00286a4a..6ba77cc904d 100644 --- a/ProjectNLD/Assets/Editor/MapEditor/TerrainTypeConfigWindow.cs +++ b/ProjectNLD/Assets/Editor/MapEditor/TerrainTypeConfigWindow.cs @@ -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(terrainTypeProperty.buffObjectPath); + } + } + [LabelText("编辑")] public bool isEditing; @@ -15,14 +46,18 @@ namespace MapEditor [LabelText("注意,只能添加,不能删除和修改顺序,会影响已经编辑好的地图数据")] [EnableIf("isEditing")] [TableList(AlwaysExpanded = true, DrawScrollView = false, ShowIndexLabels = true)] - public List terrainTypeProperties; + public List terrainTypeProperties; [EnableIf("isEditing")] [Button("保存")] private void Save() { - // VersionControlSystem.Checkout(Constants.TERRAIN_TYPE_CONFIG_PATH); - TerrainTypeConfig.Save(terrainTypeProperties); + var terrainTypes = new List(); + 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(); + foreach (var terrainType in TerrainTypeConfig.TerrainTypeProperties) + { + editTerrainTypes.Add(new EditTerrainType(terrainType)); + } + terrainTypeProperties = editTerrainTypes; base.OnEnable(); } }