using System; using cfg.CharacterCfg; using Framework; using Gameplay.Character; using Gameplay.Level; using Gameplay.Skill; using Gameplay.Unit; using Gameplay.Unit.Data; using UnityEditor; using UnityEngine; using cfg.LevelCfg; using Gameplay.AI; namespace FightDebug { public class FightDebugWindowV2 : EditorWindow { private Vector2 _scrollPos1; private Vector2 _scrollPos2; private int _cellIndex = 0; [MenuItem("Tools/*战斗信息Debug/FightDebugWindowV2 _F11")] public static void ShowWindow() { var win = GetWindow("战斗信息调试"); win.Show(); } private void _ShowSkillInfo(GameUnit unit) { var skillManager = SkillManager.instance.GetUnitSkillManager(unit); if (skillManager == null) { EditorGUILayout.LabelField("无技能管理器"); EditorGUILayout.LabelField("无技能管理器"); return; } if (skillManager.positiveSkill == null) { EditorGUILayout.LabelField("无主动技能"); EditorGUILayout.LabelField("无主动技能"); return; } var skill = skillManager.positiveSkill; EditorGUILayout.LabelField("技能ID:", skill.runtimeData.configData.ID + ""); EditorGUILayout.LabelField("技能名称:", skill.runtimeData.configData.NameRead); } private void _ShowWaveIndex(GameUnit unit) { var levelData = unit.unitLevelData; if (levelData == null) { EditorGUILayout.LabelField("无波次数据"); return; } EditorGUILayout.LabelField("波次ID:", levelData.WaveId + ""); } 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 "未知"; } } private void _ShowUnit(GameUnit unit) { GUILayout.BeginVertical("box", GUILayout.Width(200)); _ShowLabel("ID:", unit.GetID() + ""); _ShowLabel("类型:", EGameUnitTypeUtils.GetStrByType(unit.gameunitType)); if (unit.gameunitType == EGameUnitType.Character) { var character = unit as UnitCharacter; if (character == null) { EditorGUILayout.HelpBox("类型错误", MessageType.Error); } else { _ShowLabel("职业:", _GetJobStr(character.runtimeData.configData.job)); } } _ShowLabel("名字:", unit.debugShowInfo.name); _ShowLabel("配置ID:", unit.debugShowInfo.configId); _ShowWaveIndex(unit); _ShowLabel("等级:", unit.commonData.level + ""); _ShowLabel("攻击力:", unit.fightData.mainWeaponData.attack + ""); _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() + ""); } _ShowLabel("所在位置:", unit.transData.cellIndex + ""); _ShowLabel("追踪距离:", unit.fightData.trackRange + ""); if (unit.commonData.troopId == ETroopsId.Enemy) { _ShowLabel("怪物品质:", unit.unitLevelData.monsterQualityType.ToString()); _ShowLabel("怪物LocalID:", unit.unitLevelData.LocalId + ""); foreach (var group in unit.unitLevelData.GroupInfos) { _ShowLabel("怪物组:", group + ""); } 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 + ""); } } if (GUILayout.Button("显示详情", GUILayout.Height(40))) { SingleUnitWindow.ShowWindow(unit); } 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); } } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("直接杀死", GUILayout.Height(40))) { unit.ForceKill(); } if (GUILayout.Button("清空士气", GUILayout.Height(40))) { unit.ClearMorale(); } EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); } private bool _CheckIconPathValid(string iconPath) { if (string.IsNullOrEmpty(iconPath)) { return false; } if (!iconPath.StartsWith("Assets/")) { return false; } var iconObj = AssetDatabase.LoadAssetAtPath(iconPath); if (iconObj == null) { return false; } return true; } private Texture2D _LoadIcon(string iconPath) { const string defaultIconPath = "Assets/_Test/Texture/no_pic.png"; if (string.IsNullOrEmpty(iconPath)) { return AssetDatabase.LoadAssetAtPath(defaultIconPath); } if (!iconPath.StartsWith("Assets/")) { return AssetDatabase.LoadAssetAtPath(defaultIconPath); } var iconObj = AssetDatabase.LoadAssetAtPath(iconPath); if (iconObj == null) { return AssetDatabase.LoadAssetAtPath(defaultIconPath); } 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(); } 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); } } 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); } } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); GUILayout.EndVertical(); GUI.backgroundColor = oldBgColor; } private bool _CheckCanShow() { if (!Application.isPlaying) { return false; } if (LevelManager.Instance == null) { return false; } if (GameUnitManager.instance == null) { return false; } return true; } private void _ShowNotInFight() { EditorGUILayout.HelpBox("仅支持在开战后使用", MessageType.Error); } private void OnGUI() { if (_CheckCanShow()) { _ShowInFight(); } else { _ShowNotInFight(); } } } }