using System; using Gameplay.Character; using Gameplay.Level; using Gameplay.Unit; using Gameplay.Unit.Data; using UnityEditor; using UnityEngine; namespace FightDebug { public class FightDebugWindowV2 : EditorWindow { private Vector2 _scrollPos1; private Vector2 _scrollPos2; [MenuItem("Tools/战斗信息Debug/FightDebugWindowV2 _F11")] public static void ShowWindow() { var win = GetWindow("战斗信息调试"); win.Show(); } private void _ShowUnit(GameUnit unit) { GUILayout.BeginVertical("box",GUILayout.Width(200)); _ShowLabel("ID:", unit.GetID() + ""); _ShowLabel("类型:", EGameUnitTypeUtils.GetStrByType(unit.gameunitType)); _ShowLabel("名字:", unit.debugShowInfo.name); _ShowLabel("配置ID:", unit.debugShowInfo.configId); _ShowLabel("等级:", unit.commonData.level + ""); _ShowLabel("攻击力:", unit.fightData.attack + ""); _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 (GUILayout.Button("显示详情", GUILayout.Height(40))) { SingleUnitWindow.ShowWindow(unit); } if (GUILayout.Button("直接杀死", GUILayout.Height(40))) { unit.TakeNormalDamage(99999999, unit, false); } 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(); } } } }