地格编辑器优化指示信息添加方式
parent
6a76baddc7
commit
8e5977a305
|
|
@ -37,8 +37,7 @@ public class MapBlockData
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class TerrainTypeProperty
|
public class TerrainTypeProperty
|
||||||
{
|
{
|
||||||
[HideInInspector]
|
[HideInInspector] public int id;
|
||||||
public int id;
|
|
||||||
public string name;
|
public string name;
|
||||||
public bool selectable;
|
public bool selectable;
|
||||||
public bool banAttack;
|
public bool banAttack;
|
||||||
|
|
@ -50,7 +49,8 @@ public class TerrainTypeProperty
|
||||||
[ShowIf("AddBuff")] public EGameUnitType buffUnitType;
|
[ShowIf("AddBuff")] public EGameUnitType buffUnitType;
|
||||||
[ShowIf("AddBuff")] public EBlockBuffSideType buffSideType;
|
[ShowIf("AddBuff")] public EBlockBuffSideType buffSideType;
|
||||||
|
|
||||||
|
[HideInInspector] public string buffObjectPath;
|
||||||
|
|
||||||
[JsonConverter(typeof(ColorJsonConverter))]
|
[JsonConverter(typeof(ColorJsonConverter))]
|
||||||
public Color Color;
|
public Color Color;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -146,7 +146,7 @@ namespace MapEditor
|
||||||
if (CanBrushTerrainType && _map != null)
|
if (CanBrushTerrainType && _map != null)
|
||||||
{
|
{
|
||||||
CanEditorAreaType = false;
|
CanEditorAreaType = false;
|
||||||
CanBrushBuffCellIndex = false;
|
// CanBrushBuffCellIndex = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,7 +166,7 @@ namespace MapEditor
|
||||||
window.Show();
|
window.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
[BoxGroup("指示信息")]
|
/*[BoxGroup("指示信息")]
|
||||||
[LabelText("刷指示信息"), Indent]
|
[LabelText("刷指示信息"), Indent]
|
||||||
[OnValueChanged("OnCanBrushBuffCellIndexChanged")]
|
[OnValueChanged("OnCanBrushBuffCellIndexChanged")]
|
||||||
[LabelWidth(100)]
|
[LabelWidth(100)]
|
||||||
|
|
@ -187,7 +187,7 @@ namespace MapEditor
|
||||||
[PreviewField(150, ObjectFieldAlignment.Center)]
|
[PreviewField(150, ObjectFieldAlignment.Center)]
|
||||||
[LabelText("指示预览图"), ShowIf("CanBrushBuffCellIndex")]
|
[LabelText("指示预览图"), ShowIf("CanBrushBuffCellIndex")]
|
||||||
[AssetList(Path = BuffPrefabPath)]
|
[AssetList(Path = BuffPrefabPath)]
|
||||||
public GameObject buffObject;
|
public GameObject buffObject;*/
|
||||||
|
|
||||||
[BoxGroup("地区信息")]
|
[BoxGroup("地区信息")]
|
||||||
[HorizontalGroup("地区信息/Region")]
|
[HorizontalGroup("地区信息/Region")]
|
||||||
|
|
@ -203,7 +203,7 @@ namespace MapEditor
|
||||||
if (CanEditorAreaType)
|
if (CanEditorAreaType)
|
||||||
{
|
{
|
||||||
CanBrushTerrainType = false;
|
CanBrushTerrainType = false;
|
||||||
CanBrushBuffCellIndex = false;
|
// CanBrushBuffCellIndex = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -266,13 +266,8 @@ namespace MapEditor
|
||||||
var buffObjCells = _map.MapData.showBuffPoints;
|
var buffObjCells = _map.MapData.showBuffPoints;
|
||||||
foreach (var cell in buffObjCells)
|
foreach (var cell in buffObjCells)
|
||||||
{
|
{
|
||||||
var buffObj = AssetDatabase.LoadAssetAtPath<GameObject>(cell.path);
|
var buffObj = CreateBuffObj(cell.cellIndex, cell.path);
|
||||||
if (buffObj == null)
|
_buffPrefabDic.Add(cell.cellIndex, buffObj);
|
||||||
{
|
|
||||||
DebugUtil.LogError("读不到指示图标: {0}", cell.path);
|
|
||||||
}
|
|
||||||
|
|
||||||
_buffPrefabDic.Add(cell.cellIndex, CreateBuffObj(cell.cellIndex, buffObj));
|
|
||||||
_buffPathDic.Add(cell.cellIndex, cell.path);
|
_buffPathDic.Add(cell.cellIndex, cell.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -380,7 +375,7 @@ namespace MapEditor
|
||||||
|
|
||||||
private void OnCellOperation(TerrainGridSystem tgs, int cellIndex, bool isOpTrue)
|
private void OnCellOperation(TerrainGridSystem tgs, int cellIndex, bool isOpTrue)
|
||||||
{
|
{
|
||||||
if (!CanBrushTerrainType && !CanEditorAreaType && !CanBrushBuffCellIndex)
|
if (!CanBrushTerrainType && !CanEditorAreaType)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -409,15 +404,6 @@ namespace MapEditor
|
||||||
{
|
{
|
||||||
_currEditRegionArea.RemovePosition(cellIndex);
|
_currEditRegionArea.RemovePosition(cellIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOpTrue && CanBrushBuffCellIndex)
|
|
||||||
{
|
|
||||||
AddBuffCell(cellIndex);
|
|
||||||
}
|
|
||||||
else if (!isOpTrue && CanBrushBuffCellIndex)
|
|
||||||
{
|
|
||||||
RemoveBuffCell(cellIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCellBlockType(int cellIndex, int TerrainTypeIndex)
|
private void SetCellBlockType(int cellIndex, int TerrainTypeIndex)
|
||||||
|
|
@ -435,6 +421,12 @@ namespace MapEditor
|
||||||
|
|
||||||
map.SetTerrainType(cellIndex, TerrainTypeIndex);
|
map.SetTerrainType(cellIndex, TerrainTypeIndex);
|
||||||
map.TerrainGridSystem.CellToggleRegionSurface(cellIndex, true, _terrainTypeConfig[TerrainTypeIndex].Color);
|
map.TerrainGridSystem.CellToggleRegionSurface(cellIndex, true, _terrainTypeConfig[TerrainTypeIndex].Color);
|
||||||
|
var buffPath = _terrainTypeConfig[TerrainTypeIndex].buffObjectPath;
|
||||||
|
if (!string.IsNullOrEmpty(buffPath))
|
||||||
|
{
|
||||||
|
AddBuffCell(cellIndex, buffPath);
|
||||||
|
}
|
||||||
|
|
||||||
Debug.Log(
|
Debug.Log(
|
||||||
$"Set Territory, cellIndex ({cellIndex}), terrain type ({TerrainTypeIndex}), name ({_terrainTypeConfig[TerrainTypeIndex].Color})");
|
$"Set Territory, cellIndex ({cellIndex}), terrain type ({TerrainTypeIndex}), name ({_terrainTypeConfig[TerrainTypeIndex].Color})");
|
||||||
}
|
}
|
||||||
|
|
@ -446,6 +438,11 @@ namespace MapEditor
|
||||||
map.TerrainGridSystem.CellHideRegionSurface(cellIndex);
|
map.TerrainGridSystem.CellHideRegionSurface(cellIndex);
|
||||||
_map.SetBlockColor(cellIndex, false, _terrainTypeConfig[TerrainTypeIndex].Color);
|
_map.SetBlockColor(cellIndex, false, _terrainTypeConfig[TerrainTypeIndex].Color);
|
||||||
map?.SetTerrainType(cellIndex, -1);
|
map?.SetTerrainType(cellIndex, -1);
|
||||||
|
var buffPath = _terrainTypeConfig[TerrainTypeIndex].buffObjectPath;
|
||||||
|
if (!string.IsNullOrEmpty(buffPath))
|
||||||
|
{
|
||||||
|
RemoveBuffCell(cellIndex);
|
||||||
|
}
|
||||||
|
|
||||||
Debug.Log($"Cell Clear Territory, cellIndex({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指示
|
// 阵地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);
|
_buffPrefabDic.Add(cellIndex, buff);
|
||||||
var path = "Assets/" + BuffPrefabPath + "/" + buffObject.name + ".prefab";
|
|
||||||
_buffPathDic.Add(cellIndex, path);
|
_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 posV3 = _map.TGSCellIndex2WorldPosition(cellIndex);
|
||||||
var buff = Instantiate(buffObj, posV3, buffObj.transform.rotation);
|
var buff = Instantiate(buffObj, posV3, buffObj.transform.rotation);
|
||||||
buff.SetActive(true);
|
buff.SetActive(true);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,44 @@
|
||||||
|
using System;
|
||||||
using Gameplay;
|
using Gameplay;
|
||||||
using Sirenix.OdinInspector;
|
using Sirenix.OdinInspector;
|
||||||
using Sirenix.OdinInspector.Editor;
|
using Sirenix.OdinInspector.Editor;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Framework;
|
using Framework;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MapEditor
|
namespace MapEditor
|
||||||
{
|
{
|
||||||
public class TerrainTypeConfigWindow : OdinEditorWindow
|
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("编辑")]
|
[LabelText("编辑")]
|
||||||
public bool isEditing;
|
public bool isEditing;
|
||||||
|
|
||||||
|
|
@ -15,14 +46,18 @@ namespace MapEditor
|
||||||
[LabelText("注意,只能添加,不能删除和修改顺序,会影响已经编辑好的地图数据")]
|
[LabelText("注意,只能添加,不能删除和修改顺序,会影响已经编辑好的地图数据")]
|
||||||
[EnableIf("isEditing")]
|
[EnableIf("isEditing")]
|
||||||
[TableList(AlwaysExpanded = true, DrawScrollView = false, ShowIndexLabels = true)]
|
[TableList(AlwaysExpanded = true, DrawScrollView = false, ShowIndexLabels = true)]
|
||||||
public List<TerrainTypeProperty> terrainTypeProperties;
|
public List<EditTerrainType> terrainTypeProperties;
|
||||||
|
|
||||||
[EnableIf("isEditing")]
|
[EnableIf("isEditing")]
|
||||||
[Button("保存")]
|
[Button("保存")]
|
||||||
private void Save()
|
private void Save()
|
||||||
{
|
{
|
||||||
// VersionControlSystem.Checkout(Constants.TERRAIN_TYPE_CONFIG_PATH);
|
var terrainTypes = new List<TerrainTypeProperty>();
|
||||||
TerrainTypeConfig.Save(terrainTypeProperties);
|
foreach (var terrainType in terrainTypeProperties)
|
||||||
|
{
|
||||||
|
terrainTypes.Add(terrainType.TerrainTypeProperty);
|
||||||
|
}
|
||||||
|
TerrainTypeConfig.Save(terrainTypes);
|
||||||
CustomPopUpWindow.PopUp($"保存地块属性成功");
|
CustomPopUpWindow.PopUp($"保存地块属性成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,7 +65,12 @@ namespace MapEditor
|
||||||
protected override void OnEnable()
|
protected override void OnEnable()
|
||||||
{
|
{
|
||||||
TerrainTypeConfig.Load();
|
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();
|
base.OnEnable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue