NLDClient-yudde/ProjectNLD/Assets/Editor/LevelEditor/LevelEditorWindow.cs

1531 lines
48 KiB
C#
Raw Normal View History

using TGS;
using System;
2023-08-22 19:08:45 +08:00
using Gameplay;
using Framework;
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Linq;
using Gameplay.Utils;
2023-08-22 19:08:45 +08:00
using Gameplay.Level;
using Sirenix.Utilities;
using Sirenix.OdinInspector;
2023-08-22 19:08:45 +08:00
using Sirenix.Utilities.Editor;
using System.Collections.Generic;
2024-11-07 15:40:07 +08:00
using cfg;
2024-11-18 16:50:35 +08:00
using cfg.FightCfg;
using cfg.MonsterCfg;
using cfg.VehicleCfg;
using Sirenix.OdinInspector.Editor;
2024-11-18 16:50:35 +08:00
using Level = cfg.LevelCfg.Level;
2023-08-22 19:08:45 +08:00
using ObjectFieldAlignment = Sirenix.OdinInspector.ObjectFieldAlignment;
public class LevelEditorWindow : OdinEditorWindow
{
public static void OpenWindow(LevelEditor levelEditor)
{
MapEditorSettings.Init();
currWindow = GetWindow<LevelEditorWindow>();
currWindow.position = GUIHelper.GetEditorWindowRect().AlignCenter(800, 600);
currWindow.currentLevelData = null;
currWindow._levelEditor = levelEditor;
currWindow.LoadLevel(levelEditor.LevelData);
var level = Path.GetFileNameWithoutExtension(levelEditor.LevelDataJson.name);
currWindow.levelID = level.Substring(level.Length - 6);
currWindow.GetLevelMonsterClass();
DebugUtil.Log("关卡数据:{0}", currWindow.levelID);
}
#region 编辑器类
2023-08-22 19:08:45 +08:00
[Serializable]
public class RegionData
{
2024-04-02 16:53:46 +08:00
[LabelText("出战区")] [OnValueChanged("OnRegionChanged")]
public int preparingRegionId;
2024-04-02 16:53:46 +08:00
[LabelText("出战区朝向")] public LevelData.CharacterToward preparingRegionToward;
2024-04-02 16:53:46 +08:00
[LabelText("撤退区")] public int fallbackRegionId;
2024-04-02 16:53:46 +08:00
[LabelText("敌方撤退区")] public int enemyFallbackRegionId;
2024-04-02 16:53:46 +08:00
[LabelText("PVP防守区")] public int pvpDefendRegionId;
2023-12-26 18:19:05 +08:00
2024-04-02 16:53:46 +08:00
[LabelText("PVP防守方朝向")] public LevelData.CharacterToward pvpDefendToward;
2023-12-26 18:19:05 +08:00
private void OnRegionChanged()
{
var regionsList = currWindow._curMap.MapData.regions;
for (int i = 0; i < regionsList.Count; i++)
{
2024-11-18 16:50:35 +08:00
currWindow._curMap.SetRegionColor(i, false, RegionColor);
}
2023-11-21 15:04:56 +08:00
2024-11-18 16:50:35 +08:00
currWindow._curMap.SetRegionColor(preparingRegionId, true, RegionColor);
2023-12-22 15:26:48 +08:00
}
}
[Serializable]
public class NpcEditorInfo
2023-12-22 15:26:48 +08:00
{
2024-11-18 16:50:35 +08:00
[HideInInspector] public bool selfNpc;
2024-11-07 15:50:33 +08:00
[ReadOnly] [LabelText("序号ID")] public int id;
2024-11-04 18:19:57 +08:00
[LabelText("MonsterID")] [ValueDropdown("GetMonsterIDs")] [OnValueChanged("ChangeNpcID")]
public int monsterId;
2024-11-07 15:50:33 +08:00
2024-11-04 18:43:29 +08:00
private IEnumerable<int> GetMonsterIDs()
{
2024-11-18 16:50:35 +08:00
if (!selfNpc)
return currWindow.GetMonsterIDs();
return currWindow.GetSelfNpcIDs();
2024-11-04 18:43:29 +08:00
}
2024-11-04 18:19:57 +08:00
2024-11-04 18:43:29 +08:00
private void ChangeNpcID()
{
2024-11-18 16:50:35 +08:00
if (!selfNpc)
currWindow.ChangeNpcID(npcInfo, monsterId);
else
currWindow.ChangeFightNpcID(npcInfo, monsterId);
2024-11-04 18:43:29 +08:00
}
2023-12-22 15:26:48 +08:00
2024-11-04 18:43:29 +08:00
[LabelText("朝向")] [OnValueChanged("NpcTowardOnChange")]
public LevelData.CharacterToward npcToward;
2024-11-07 15:50:33 +08:00
2024-11-04 18:43:29 +08:00
private void NpcTowardOnChange()
{
npcInfo.npcToward = npcToward;
2024-11-18 16:50:35 +08:00
if (!selfNpc)
currWindow.ChangeNpcToward(npcInfo.position, npcToward);
else
currWindow.ChangeSelfNpcToward(npcInfo.position, npcToward);
2024-11-04 18:43:29 +08:00
}
[HideLabel] public LevelData.NPCInfo npcInfo;
2024-11-07 15:50:33 +08:00
2024-11-18 16:50:35 +08:00
public NpcEditorInfo(LevelData.NPCInfo npcInfo, int index, bool isSelfNpc = false)
2023-12-22 15:26:48 +08:00
{
this.npcInfo = npcInfo;
2024-11-04 18:19:57 +08:00
monsterId = npcInfo.id;
id = index;
2024-11-18 16:50:35 +08:00
selfNpc = isSelfNpc;
npcToward = this.npcInfo.npcToward;
2024-11-04 18:19:57 +08:00
}
[LabelText("位置调整")] [OnValueChanged("ChangeNpcPos")]
public bool isChangePos;
private void ChangeNpcPos()
{
if (isChangePos)
{
currWindow.isEditingPatrolInfo = false;
if (currWindow._currEditingNpcInfo != null)
2024-11-04 18:19:57 +08:00
DebugUtil.LogWarning("检查其他怪物是否处于位置调整或编辑巡逻信息状态");
}
currWindow.isEditingNpcPos = isChangePos;
currWindow._currEditingNpcInfo = isChangePos ? npcInfo : null;
2024-11-04 18:19:57 +08:00
}
[LabelText("显示该怪物序号")] [OnValueChanged("ShowNpcID")]
public bool isShowNpcID;
private void ShowNpcID()
{
if (isShowNpcID && !currWindow._showNpcInfos.Contains(this))
currWindow._showNpcInfos.Add(this);
else
{
currWindow._showNpcInfos.Remove(this);
}
2023-12-22 15:26:48 +08:00
}
2024-11-04 18:43:29 +08:00
private bool _isEditing;
2023-12-22 15:26:48 +08:00
[Button("开始编辑巡逻信息")]
[HideIf("_isEditing")]
2024-11-04 18:19:57 +08:00
private void StartEditNpc()
2023-12-22 15:26:48 +08:00
{
2024-11-04 18:19:57 +08:00
currWindow.StartEditPatrolInfo(npcInfo);
2023-12-22 15:26:48 +08:00
_isEditing = true;
}
[Button("完成编辑巡逻信息")]
[ShowIf("_isEditing")]
2024-11-04 18:19:57 +08:00
private void FinishEditNpc()
2023-12-22 15:26:48 +08:00
{
2024-11-04 18:19:57 +08:00
currWindow.FinishEditPatrolInfo();
2023-12-22 15:26:48 +08:00
_isEditing = false;
}
}
2023-08-22 19:08:45 +08:00
[Serializable]
public class CaptureEditorInfo
{
[LabelText("占领点位")] public Vector2Int capturePoint;
[LabelText("占领时间")] public int captureProgress;
}
[Serializable]
public class FlagEditorInfo
{
[LabelText("扛旗起点")] public List<Vector2Int> flagStartPoints = new();
[LabelText("扛旗终点")] public List<Vector2Int> flagEndPoints = new();
[LabelText("添加起点")] [OnValueChanged("EditingStartPoints")]
public bool isEditingStart;
[LabelText("添加终点")] [OnValueChanged("EditingEndPoints")]
public bool isEditingEnd;
private void EditingStartPoints()
{
currWindow.isEditingFlagStart = isEditingStart;
if (isEditingStart)
{
isEditingEnd = false;
currWindow.isEditingFlagEnd = false;
}
}
private void EditingEndPoints()
{
currWindow.isEditingFlagEnd = isEditingEnd;
if (isEditingEnd)
{
isEditingStart = false;
currWindow.isEditingFlagStart = false;
}
}
}
2024-11-11 13:46:47 +08:00
[Serializable]
public class FallbackEditorInfo
{
[LabelText("单次撤离点")] public List<Vector2Int> fallbackSinglePoints = new();
[LabelText("复用撤离点")] public List<Vector2Int> fallbackReusablePoints = new();
[LabelText("添加单次撤离点")] [OnValueChanged("EditingFallbackPoints")]
public bool isEditingSinglePoints;
[LabelText("添加复用撤离点")] [OnValueChanged("EditingMultiplexPoint")]
public bool isEditingReusablePoints;
private void EditingFallbackPoints()
{
currWindow.isEditingFallbackSingle = isEditingSinglePoints;
if (isEditingSinglePoints)
{
isEditingReusablePoints = false;
currWindow.isEditingFallbackReusable = false;
}
}
private void EditingMultiplexPoint()
{
currWindow.isEditingFallbackReusable = isEditingReusablePoints;
if (isEditingReusablePoints)
{
isEditingSinglePoints = false;
currWindow.isEditingFallbackSingle = false;
}
}
}
#endregion
2024-11-18 16:50:35 +08:00
#region 配置表
private Level LevelCfg => EditorTableManager.instance.tables.Level;
private Monster MonsterCfg => EditorTableManager.instance.tables.Monster;
private VehicleConfig VehicleCfg => EditorTableManager.instance.tables.VehicleConfig;
private FightNPCConfig FightNpcCfg => EditorTableManager.instance.tables.FightNPCConfig;
#endregion
2024-11-13 19:11:46 +08:00
private const int SelfID = 200;
2024-11-18 16:50:35 +08:00
private static readonly Color RegionColor = MapUtils.GetRGBAColor("FF960072");
2024-11-04 18:19:57 +08:00
private static LevelEditorWindow currWindow;
2023-11-21 15:04:56 +08:00
2023-12-18 19:42:46 +08:00
private MapManager _mapManager;
2023-12-22 15:26:48 +08:00
2024-11-04 18:19:57 +08:00
private Dictionary<Vector2Int, GameObject> _npcObjectDic;
2023-08-22 19:08:45 +08:00
2024-11-13 17:14:27 +08:00
private Dictionary<Vector2Int, GameObject> _selfNpcObjectDic;
2024-11-12 20:31:06 +08:00
private Map _curMap;
2023-10-19 15:00:19 +08:00
2023-11-21 15:04:56 +08:00
private LevelEditor _levelEditor;
2023-12-22 15:26:48 +08:00
private LevelData.NPCInfo _currEditingNpcInfo;
2023-12-22 15:26:48 +08:00
2024-11-04 18:19:57 +08:00
private bool isEditingPatrolInfo;
private bool isEditingNpcPos;
private bool isEditingFlagStart;
private bool isEditingFlagEnd;
2024-11-11 13:46:47 +08:00
private bool isEditingFallbackSingle;
private bool isEditingFallbackReusable;
private bool IsShowNpcID => _showNpcInfos != null && _showNpcInfos.Count > 0;
2024-11-04 18:19:57 +08:00
private List<NpcEditorInfo> _showNpcInfos;
2023-12-22 15:26:48 +08:00
2024-11-07 18:30:47 +08:00
private bool ResponseClickOnCell =>
2024-11-13 17:14:27 +08:00
isEditingNpc || isEditingSelfNpc || isEditingNpcPos || isEditingPatrolInfo || isEditingFlagStart ||
2024-11-13 13:21:36 +08:00
isEditingFlagEnd || isEditingCapture ||
2024-11-11 13:46:47 +08:00
isEditingFallbackReusable || isEditingFallbackSingle;
2023-12-22 15:26:48 +08:00
2024-04-02 16:53:46 +08:00
[LabelText("当前关卡数据"), Indent] [OnValueChanged("OnCurrentLevelDataChanged")]
2023-08-22 19:08:45 +08:00
public LevelData currentLevelData = null;
2023-12-22 15:26:48 +08:00
[LabelText("当前占领数据"), Indent] [ShowIf("EditorCaptureInfo")]
public List<CaptureEditorInfo> captureEditorInfo = new();
2024-11-07 18:30:47 +08:00
[LabelText("编辑占领数据"), Indent] [ShowIf("EditorCaptureInfo")]
public bool isEditingCapture = false;
private bool EditorCaptureInfo()
{
return CheckConditionSame(ConditionType.CombatLeastOccupy);
}
[LabelText("当前扛旗数据"), Indent] [ShowIf("EditorFlagInfo")]
public FlagEditorInfo flagEditorInfo = new();
private bool EditorFlagInfo()
{
return CheckConditionSame(ConditionType.CombatSubmitFlag);
}
2024-11-11 13:46:47 +08:00
[LabelText("当前撤离数据"), Indent] [ShowIf("EditorFallbackInfo")]
public FallbackEditorInfo fallbackEditorInfo = new();
private bool EditorFallbackInfo()
{
return CheckConditionSame(ConditionType.CombatFallBack);
}
2024-04-02 16:53:46 +08:00
[LabelText("当前地区数据"), Indent] [OnValueChanged("OnCurrentLevelDataChanged")]
public RegionData curRegionData = null;
2023-12-22 15:26:48 +08:00
2024-11-18 16:50:35 +08:00
[LabelText("显示索引地图"), Indent] [LabelWidth(100)] [OnValueChanged("ShowCellCoordinates")] [SerializeField]
2024-11-04 18:19:57 +08:00
public bool isShowCellCoordinates;
private void ShowCellCoordinates()
{
if (_curMap == null || _curMap.TerrainGridSystem == null) return;
2024-11-13 13:21:36 +08:00
_curMap.TerrainGridSystem.displayCellDebugInfo =
isShowCellCoordinates ? CellDebugInfo.CellCoordinates : CellDebugInfo.Nothing;
2024-11-04 18:19:57 +08:00
var obj = FindObjectOfType<TerrainGridSystem>().gameObject;
Selection.activeGameObject = obj;
}
/// <summary>
/// 关卡ID 通过关卡数据 json文件名 获得
/// </summary>
2024-11-18 16:50:35 +08:00
[LabelText("手动指定关卡ID"), Indent, LabelWidth(100), ShowIf("needManualInputLevelID")]
[OnValueChanged("GetLevelMonsterClass")]
[InfoBox("无法正确获得关卡ID请手动指定")]
2024-11-18 16:50:35 +08:00
[SerializeField]
2024-06-04 16:50:16 +08:00
public string levelID;
2024-11-13 17:14:27 +08:00
#region 敌方Npc
2024-11-12 20:31:06 +08:00
2024-11-18 16:50:35 +08:00
[LabelText("编辑NPC"), Indent] [LabelWidth(100)] [SerializeField] [OnValueChanged("OnIsEditingNpcChanged")]
public bool isEditingNpc;
[LabelText("显示所有怪物序号ID"), Indent] [OnValueChanged("ShowAllNpcId")] [SerializeField]
public bool isShowAllNpcID;
2024-11-12 20:31:06 +08:00
[LabelText("怪物ID"), Indent, LabelWidth(100)]
[SerializeField]
[OnValueChanged("MonsterIDChanged")]
[ValueDropdown("GetMonsterIDs")]
[ShowIf("isEditingNpc")]
public int curMonsterID;
[PreviewField(150, ObjectFieldAlignment.Center), Indent, ReadOnly] [LabelText("NPC预制体预览图"), ShowIf("isEditingNpc")]
public GameObject npcObject;
2023-12-21 12:48:58 +08:00
2024-11-18 16:50:35 +08:00
[LabelText("当前怪物列表"), Indent, ShowIf("isEditingNpc")]
[ListDrawerSettings(HideAddButton = true, HideRemoveButton = true)]
2024-11-12 20:31:06 +08:00
public List<NpcEditorInfo> currentNpcInfo = null;
private IEnumerable<int> GetMonsterIDs()
{
return monsterIDs;
}
2024-04-02 16:53:46 +08:00
private void MonsterIDChanged()
2023-12-21 12:48:58 +08:00
{
2024-11-04 18:19:57 +08:00
var obj = LoadNpcPrefab(curMonsterID);
if (obj != null)
npcObject = obj;
}
2023-12-21 12:48:58 +08:00
2024-11-18 16:50:35 +08:00
private void OnIsEditingNpcChanged()
{
if (isEditingNpc && isEditingSelfNpc)
isEditingSelfNpc = false;
}
2024-11-04 18:19:57 +08:00
private void ShowAllNpcId()
{
foreach (var npc in currentNpcInfo)
2024-09-05 13:26:43 +08:00
{
2024-11-04 18:19:57 +08:00
npc.isShowNpcID = isShowAllNpcID;
if (isShowAllNpcID)
2024-09-05 12:28:32 +08:00
{
2024-11-04 18:19:57 +08:00
if (!_showNpcInfos.Contains(npc))
2024-09-05 12:28:32 +08:00
{
2024-11-04 18:19:57 +08:00
_showNpcInfos.Add(npc);
2024-09-05 12:28:32 +08:00
}
}
2024-11-04 18:19:57 +08:00
else
{
2024-11-04 18:19:57 +08:00
_showNpcInfos.Remove(npc);
}
}
2023-12-21 12:48:58 +08:00
}
2023-12-22 15:26:48 +08:00
2024-11-12 20:31:06 +08:00
#endregion
2024-11-13 17:14:27 +08:00
#region 己方Npc
2024-11-12 20:31:06 +08:00
2024-11-18 16:50:35 +08:00
[LabelText("编辑己方NPC"), Indent] [LabelWidth(100)] [OnValueChanged("OnIsEditingSelfNpcChanged")] [SerializeField]
2024-11-13 17:14:27 +08:00
public bool isEditingSelfNpc;
2024-11-12 20:31:06 +08:00
2024-11-18 16:50:35 +08:00
[LabelText("显示所有己方序号ID"), Indent] [OnValueChanged("ShowAllSelfNpcId")] [SerializeField]
public bool isShowAllSelfNpcID;
2024-11-13 17:14:27 +08:00
[LabelText("己方NpcID"), Indent, LabelWidth(100)]
2024-11-12 20:31:06 +08:00
[SerializeField]
2024-11-13 17:14:27 +08:00
[OnValueChanged("SelfNpcIDChanged")]
[ValueDropdown("GetSelfNpcIDs")]
[ShowIf("isEditingSelfNpc")]
public int curSelfNpcID;
2024-11-12 20:31:06 +08:00
2024-11-13 13:21:36 +08:00
[PreviewField(150, ObjectFieldAlignment.Center), Indent, ReadOnly]
2024-11-13 17:14:27 +08:00
[LabelText("己方NPC预制体预览图"), ShowIf("isEditingSelfNpc")]
public GameObject selfNpcObject;
2024-11-12 20:31:06 +08:00
2024-11-13 17:14:27 +08:00
[LabelText("当前己方NPC列表"), Indent, ShowIf("isEditingSelfNpc")]
2024-11-13 13:21:36 +08:00
[ListDrawerSettings(HideAddButton = true, HideRemoveButton = true)]
2024-11-18 16:50:35 +08:00
public List<NpcEditorInfo> currentSelfNpcInfo = null;
2024-11-12 20:31:06 +08:00
2024-11-13 17:14:27 +08:00
private IEnumerable<int> GetSelfNpcIDs()
2024-11-12 20:31:06 +08:00
{
2024-11-18 14:34:15 +08:00
return selfMonsterIDs;
2024-11-12 20:31:06 +08:00
}
2024-11-13 17:14:27 +08:00
private void SelfNpcIDChanged()
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
var obj = LoadSelfNpcPrefab(curSelfNpcID);
2024-11-12 20:31:06 +08:00
if (obj != null)
2024-11-13 17:14:27 +08:00
selfNpcObject = obj;
2024-11-12 20:31:06 +08:00
}
2024-11-18 16:50:35 +08:00
private void OnIsEditingSelfNpcChanged()
{
if (isEditingNpc && isEditingSelfNpc)
isEditingNpc = false;
}
private void ShowAllSelfNpcId()
{
foreach (var npc in currentSelfNpcInfo)
{
npc.isShowNpcID = isShowAllSelfNpcID;
if (isShowAllSelfNpcID)
{
if (!_showNpcInfos.Contains(npc))
{
_showNpcInfos.Add(npc);
}
}
else
{
_showNpcInfos.Remove(npc);
}
}
}
2024-11-12 20:31:06 +08:00
#endregion
2024-06-04 16:50:16 +08:00
#region 保存
2024-06-04 16:50:16 +08:00
[Button("保存当前关卡"), Indent]
2023-08-22 19:08:45 +08:00
private void SaveCurrentLevel()
{
CheckCorrectLevel();
// 地区
currentLevelData.preparingRegionId = curRegionData.preparingRegionId;
currentLevelData.fallbackRegionId = curRegionData.fallbackRegionId;
currentLevelData.enemyFallbackRegionId = curRegionData.enemyFallbackRegionId;
currentLevelData.preparingRegionToward = curRegionData.preparingRegionToward;
2023-12-26 18:19:05 +08:00
currentLevelData.pvpDefendRegionId = curRegionData.pvpDefendRegionId;
currentLevelData.pvpDefendToward = curRegionData.pvpDefendToward;
2024-11-07 15:50:33 +08:00
// NPC
2024-11-07 13:09:27 +08:00
foreach (var npcEditor in currentNpcInfo)
{
npcEditor.npcInfo.index = npcEditor.id;
}
2024-11-13 17:14:27 +08:00
2024-11-07 13:09:27 +08:00
currentLevelData.npcInfos = currentNpcInfo.Select(editorNpcInfo => editorNpcInfo.npcInfo).ToList();
2024-11-18 16:50:35 +08:00
2024-11-13 17:14:27 +08:00
// 己方NPC
foreach (var npcFightEditorInfo in currentSelfNpcInfo)
2024-11-13 13:21:36 +08:00
{
npcFightEditorInfo.npcInfo.index = npcFightEditorInfo.id;
}
2024-11-13 17:14:27 +08:00
currentLevelData.selfNpcInfos =
currentSelfNpcInfo.Select(editorFightNpcInfo => editorFightNpcInfo.npcInfo).ToList();
2024-11-12 20:31:06 +08:00
// 条件
2024-11-07 15:50:33 +08:00
ProcessCondition();
// 占领数据
currentLevelData.CapturePoints.Clear();
foreach (var captureInfo in captureEditorInfo)
{
var capture = new LevelData.CaptureInfo
{
CapturePoint = _curMap.BlockPosition2TGSCellIndex(captureInfo.capturePoint),
CaptureProgress = captureInfo.captureProgress,
};
currentLevelData.CapturePoints.Add(capture);
}
// 扛旗数据
currentLevelData.flagStartPoints.Clear();
currentLevelData.flagEndPoints.Clear();
foreach (var flag in flagEditorInfo.flagStartPoints)
{
var cellIndex = _curMap.BlockPosition2TGSCellIndex(flag);
currentLevelData.flagStartPoints.Add(cellIndex);
}
foreach (var flag in flagEditorInfo.flagEndPoints)
{
var cellIndex = _curMap.BlockPosition2TGSCellIndex(flag);
currentLevelData.flagEndPoints.Add(cellIndex);
}
2024-11-11 13:46:47 +08:00
// 撤离数据
currentLevelData.fallbackSinglePoints.Clear();
currentLevelData.fallbackReusablePoints.Clear();
foreach (var fallback in fallbackEditorInfo.fallbackSinglePoints)
{
var cellIndex = _curMap.BlockPosition2TGSCellIndex(fallback);
currentLevelData.fallbackSinglePoints.Add(cellIndex);
}
foreach (var fallback in fallbackEditorInfo.fallbackReusablePoints)
{
var cellIndex = _curMap.BlockPosition2TGSCellIndex(fallback);
currentLevelData.fallbackReusablePoints.Add(cellIndex);
}
2023-11-21 15:04:56 +08:00
_levelEditor.SaveLevelData();
}
2023-08-22 19:08:45 +08:00
2024-11-07 15:50:33 +08:00
private void ProcessCondition()
{
ProcessConditionForList(currentLevelData.stages.Select(stage => stage.successCondition));
ProcessConditionForList(currentLevelData.starTarget);
ProcessConditionForList(currentLevelData.scoreTarget);
}
private void ProcessConditionForList(IEnumerable<ConditionModifier> conditionModifiers)
{
foreach (var conditionModifier in conditionModifiers)
{
if (conditionModifier.conditionType == ConditionType.CombatKillEnemy)
{
conditionModifier.conditionArgs.Clear();
foreach (var enemy in conditionModifier.killEnemyIDList)
{
conditionModifier.conditionArgs.Add(new Param("", enemy, ""));
}
}
}
2024-11-26 16:58:42 +08:00
foreach (var conditionModifier in conditionModifiers)
{
if (conditionModifier.conditionType == ConditionType.CombatFallBack &&
conditionModifier.conditionArgs.Count > 0)
{
currentLevelData.fallBackCount = (int)conditionModifier.conditionArgs[0].Arg;
}
}
2024-11-07 15:50:33 +08:00
}
#endregion
/// <summary>
/// 该关卡的怪物ID
/// </summary>
[HideInInspector] public List<int> monsterIDs;
2024-11-18 14:34:15 +08:00
/// <summary>
/// 该关卡的怪物ID
/// </summary>
[HideInInspector] public List<int> selfMonsterIDs;
2024-11-12 20:31:06 +08:00
/// <summary>
2024-11-13 17:14:27 +08:00
/// 该关卡的剧怪物ID
2024-11-12 20:31:06 +08:00
/// </summary>
[HideInInspector] public List<int> fightMonsterIDs;
/// <summary>
/// 需要手动输入关卡ID
/// </summary>
2024-11-18 16:50:35 +08:00
[HideInInspector] public bool needManualInputLevelID;
public void GetLevelMonsterClass()
{
2024-06-04 16:50:16 +08:00
if (!int.TryParse(levelID, out var levelIndex) ||
2024-11-18 16:50:35 +08:00
!LevelCfg.DataMap.TryGetValue(levelIndex, out var level))
{
2024-11-18 16:50:35 +08:00
needManualInputLevelID = true;
DebugUtil.LogError("无对应的关卡ID请手动输入关卡ID");
curMonsterID = 0;
npcObject = null;
return;
}
monsterIDs = new List<int>();
2024-11-18 14:34:15 +08:00
selfMonsterIDs = new List<int>();
2024-11-18 16:50:35 +08:00
foreach (var monster in MonsterCfg.DataMap)
{
var strID = monster.Key.ToString();
var tempID = strID.Substring(0, 6);
//关卡ID相同
2024-06-04 16:50:16 +08:00
if (tempID.Equals(levelID))
{
2024-11-18 14:34:15 +08:00
switch (monster.Value.NpcType)
{
case 2:
selfMonsterIDs.Add(monster.Key);
break;
2024-11-18 15:02:49 +08:00
case 3:
selfMonsterIDs.Add(monster.Key);
break;
2024-11-18 14:34:15 +08:00
default:
monsterIDs.Add(monster.Key);
break;
}
}
}
if (monsterIDs.Count <= 0)
{
2024-06-04 16:50:16 +08:00
DebugUtil.LogError("请检查Monster表没有{0}关卡的怪物数据", levelID);
}
2023-08-22 19:08:45 +08:00
}
#region 加载
2023-11-21 15:04:56 +08:00
private void LoadLevel(LevelData levelData)
2023-08-22 19:08:45 +08:00
{
DestroyNpcPrefab();
2024-11-04 18:19:57 +08:00
_npcObjectDic.Clear();
_showNpcInfos.Clear();
2024-11-13 17:14:27 +08:00
_selfNpcObjectDic.Clear();
2023-11-21 15:04:56 +08:00
currentLevelData = levelData;
//加载地区信息
curRegionData = new RegionData
{
preparingRegionId = currentLevelData.preparingRegionId,
fallbackRegionId = currentLevelData.fallbackRegionId,
enemyFallbackRegionId = currentLevelData.enemyFallbackRegionId,
preparingRegionToward = currentLevelData.preparingRegionToward,
pvpDefendRegionId = currentLevelData.pvpDefendRegionId,
pvpDefendToward = currentLevelData.pvpDefendToward
};
2024-04-02 16:53:46 +08:00
2023-12-18 19:42:46 +08:00
_mapManager = FindObjectOfType<MapManager>();
_curMap = _mapManager.Map;
2023-11-21 15:04:56 +08:00
_curMap.TerrainGridSystem.OnMouseClickOnGrid += OnCellClick;
// 加载占领数据
captureEditorInfo = new List<CaptureEditorInfo>();
foreach (var captureInfo in currentLevelData.CapturePoints)
{
var captureEditor = new CaptureEditorInfo()
{
capturePoint = _curMap.TGSCellIndex2BlockPosition(captureInfo.CapturePoint),
captureProgress = captureInfo.CaptureProgress,
};
captureEditorInfo.Add(captureEditor);
}
// 加载扛旗数据
flagEditorInfo = new FlagEditorInfo();
foreach (var flagStartPoint in currentLevelData.flagStartPoints)
{
var pos = _curMap.TGSCellIndex2BlockPosition(flagStartPoint);
flagEditorInfo.flagStartPoints.Add(pos);
}
foreach (var flagEndPoint in currentLevelData.flagEndPoints)
{
var pos = _curMap.TGSCellIndex2BlockPosition(flagEndPoint);
flagEditorInfo.flagEndPoints.Add(pos);
}
2024-11-11 13:46:47 +08:00
// 加载撤离数据
fallbackEditorInfo = new FallbackEditorInfo();
foreach (var fallback in currentLevelData.fallbackSinglePoints)
{
var pos = _curMap.TGSCellIndex2BlockPosition(fallback);
fallbackEditorInfo.fallbackSinglePoints.Add(pos);
}
foreach (var fallback in currentLevelData.fallbackReusablePoints)
{
var pos = _curMap.TGSCellIndex2BlockPosition(fallback);
fallbackEditorInfo.fallbackReusablePoints.Add(pos);
}
// 加载NPC到场景中
LoadNpcInfo();
2024-11-13 17:14:27 +08:00
// 加载己方NPC
2024-11-18 16:50:35 +08:00
LoadSelfNpcInfo();
}
2024-11-04 18:19:57 +08:00
private void LoadNpcInfo()
{
2024-11-18 16:50:35 +08:00
var monsterConfigDic = MonsterCfg.DataMap;
2024-06-04 16:50:16 +08:00
currentNpcInfo = new();
2024-11-04 18:19:57 +08:00
var index = 1;
foreach (var npcInfo in currentLevelData.npcInfos)
{
2024-09-05 13:26:43 +08:00
if (!monsterConfigDic.TryGetValue(npcInfo.id, out var monsterClassData))
2024-06-04 16:50:16 +08:00
{
2024-09-05 13:26:43 +08:00
DebugUtil.LogError("请检查配置,没有 {0} 的怪物类ID", npcInfo.id);
continue;
}
2024-09-05 12:28:32 +08:00
2024-11-18 16:50:35 +08:00
var npcEditor = new NpcEditorInfo(npcInfo, index);
currentNpcInfo.Add(npcEditor);
2024-09-05 13:26:43 +08:00
npcInfo.level = monsterClassData.MonsterLevel;
2024-09-05 12:28:32 +08:00
2024-11-04 18:19:57 +08:00
var npcObj = LoadNpcPrefab(npcInfo.id);
if (npcObj != null)
2024-09-05 13:26:43 +08:00
{
2024-11-04 18:19:57 +08:00
var setPos = _curMap.BlockPosition2WorldPosition(npcInfo.position);
2024-11-04 18:43:29 +08:00
var yaw = LevelUtils.SetCharaterToward(npcInfo.npcToward);
_npcObjectDic.Add(npcInfo.position, Instantiate(npcObj, setPos, Quaternion.Euler(0, yaw, 0)));
2024-04-02 16:53:46 +08:00
}
2024-11-04 18:19:57 +08:00
index++;
}
}
2024-11-18 16:50:35 +08:00
private void LoadSelfNpcInfo()
2024-11-12 20:31:06 +08:00
{
2024-11-18 16:50:35 +08:00
var monsterConfigDic = MonsterCfg.DataMap;
2024-11-13 17:14:27 +08:00
currentSelfNpcInfo = new();
2024-11-13 19:11:46 +08:00
var index = SelfID + 1;
2024-11-18 15:27:53 +08:00
foreach (var selfNpcInfo in currentLevelData.selfNpcInfos)
2024-11-12 20:31:06 +08:00
{
2024-11-18 16:50:35 +08:00
if (!monsterConfigDic.TryGetValue(selfNpcInfo.id, out var monsterClassData))
2024-11-12 20:31:06 +08:00
{
2024-11-18 15:27:53 +08:00
DebugUtil.LogError("请检查配置,没有 {0} 的怪物类ID, 已经删除对应", selfNpcInfo.id);
2024-11-12 20:31:06 +08:00
continue;
}
2024-11-18 16:50:35 +08:00
var npcEditor = new NpcEditorInfo(selfNpcInfo, index, true);
currentSelfNpcInfo.Add(npcEditor);
selfNpcInfo.level = monsterClassData.MonsterLevel;
2024-11-18 15:27:53 +08:00
var npcObj = LoadSelfNpcPrefab(selfNpcInfo.id);
2024-11-12 20:31:06 +08:00
if (npcObj != null)
{
2024-11-18 15:27:53 +08:00
var setPos = _curMap.BlockPosition2WorldPosition(selfNpcInfo.position);
var yaw = LevelUtils.SetCharaterToward(selfNpcInfo.npcToward);
_selfNpcObjectDic.Add(selfNpcInfo.position, Instantiate(npcObj, setPos, Quaternion.Euler(0, yaw, 0)));
2024-11-12 20:31:06 +08:00
}
2024-11-13 13:21:36 +08:00
index++;
2024-11-12 20:31:06 +08:00
}
}
#endregion
#region 点击添加事件
private void OnCellClick(TerrainGridSystem tgs, int cellindex, int buttonindex)
{
2023-12-22 15:26:48 +08:00
if (!ResponseClickOnCell) return;
var clickPosition = _curMap.TGSCellIndex2BlockPosition(cellindex);
2023-11-21 15:04:56 +08:00
int leftButton = 0;
int rightButton = 1;
2023-12-22 15:26:48 +08:00
if (buttonindex != leftButton && buttonindex != rightButton)
return;
bool opTrue = buttonindex == leftButton;
if (isEditingFlagStart)
{
EditingFlagStart(clickPosition, true, opTrue);
}
else if (isEditingFlagEnd)
{
EditingFlagStart(clickPosition, false, opTrue);
}
2024-11-11 13:46:47 +08:00
else if (isEditingFallbackSingle)
{
EditingFallBack(clickPosition, true, opTrue);
}
else if (isEditingFallbackReusable)
{
EditingFallBack(clickPosition, false, opTrue);
}
2024-11-07 18:30:47 +08:00
else if (isEditingCapture)
{
EditingCapture(clickPosition, opTrue);
}
else if (isEditingPatrolInfo)
2023-12-22 15:26:48 +08:00
{
if (opTrue)
AddPatrolInfo(clickPosition);
else
RemovePatrolInfo(clickPosition);
}
2024-11-04 18:19:57 +08:00
else if (isEditingNpcPos)
{
if (opTrue)
ChangeNpcPos(clickPosition);
}
else if (isEditingNpc)
{
2024-11-12 20:31:06 +08:00
EditNpc(clickPosition, opTrue);
}
2024-11-13 17:14:27 +08:00
else if (isEditingSelfNpc)
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
EditSelfNpc(clickPosition, opTrue);
}
}
2024-11-11 13:46:47 +08:00
private void EditingFallBack(Vector2Int clickPosition, bool isEditingSingle, bool isAdd)
{
if (isEditingSingle)
{
if (isAdd && !fallbackEditorInfo.fallbackSinglePoints.Contains(clickPosition))
{
DebugUtil.Log("单次撤离点添加: {0}", clickPosition);
fallbackEditorInfo.fallbackSinglePoints.Add(clickPosition);
}
else if (!isAdd && fallbackEditorInfo.fallbackSinglePoints.Contains(clickPosition))
{
DebugUtil.Log("单次撤离点移除: {0}", clickPosition);
fallbackEditorInfo.fallbackSinglePoints.Remove(clickPosition);
}
}
else
{
if (isAdd && !fallbackEditorInfo.fallbackReusablePoints.Contains(clickPosition))
{
DebugUtil.Log("复用撤离点添加: {0}", clickPosition);
fallbackEditorInfo.fallbackReusablePoints.Add(clickPosition);
}
else if (!isAdd && fallbackEditorInfo.fallbackReusablePoints.Contains(clickPosition))
{
DebugUtil.Log("复用撤离点移除: {0}", clickPosition);
fallbackEditorInfo.fallbackReusablePoints.Remove(clickPosition);
}
}
}
2024-11-07 18:30:47 +08:00
private void EditingFlagStart(Vector2Int clickPosition, bool isEditingStart, bool isAdd)
{
if (isEditingStart)
{
if (isAdd && !flagEditorInfo.flagStartPoints.Contains(clickPosition))
{
DebugUtil.Log("扛旗起点添加: {0}", clickPosition);
flagEditorInfo.flagStartPoints.Add(clickPosition);
}
else if (!isAdd && flagEditorInfo.flagStartPoints.Contains(clickPosition))
{
DebugUtil.Log("扛旗起点移除: {0}", clickPosition);
flagEditorInfo.flagStartPoints.Remove(clickPosition);
}
}
else
{
if (isAdd && !flagEditorInfo.flagEndPoints.Contains(clickPosition))
{
DebugUtil.Log("扛旗终点添加: {0}", clickPosition);
flagEditorInfo.flagEndPoints.Add(clickPosition);
}
else if (!isAdd && flagEditorInfo.flagEndPoints.Contains(clickPosition))
{
DebugUtil.Log("扛旗终点移除: {0}", clickPosition);
flagEditorInfo.flagEndPoints.Remove(clickPosition);
}
2023-12-22 15:26:48 +08:00
}
}
2023-11-21 15:04:56 +08:00
2024-11-07 18:30:47 +08:00
private void EditingCapture(Vector2Int clickPosition, bool isAdd)
{
var isExist = false;
CaptureEditorInfo existCapture = null;
foreach (var capture in captureEditorInfo)
{
if (capture.capturePoint == clickPosition)
{
isExist = true;
existCapture = capture;
}
}
if (isAdd)
{
if (!isExist)
{
DebugUtil.Log("占领点添加: {0}", clickPosition);
captureEditorInfo.Add(new CaptureEditorInfo()
{
capturePoint = clickPosition
});
}
}
else
{
if (existCapture != null)
{
DebugUtil.Log("占领点移除: {0}", clickPosition);
captureEditorInfo.Remove(existCapture);
}
}
}
2024-11-04 18:19:57 +08:00
private void ChangeNpcPos(Vector2Int clickPosition)
{
var oldPos = _currEditingNpcInfo.position;
2024-11-04 18:19:57 +08:00
if (oldPos == clickPosition) return;
var newWorldPos = _curMap.BlockPosition2WorldPosition(clickPosition);
if (_npcObjectDic.TryGetValue(oldPos, out var npcObj))
{
npcObj.transform.position = newWorldPos;
_currEditingNpcInfo.position = clickPosition;
2024-11-04 18:19:57 +08:00
_npcObjectDic.Remove(oldPos);
_npcObjectDic.Add(clickPosition, npcObj);
DebugUtil.Log("怪物: [ {0} ] 移动到 [ {1} ]位置上", _currEditingNpcInfo.id, clickPosition);
2024-11-04 18:19:57 +08:00
}
2024-11-18 16:50:35 +08:00
else if (_selfNpcObjectDic.TryGetValue(oldPos, out var selfNpcObj))
{
selfNpcObj.transform.position = newWorldPos;
_currEditingNpcInfo.position = clickPosition;
_selfNpcObjectDic.Remove(oldPos);
_selfNpcObjectDic.Add(clickPosition, selfNpcObj);
DebugUtil.Log("怪物: [ {0} ] 移动到 [ {1} ]位置上", _currEditingNpcInfo.id, clickPosition);
}
else
{
DebugUtil.LogError("需要更改的旧位置上没有怪物:{0}", oldPos);
}
2024-11-04 18:19:57 +08:00
}
2024-11-12 20:31:06 +08:00
private void EditNpc(Vector2Int clickPosition, bool isAdd)
{
if (isAdd)
{
AddNpc(clickPosition);
}
else
{
RemoveNpc(clickPosition);
}
}
private void AddNpc(Vector2Int clickPosition)
2023-12-22 15:26:48 +08:00
{
if (npcObject == null || curMonsterID == 0)
2023-12-22 15:26:48 +08:00
{
DebugUtil.LogError("请选择正确的NPC");
return;
}
2023-11-21 15:04:56 +08:00
2024-11-04 18:19:57 +08:00
_npcObjectDic ??= new Dictionary<Vector2Int, GameObject>();
2024-11-04 18:19:57 +08:00
if (_npcObjectDic.ContainsKey(clickPosition))
2023-12-22 15:26:48 +08:00
{
DebugUtil.LogError("该位置已有NPC存在请重新选");
return;
}
2023-12-22 15:26:48 +08:00
2024-11-04 18:19:57 +08:00
LevelData.NPCInfo npcInfo = new LevelData.NPCInfo
2024-09-05 13:26:43 +08:00
{
2024-11-04 18:19:57 +08:00
id = curMonsterID,
position = clickPosition
};
2023-12-22 15:26:48 +08:00
2024-11-18 16:50:35 +08:00
var monsterConfigDic = MonsterCfg.DataMap;
if (monsterConfigDic.TryGetValue(curMonsterID, out var monster))
{
npcInfo.level = monster.MonsterLevel;
}
else
{
DebugUtil.LogError("获取怪物[{0}]配置数据错误", curMonsterID);
}
2024-11-12 20:31:06 +08:00
currentNpcInfo.Add(new NpcEditorInfo(npcInfo, currentNpcInfo.Count + 1));
2024-11-04 18:19:57 +08:00
var pos = _curMap.BlockPosition2WorldPosition(npcInfo.position);
_npcObjectDic.Add(npcInfo.position, Instantiate(npcObject, pos, npcObject.transform.rotation));
DebugUtil.Log("添加了怪物: [ {0} ] 到 [ {1} ]位置上, 其预制体为: {2}", npcInfo.id, npcInfo.position, npcObject.name);
2023-12-22 15:26:48 +08:00
}
private void RemoveNpc(Vector2Int clickPosition)
2023-12-22 15:26:48 +08:00
{
2024-11-04 18:19:57 +08:00
if (_npcObjectDic.TryGetValue(clickPosition, out var npcObj))
{
2024-06-04 16:50:16 +08:00
var npc = currentNpcInfo.FirstOrDefault(npc => npc.npcInfo.position == clickPosition);
2023-12-22 15:26:48 +08:00
if (npc != null)
{
2024-06-04 16:50:16 +08:00
currentNpcInfo.Remove(npc);
2023-12-22 15:26:48 +08:00
DebugUtil.Log("从[ {0} ]位置上移除了[{1}]NPC", clickPosition, npcObj.name);
DestroyImmediate(npcObj);
2024-11-04 18:19:57 +08:00
_npcObjectDic.Remove(clickPosition);
}
}
2024-11-04 18:19:57 +08:00
ReorderNpcID();
}
2024-11-13 17:14:27 +08:00
private void EditSelfNpc(Vector2Int clickPosition, bool isAdd)
2024-11-12 20:31:06 +08:00
{
if (isAdd)
{
2024-11-13 17:14:27 +08:00
AddSelfNpc(clickPosition);
2024-11-12 20:31:06 +08:00
}
else
{
2024-11-13 17:14:27 +08:00
RemoveSelfNpc(clickPosition);
2024-11-12 20:31:06 +08:00
}
}
2024-11-13 17:14:27 +08:00
private void AddSelfNpc(Vector2Int clickPosition)
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
if (selfNpcObject == null || curSelfNpcID == 0)
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
DebugUtil.LogError("请选择正确的己方NPC");
2024-11-12 20:31:06 +08:00
return;
}
2024-11-13 17:14:27 +08:00
_selfNpcObjectDic ??= new Dictionary<Vector2Int, GameObject>();
2024-11-12 20:31:06 +08:00
2024-11-13 17:14:27 +08:00
if (_selfNpcObjectDic.ContainsKey(clickPosition))
2024-11-12 20:31:06 +08:00
{
DebugUtil.LogError("该位置已有NPC存在请重新选");
return;
}
2024-11-13 19:11:46 +08:00
LevelData.NPCInfo npcInfo = new LevelData.NPCInfo
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
id = curSelfNpcID,
2024-11-12 20:31:06 +08:00
position = clickPosition
};
2024-11-18 16:50:35 +08:00
currentSelfNpcInfo.Add(new NpcEditorInfo(npcInfo, SelfID + currentSelfNpcInfo.Count + 1));
2024-11-12 20:31:06 +08:00
var pos = _curMap.BlockPosition2WorldPosition(npcInfo.position);
2024-11-13 17:14:27 +08:00
_selfNpcObjectDic.Add(npcInfo.position, Instantiate(selfNpcObject, pos, selfNpcObject.transform.rotation));
DebugUtil.Log("添加了己方Npc: [ {0} ] 到 [ {1} ]位置上, 其预制体为: {2}", npcInfo.id, npcInfo.position, selfNpcObject.name);
2024-11-12 20:31:06 +08:00
}
2024-11-13 17:14:27 +08:00
private void RemoveSelfNpc(Vector2Int clickPosition)
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
if (_selfNpcObjectDic.TryGetValue(clickPosition, out var npcObj))
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
var npc = currentSelfNpcInfo.FirstOrDefault(npcFight => npcFight.npcInfo.position == clickPosition);
2024-11-12 20:31:06 +08:00
if (npc != null)
{
2024-11-13 17:14:27 +08:00
currentSelfNpcInfo.Remove(npc);
DebugUtil.Log("从[ {0} ]位置上移除了[{1}] 己方NPC", clickPosition, npcObj.name);
2024-11-12 20:31:06 +08:00
DestroyImmediate(npcObj);
2024-11-13 17:14:27 +08:00
_selfNpcObjectDic.Remove(clickPosition);
2024-11-12 20:31:06 +08:00
}
}
2024-11-13 13:21:36 +08:00
2024-11-13 17:14:27 +08:00
ReorderSelfNpcID();
2024-11-12 20:31:06 +08:00
}
2023-12-22 15:26:48 +08:00
private void AddPatrolInfo(Vector2Int clickPosition)
{
_currEditingNpcInfo.patrolInfos.Add(new LevelData.PatrolInfo()
2023-12-22 15:26:48 +08:00
{
patrolPoint = clickPosition,
});
}
private void RemovePatrolInfo(Vector2Int clickPosition)
{
var index = _currEditingNpcInfo.patrolInfos.FindLastIndex(pInfo => pInfo.patrolPoint == clickPosition);
2023-12-22 15:26:48 +08:00
if (index >= 0)
_currEditingNpcInfo.patrolInfos.RemoveAt(index);
2023-12-22 15:26:48 +08:00
}
#endregion
#region 值改变时响应时间事件
private void OnCurrentLevelDataChanged()
{
Debug.Log($"{GetType()}.OnCurrentLevelDataChanged");
}
2024-11-04 18:19:57 +08:00
private void StartEditPatrolInfo(LevelData.NPCInfo npcInfo)
2023-12-22 15:26:48 +08:00
{
2024-11-04 18:19:57 +08:00
isEditingPatrolInfo = true;
_currEditingNpcInfo = npcInfo;
2023-12-22 15:26:48 +08:00
}
2024-11-04 18:19:57 +08:00
private void FinishEditPatrolInfo()
2023-12-22 15:26:48 +08:00
{
2024-11-04 18:19:57 +08:00
isEditingPatrolInfo = false;
_currEditingNpcInfo = null;
2023-12-22 15:26:48 +08:00
}
2024-11-04 18:19:57 +08:00
private void ReorderNpcID()
{
for (var i = 0; i < currentNpcInfo.Count; i++)
{
currentNpcInfo[i].id = i + 1;
}
}
2024-11-13 17:14:27 +08:00
private void ReorderSelfNpcID()
2024-11-13 13:21:36 +08:00
{
2024-11-13 17:14:27 +08:00
for (var i = 0; i < currentSelfNpcInfo.Count; i++)
2024-11-13 13:21:36 +08:00
{
2024-11-13 19:11:46 +08:00
currentSelfNpcInfo[i].id = SelfID + i + 1;
2024-11-13 13:21:36 +08:00
}
}
2024-11-04 18:19:57 +08:00
private void ChangeNpcID(LevelData.NPCInfo npcInfo, int newMonsterID)
{
if (_npcObjectDic.TryGetValue(npcInfo.position, out var npcObj))
{
var newObj = LoadNpcPrefab(newMonsterID);
if (newObj != null)
{
npcInfo.id = newMonsterID;
2024-11-13 13:21:36 +08:00
_npcObjectDic[npcInfo.position] =
Instantiate(newObj, npcObj.transform.position, npcObj.transform.rotation);
2024-11-04 18:19:57 +08:00
DestroyImmediate(npcObj);
DebugUtil.Log("位置上[ {0} ]的怪物ID改为: [ {1} ] ", npcInfo.position, npcInfo.id);
}
}
}
2024-11-13 19:11:46 +08:00
private void ChangeFightNpcID(LevelData.NPCInfo npcInfoInfo, int newMonsterID)
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
if (_selfNpcObjectDic.TryGetValue(npcInfoInfo.position, out var npcObj))
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
var newObj = LoadSelfNpcPrefab(newMonsterID);
2024-11-12 20:31:06 +08:00
if (newObj != null)
{
npcInfoInfo.id = newMonsterID;
2024-11-13 17:14:27 +08:00
_selfNpcObjectDic[npcInfoInfo.position] =
2024-11-13 13:21:36 +08:00
Instantiate(newObj, npcObj.transform.position, npcObj.transform.rotation);
2024-11-12 20:31:06 +08:00
DestroyImmediate(npcObj);
DebugUtil.Log("位置上[ {0} ]的fight怪物ID改为: [ {1} ] ", npcInfoInfo.position, npcInfoInfo.id);
}
}
}
#endregion
#region 检查关卡
private const string PreparingRegionErrorMessage = "关卡出战区设置错误,该地图没有:<{0}>号地区。\n";
private const string FallbackRegionErrorMessage = "关卡撤退区设置错误,该地图没有:<{0}>号地区。\n";
private const string EnemyFallbackRegionErrorMessage = "关卡敌方撤退区设置错误,该地图没有:<{0}>号地区。\n";
private const string FixedMessage = "已将错误区域设置为默认<0>号地区。";
private const string CaptureErrorMessage = "占领条件参数大于配置的占领区域。";
private void CheckCorrectLevel()
{
if (_curMap == null)
{
return;
}
var errorMessage = string.Empty;
if (!_curMap.MapData.IsRegionExist(curRegionData.preparingRegionId))
{
errorMessage += string.Format(PreparingRegionErrorMessage,
curRegionData.preparingRegionId);
curRegionData.preparingRegionId = 0;
}
if (!_curMap.MapData.IsRegionExist(curRegionData.fallbackRegionId))
{
errorMessage += string.Format(FallbackRegionErrorMessage,
curRegionData.fallbackRegionId);
curRegionData.fallbackRegionId = 0;
}
if (!_curMap.MapData.IsRegionExist(curRegionData.enemyFallbackRegionId))
{
errorMessage += string.Format(EnemyFallbackRegionErrorMessage,
curRegionData.enemyFallbackRegionId);
curRegionData.enemyFallbackRegionId = 0;
}
// 检查占领条件相关
if (!CheckLevelCondition())
{
CustomPopUpWindow.PopUp(CaptureErrorMessage);
}
if (!string.IsNullOrEmpty(errorMessage))
{
CustomPopUpWindow.PopUp(errorMessage + FixedMessage);
}
}
private bool CheckLevelCondition()
{
if (currentLevelData.stages.Any(stage => stage.successCondition.conditionType == ConditionType.CombatLeastOccupy
2024-11-13 13:21:36 +08:00
&& stage.successCondition.conditionArgs[0].Arg >
captureEditorInfo.Count))
{
return false;
}
if (currentLevelData.starTarget.Any(modifier => modifier.conditionType == ConditionType.CombatLeastOccupy
&& modifier.conditionArgs[0].Arg > captureEditorInfo.Count))
{
return false;
}
if (currentLevelData.scoreTarget.Any(modifier => modifier.conditionType == ConditionType.CombatLeastOccupy
&& modifier.conditionArgs[0].Arg > captureEditorInfo.Count))
{
return false;
}
return true;
}
#endregion
#region 内部方法
2024-11-04 18:19:57 +08:00
private GameObject LoadNpcPrefab(int monsterID)
{
GameObject obj = null;
2024-11-18 15:02:49 +08:00
var curMonsterClassID = 0;
2024-11-18 16:50:35 +08:00
if (MonsterCfg.DataMap.TryGetValue(monsterID, out var monster))
2024-11-04 18:19:57 +08:00
{
2024-11-18 15:02:49 +08:00
curMonsterClassID = monster.MonsterClassID;
2024-11-04 18:19:57 +08:00
}
else
{
return null;
}
switch (monster.NpcType)
{
2024-11-18 15:02:49 +08:00
case 1:
2024-11-04 18:19:57 +08:00
{
2024-11-18 16:50:35 +08:00
if (VehicleCfg.DataMap.TryGetValue(curMonsterClassID, out var vehicle))
2024-11-04 18:19:57 +08:00
{
var prefabPath = PathEx.GetVehicleGameModelPath(vehicle.ID);
obj = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
if (obj == null)
{
2024-11-18 15:02:49 +08:00
DebugUtil.LogError("请检查载具类: {0}的预制体路径是否存在,对应的完整路径: {1}", curMonsterClassID, prefabPath);
2024-11-04 18:19:57 +08:00
}
}
else
{
2024-11-18 15:02:49 +08:00
DebugUtil.LogError("请检查载具类: {0}的配置是否存在", curMonsterClassID);
2024-11-04 18:19:57 +08:00
}
return obj;
}
2024-11-18 15:02:49 +08:00
case 0:
2024-11-04 18:19:57 +08:00
{
var monsterClassCfg = EditorTableManager.instance.tables.MonsterClass;
2024-11-18 15:02:49 +08:00
if (monsterClassCfg.DataMap.TryGetValue(curMonsterClassID, out var monsterClass))
2024-11-04 18:19:57 +08:00
{
var prefabPath = PathEx.GetCharacterFightModelPath(monsterClass.NameId, monsterClass.WeaponId);
2024-11-04 18:19:57 +08:00
obj = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
if (obj == null)
{
2024-11-18 15:02:49 +08:00
DebugUtil.LogError("请检查怪物类: {0}的预制体路径是否存在,对应的完整路径: {1}", curMonsterClassID, prefabPath);
2024-11-04 18:19:57 +08:00
}
}
else
{
2024-11-18 15:02:49 +08:00
DebugUtil.LogError("请检查怪物类: {0}的配置是否存在", curMonsterClassID);
2024-11-04 18:19:57 +08:00
}
return obj;
}
default: return null;
}
}
2024-11-13 17:14:27 +08:00
private GameObject LoadSelfNpcPrefab(int monsterID)
2024-11-12 20:31:06 +08:00
{
2024-11-18 15:02:49 +08:00
GameObject obj = null;
var curFightNpcID = 0;
2024-11-18 16:50:35 +08:00
if (MonsterCfg.DataMap.TryGetValue(monsterID, out var monster))
2024-11-18 15:02:49 +08:00
{
curFightNpcID = monster.MonsterClassID;
}
else
{
2024-11-12 20:31:06 +08:00
return null;
2024-11-18 15:02:49 +08:00
}
2024-11-12 20:31:06 +08:00
2024-11-18 15:02:49 +08:00
switch (monster.NpcType)
2024-11-12 20:31:06 +08:00
{
2024-11-18 15:02:49 +08:00
case 3:
{
2024-11-18 16:50:35 +08:00
if (VehicleCfg.DataMap.TryGetValue(curFightNpcID, out var vehicle))
2024-11-18 15:02:49 +08:00
{
var prefabPath = PathEx.GetVehicleGameModelPath(vehicle.ID);
obj = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
if (obj == null)
{
DebugUtil.LogError("请检查载具类: {0}的预制体路径是否存在,对应的完整路径: {1}", curFightNpcID, prefabPath);
}
}
else
{
DebugUtil.LogError("请检查载具类: {0}的配置是否存在", curFightNpcID);
}
2024-11-12 20:31:06 +08:00
2024-11-18 15:02:49 +08:00
return obj;
}
case 2:
{
2024-11-18 16:50:35 +08:00
if (FightNpcCfg.DataMap.TryGetValue(curFightNpcID, out var fightNpc))
2024-11-18 15:02:49 +08:00
{
var prefabPath = PathEx.GetCharacterFightModelPath(fightNpc.NameId, fightNpc.WeaponId);
obj = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
if (obj == null)
{
DebugUtil.LogError("请检查FightNpc类: {0}的预制体路径是否存在,对应的完整路径: {1}", curFightNpcID, prefabPath);
}
}
else
{
DebugUtil.LogError("请检查FightNpc类: {0}的配置是否存在", curFightNpcID);
}
return obj;
}
default: return null;
}
2024-11-12 20:31:06 +08:00
}
private void DestroyNpcPrefab()
{
2024-11-04 18:19:57 +08:00
foreach (var npc in _npcObjectDic)
{
DestroyImmediate(npc.Value);
}
2024-11-12 20:31:06 +08:00
2024-11-13 17:14:27 +08:00
foreach (var npc in _selfNpcObjectDic)
2024-11-12 20:31:06 +08:00
{
DestroyImmediate(npc.Value);
}
2023-08-22 19:08:45 +08:00
}
2023-12-22 15:26:48 +08:00
2024-11-04 18:43:29 +08:00
private void ChangeNpcToward(Vector2Int pos, LevelData.CharacterToward npcToward)
{
if (_npcObjectDic.TryGetValue(pos, out var npcObj))
{
var yaw = LevelUtils.SetCharaterToward(npcToward);
npcObj.transform.eulerAngles = new Vector3(0, yaw, 0);
}
}
2024-11-13 17:14:27 +08:00
private void ChangeSelfNpcToward(Vector2Int pos, LevelData.CharacterToward npcToward)
2024-11-12 20:31:06 +08:00
{
2024-11-13 17:14:27 +08:00
if (_selfNpcObjectDic.TryGetValue(pos, out var npcObj))
2024-11-12 20:31:06 +08:00
{
var yaw = LevelUtils.SetCharaterToward(npcToward);
npcObj.transform.eulerAngles = new Vector3(0, yaw, 0);
}
}
private bool CheckConditionSame(ConditionType conditionType)
{
if (currentLevelData.stages.Any(stage => stage.successCondition.conditionType == conditionType))
{
return true;
}
if (currentLevelData.starTarget.Any(modifier => modifier.conditionType == conditionType))
{
return true;
}
if (currentLevelData.scoreTarget.Any(modifier => modifier.conditionType == conditionType))
{
return true;
}
return false;
}
#endregion
#region MainLife
private void Awake()
{
SceneView.duringSceneGui += OnSceneGUI;
}
protected override void OnEnable()
{
TerrainTypeConfig.Load();
_npcObjectDic = new Dictionary<Vector2Int, GameObject>();
_showNpcInfos = new List<NpcEditorInfo>();
2024-11-13 17:14:27 +08:00
_selfNpcObjectDic = new Dictionary<Vector2Int, GameObject>();
base.OnEnable();
}
protected override void OnDisable()
{
currWindow = null;
DestroyNpcPrefab();
_npcObjectDic = null;
2024-11-13 17:14:27 +08:00
_selfNpcObjectDic = null;
base.OnDisable();
}
protected override void OnDestroy()
{
base.OnDestroy();
if (_curMap != null)
_curMap.TerrainGridSystem.OnMouseClickOnGrid -= OnCellClick;
SaveCurrentLevel();
SceneView.duringSceneGui -= OnSceneGUI;
}
2023-12-22 15:26:48 +08:00
protected override void OnGUI()
{
base.OnGUI();
if (_levelEditor == null || _mapManager == null || _mapManager.Map != _curMap ||
_levelEditor.LevelData != currentLevelData)
{
Debug.LogError("数据已变更,请重新打开关卡编辑器");
Close();
}
}
#endregion
#region Draw
2023-12-22 15:26:48 +08:00
private void OnSceneGUI(SceneView sceneView)
{
DrawPatrolPath();
2024-11-04 18:19:57 +08:00
DrawNpcID();
2023-12-22 15:26:48 +08:00
}
private void DrawPatrolPath()
{
2024-11-04 18:19:57 +08:00
if (!isEditingPatrolInfo) return;
2023-12-22 15:26:48 +08:00
Vector3 lastWorldPos = Vector3.zero;
for (int i = 0; i < _currEditingNpcInfo.patrolInfos.Count; i++)
2023-12-22 15:26:48 +08:00
{
var gridPos = _currEditingNpcInfo.patrolInfos[i].patrolPoint;
2023-12-22 15:26:48 +08:00
var worldPos = _curMap.BlockPosition2WorldPosition(gridPos);
Handles.color = Color.blue;
Handles.DrawSolidDisc(worldPos, Vector3.up, 0.4f);
if (i > 0)
{
Handles.color = Color.yellow;
2023-12-26 18:19:05 +08:00
EditorUtil.DrawArrowInScene(lastWorldPos, worldPos, 0.5f);
2023-12-22 15:26:48 +08:00
}
//Handles.color = Color.black;
2023-12-26 18:19:05 +08:00
Handles.Label(worldPos, i.ToString());
2023-12-22 15:26:48 +08:00
lastWorldPos = worldPos;
}
}
2024-11-04 18:19:57 +08:00
private GUIStyle labelStyle;
2024-11-18 16:50:35 +08:00
private GUIStyle labelStyleSelf;
2024-11-04 18:19:57 +08:00
private void DrawNpcID()
{
if (!IsShowNpcID) return;
2024-11-04 18:19:57 +08:00
2024-11-18 16:50:35 +08:00
labelStyle ??= new GUIStyle
2024-11-04 18:19:57 +08:00
{
2024-11-18 16:50:35 +08:00
fontSize = 38,
fontStyle = FontStyle.Bold,
normal =
2024-11-04 18:19:57 +08:00
{
2024-11-18 16:50:35 +08:00
textColor = Color.red
}
};
labelStyleSelf ??= new GUIStyle
{
fontSize = 38,
fontStyle = FontStyle.Bold,
normal =
{
textColor = Color.green
}
};
2024-11-04 18:19:57 +08:00
foreach (var npc in _showNpcInfos)
{
if (_npcObjectDic.TryGetValue(npc.npcInfo.position, out var npcObj))
{
Handles.Label(npcObj.transform.position, npc.id.ToString(), labelStyle);
}
2024-11-18 16:50:35 +08:00
else if (_selfNpcObjectDic.TryGetValue(npc.npcInfo.position, out var selfNpcObj))
{
Handles.Label(selfNpcObj.transform.position, npc.id.ToString(), labelStyleSelf);
}
2024-11-04 18:19:57 +08:00
}
}
#endregion
2023-08-22 19:08:45 +08:00
}