NLDClient-yudde/ProjectNLD/Assets/Editor/FightDebug/FightDebugWindowV2.cs

334 lines
11 KiB
C#
Raw Normal View History

2026-03-09 19:47:53 +08:00
using System;
2025-09-01 19:15:41 +08:00
using cfg.CharacterCfg;
2024-11-25 18:27:04 +08:00
using Framework;
using Gameplay.Character;
using Gameplay.Level;
using Gameplay.Skill;
using Gameplay.Unit;
using Gameplay.Unit.Data;
using UnityEditor;
using UnityEngine;
2025-07-02 13:35:17 +08:00
using cfg.LevelCfg;
2025-09-12 19:40:45 +08:00
using Gameplay.AI;
2025-07-02 13:35:17 +08:00
namespace FightDebug
{
public class FightDebugWindowV2 : EditorWindow
{
private Vector2 _scrollPos1;
private Vector2 _scrollPos2;
2025-09-12 19:40:45 +08:00
private int _cellIndex = 0;
2025-02-25 15:03:08 +08:00
[MenuItem("Tools/*战斗信息Debug/FightDebugWindowV2 _F11")]
public static void ShowWindow()
{
var win = GetWindow<FightDebugWindowV2>("战斗信息调试");
win.Show();
}
private void _ShowSkillInfo(GameUnit unit)
{
var skillManager = SkillManager.instance.GetUnitSkillManager(unit);
if (skillManager == null)
{
2025-07-04 13:03:47 +08:00
EditorGUILayout.LabelField("无技能管理器");
EditorGUILayout.LabelField("无技能管理器");
return;
}
2025-07-18 14:11:53 +08:00
if (skillManager.positiveSkill == null)
{
2025-07-04 13:03:47 +08:00
EditorGUILayout.LabelField("无主动技能");
EditorGUILayout.LabelField("无主动技能");
return;
}
2025-07-18 14:11:53 +08:00
var skill = skillManager.positiveSkill;
EditorGUILayout.LabelField("技能ID:", skill.runtimeData.configData.ID + "");
EditorGUILayout.LabelField("技能名称:", skill.runtimeData.configData.NameRead);
}
2025-06-12 19:16:21 +08:00
private void _ShowWaveIndex(GameUnit unit)
{
var levelData = unit.unitLevelData;
if (levelData == null)
{
EditorGUILayout.LabelField("无波次数据");
return;
}
2025-07-18 14:11:53 +08:00
2025-07-02 19:03:43 +08:00
EditorGUILayout.LabelField("波次ID:", levelData.WaveId + "");
2025-06-12 19:16:21 +08:00
}
2025-09-12 19:40:45 +08:00
2025-09-01 19:15:41 +08:00
private string _GetJobStr(Ejob job)
{
switch (job)
{
case Ejob.Job_Commander:
return "指挥";
case Ejob.Job_Support:
return "支援";
case Ejob.Job_Shoot:
return "特射";
case Ejob.Job_Scout:
return "侦察";
case Ejob.Job_Suppress:
return "压制";
case Ejob.Job_Vehicle:
return "载具";
case Ejob.Job_Other:
return "其他";
default:
return "未知";
}
}
2025-06-12 19:16:21 +08:00
private void _ShowUnit(GameUnit unit)
{
2025-07-18 14:11:53 +08:00
GUILayout.BeginVertical("box", GUILayout.Width(200));
_ShowLabel("ID:", unit.GetID() + "");
_ShowLabel("类型:", EGameUnitTypeUtils.GetStrByType(unit.gameunitType));
2025-09-01 19:15:41 +08:00
if (unit.gameunitType == EGameUnitType.Character)
{
var character = unit as UnitCharacter;
if (character == null)
{
EditorGUILayout.HelpBox("类型错误", MessageType.Error);
}
else
{
_ShowLabel("职业:", _GetJobStr(character.runtimeData.configData.job));
}
}
2025-09-12 19:40:45 +08:00
_ShowLabel("名字:", unit.debugShowInfo.name);
_ShowLabel("配置ID:", unit.debugShowInfo.configId);
2025-06-12 19:16:21 +08:00
_ShowWaveIndex(unit);
2024-07-30 14:42:08 +08:00
_ShowLabel("等级:", unit.commonData.level + "");
2025-12-15 18:22:57 +08:00
_ShowLabel("攻击力:", unit.fightData.mainWeaponData.attack + "");
2025-12-09 16:56:33 +08:00
_ShowLabel("位置信息:", unit.transData.cellIndex + "");
_ShowSkillInfo(unit);
_ShowIcon(unit.debugShowInfo.iconPath);
_ShowProgress("生命值:", unit.aliveData.currentHp, unit.aliveData.maxHp);
_ShowProgress("护甲值:", unit.aliveData.currentShield, unit.aliveData.maxShield);
_ShowProgress("士气值:", unit.aliveData.currentMorale, unit.aliveData.maxMorale);
if (unit.controlData.targetEnemy != null)
{
_ShowLabel("目标敌人:", unit.controlData.targetEnemy.GetID() + "");
}
2025-09-12 19:46:19 +08:00
_ShowLabel("所在位置:", unit.transData.cellIndex + "");
2025-11-13 16:38:19 +08:00
_ShowLabel("追踪距离:", unit.fightData.trackRange + "");
2025-07-18 14:11:53 +08:00
if (unit.commonData.troopId == ETroopsId.Enemy)
{
2026-03-09 19:47:53 +08:00
_ShowLabel("怪物品质:", unit.unitLevelData.monsterQualityType.ToString());
2025-07-18 14:11:53 +08:00
_ShowLabel("怪物LocalID:", unit.unitLevelData.LocalId + "");
2025-07-28 16:34:56 +08:00
foreach (var group in unit.unitLevelData.GroupInfos)
{
_ShowLabel("怪物组:", group + "");
}
2025-09-12 19:40:45 +08:00
2025-07-18 14:11:53 +08:00
var aiConfig = TableManager.Instance.Tables.AITypeMonsterConfig;
if (aiConfig.DataMap.TryGetValue(unit.commonData.AIType, out var aiData))
{
_ShowLabel("AI预设ID:", unit.commonData.AIType + "");
_ShowLabel("AI预设Name:", aiData.Name + "");
}
}
2025-09-12 19:40:45 +08:00
if (GUILayout.Button("显示详情", GUILayout.Height(40)))
{
2024-07-09 16:05:44 +08:00
SingleUnitWindow.ShowWindow(unit);
}
2025-07-18 14:11:53 +08:00
2025-09-12 19:40:45 +08:00
if (unit.commonData.troopId == ETroopsId.Enemy)
{
// 输入框和按钮
GUILayout.BeginHorizontal();
GUILayout.Label("目标位置:", GUILayout.Width(80));
_cellIndex = EditorGUILayout.IntField(_cellIndex, GUILayout.Width(80));
GUILayout.EndHorizontal();
if (_cellIndex >= 0 && GUILayout.Button("移动至指定位置", GUILayout.Height(40)))
{
AIManager.Instance.SendNormalMoveStateAndCellIndex(unit, _cellIndex);
}
}
2025-07-04 13:03:47 +08:00
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("直接杀死", GUILayout.Height(40)))
{
unit.ForceKill();
}
2025-07-18 14:11:53 +08:00
2025-07-04 13:03:47 +08:00
if (GUILayout.Button("清空士气", GUILayout.Height(40)))
{
unit.ClearMorale();
}
2025-07-18 14:11:53 +08:00
2025-07-04 13:03:47 +08:00
EditorGUILayout.EndHorizontal();
GUILayout.EndVertical();
}
private bool _CheckIconPathValid(string iconPath)
{
if (string.IsNullOrEmpty(iconPath))
{
return false;
}
2025-07-18 14:11:53 +08:00
if (!iconPath.StartsWith("Assets/"))
{
return false;
}
2025-07-18 14:11:53 +08:00
var iconObj = AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
if (iconObj == null)
{
return false;
}
2025-07-18 14:11:53 +08:00
return true;
}
private Texture2D _LoadIcon(string iconPath)
{
const string defaultIconPath = "Assets/_Test/Texture/no_pic.png";
if (string.IsNullOrEmpty(iconPath))
{
return AssetDatabase.LoadAssetAtPath<Texture2D>(defaultIconPath);
}
2025-07-18 14:11:53 +08:00
if (!iconPath.StartsWith("Assets/"))
{
return AssetDatabase.LoadAssetAtPath<Texture2D>(defaultIconPath);
}
2025-07-18 14:11:53 +08:00
var iconObj = AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
if (iconObj == null)
{
return AssetDatabase.LoadAssetAtPath<Texture2D>(defaultIconPath);
}
2025-07-18 14:11:53 +08:00
return iconObj;
}
private void _ShowIcon(string iconPath)
{
GUILayout.BeginHorizontal();
GUILayout.Label("头像:", GUILayout.Width(60));
GUILayout.Label(new GUIContent(_LoadIcon(iconPath)), GUILayout.Width(100), GUILayout.Height(100));
GUILayout.EndHorizontal();
}
private void _ShowProgress(string label, int currentValue, int maxValue)
{
GUILayout.BeginHorizontal(GUILayout.Height(40));
GUILayout.Label(label, GUILayout.Width(60));
if (maxValue == 0)
{
GUILayout.Label("-无-");
}
else
{
GUILayout.BeginVertical();
var progress = 1f * currentValue / maxValue;
var progressStr = $"{currentValue}/{maxValue} ({progress:P})";
GUILayout.Label(progressStr);
GUILayout.HorizontalSlider(progress, 0, 1);
GUILayout.EndVertical();
}
2025-07-18 14:11:53 +08:00
GUILayout.EndHorizontal();
}
private void _ShowLabel(string label, string value)
{
GUILayout.BeginHorizontal();
GUILayout.Label(label, GUILayout.Width(80));
GUILayout.Label(value);
GUILayout.EndHorizontal();
}
private void _ShowInFight()
{
var oldBgColor = GUI.backgroundColor;
var allUnits = GameUnitManager.instance.infightUnits.unitList;
GUI.backgroundColor = new Color(0.2f, 0.2f, 1f, 0.5f);
GUILayout.BeginVertical("box");
GUILayout.Label("己方");
_scrollPos1 = GUILayout.BeginScrollView(_scrollPos1);
GUILayout.BeginHorizontal();
for (int i = 0; i < allUnits.Count; i++)
{
var unit = allUnits[i];
if (unit.commonData.troopId == ETroopsId.Self)
{
_ShowUnit(unit);
}
}
2025-07-18 14:11:53 +08:00
GUILayout.EndHorizontal();
GUILayout.EndScrollView();
GUILayout.EndVertical();
GUI.backgroundColor = new Color(1f, 0.2f, 0.2f, 0.5f);
GUILayout.BeginVertical("box");
GUILayout.Label("敌方");
_scrollPos2 = GUILayout.BeginScrollView(_scrollPos2);
GUILayout.BeginHorizontal();
for (int i = 0; i < allUnits.Count; i++)
{
var unit = allUnits[i];
if (unit.commonData.troopId != ETroopsId.Self)
{
_ShowUnit(unit);
}
}
2025-07-18 14:11:53 +08:00
GUILayout.EndHorizontal();
GUILayout.EndScrollView();
GUILayout.EndVertical();
GUI.backgroundColor = oldBgColor;
}
private bool _CheckCanShow()
{
if (!Application.isPlaying)
{
return false;
}
2025-07-18 14:11:53 +08:00
if (LevelManager.Instance == null)
{
return false;
}
2025-07-18 14:11:53 +08:00
if (GameUnitManager.instance == null)
{
return false;
}
2025-07-18 14:11:53 +08:00
return true;
}
private void _ShowNotInFight()
{
EditorGUILayout.HelpBox("仅支持在开战后使用", MessageType.Error);
}
private void OnGUI()
{
if (_CheckCanShow())
{
_ShowInFight();
}
else
{
_ShowNotInFight();
}
}
}
2025-07-18 14:11:53 +08:00
}