using System; using cfg.LevelCfg; using System.Collections.Generic; using Gameplay.Area; using Gameplay.Buff; using Gameplay.Level; using Gameplay.Unit; using Gameplay.Unit.Data; using Gameplay.Vehicle.Impl; using UnityEngine; using UnityEditor; namespace FightDebug { public class SingleUnitWindow : EditorWindow { private Vector2 _scrollPos1; private GameUnit _targetUnit; public static void ShowWindow(GameUnit unit) { var win = GetWindow("单位:" + unit.GetDescString()); win._targetUnit = unit; win.Show(); win.Focus(); } 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 _ShowLabel(string label, string value) { GUILayout.BeginHorizontal(); GUILayout.Label(label, GUILayout.Width(80)); GUILayout.Label(value); GUILayout.EndHorizontal(); } 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 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 _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 _ShowBuff(BaseBuff buff) { GUILayout.BeginVertical("box"); _DisplayBuffIcon(buff); _ShowLabel("名字:", buff.configData.Name); _ShowLabel("BuffId:", buff.configData.ID + ""); _ShowLabel("Level:", buff.configData.Level + ""); GUILayout.EndVertical(); } private void _DisplayBuffIcon(BaseBuff buff) { // Assets/Art/UI/Texture/Icon/BuffIcon/UI_Armor.png var displayIcon = buff.configData.BuffDisplayIcon; if (string.IsNullOrEmpty(displayIcon)) { GUILayout.Label("无图标"); return; } var iconPath = "Assets/Art_Out/UI/Texture/Icon/BuffIcon/" + displayIcon + ".png"; var icon = _LoadIcon(iconPath); if (icon == null) { EditorGUILayout.HelpBox("无法找到图标:" + displayIcon, MessageType.Error); } else { GUILayout.BeginHorizontal(); GUILayout.Label("图标:", GUILayout.Width(60)); var originWidth = icon.width; var originHeight = icon.height; var scaleSize = 40f / originWidth; GUILayout.Label(new GUIContent(icon), GUILayout.Width(originWidth * scaleSize), GUILayout.Height(originHeight * scaleSize)); GUILayout.EndHorizontal(); } } private void _ShowDebugArea(List cellIndexs) { var fakeParent = new GameObject("FakeParent").transform; for (int i = 0; i < cellIndexs.Count; i++) { var worldPos = AreaManager.instance.GetWorldPosByIndex(cellIndexs[i]); // 在对应位置创建一个球体 var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.SetParent(fakeParent); sphere.transform.position = worldPos; } } private void _ShowBelongBuild() { var belongBuild = _targetUnit.commonData.belongBuild; _ShowLabel("是否有所属建筑:", belongBuild != null ? "是" : "否"); if (belongBuild == null) return; _ShowLabel("所属建筑ID:", belongBuild.GetID() + ""); _ShowLabel("所属建筑名字:", belongBuild.configData.rawConfig.Name); } private void _ShowDamageRecord() { var levelNowTime = LevelManager.Instance.CurrentLevel.LevelTime; var recordStartTime = _targetUnit.damageRecord.beginTime; var passTime = levelNowTime - recordStartTime; GUILayout.Label("伤害记录", EditorStyles.boldLabel); _ShowLabel("伤害记录经过时间:", passTime + "秒"); _ShowLabel("总记录值:", _targetUnit.damageRecord.totalDamageCount.ToString("F2") + "点"); _ShowLabel("平均秒伤:", (_targetUnit.damageRecord.totalDamageCount / passTime).ToString("F2") + "点/秒"); if (GUILayout.Button("清零")) { _targetUnit.damageRecord.Clear(); } } private void _ShowInFight() { var unit = _targetUnit; _scrollPos1 = GUILayout.BeginScrollView(_scrollPos1, GUILayout.Width(350)); GUILayout.BeginVertical("box",GUILayout.Width(320)); _ShowLabel("ID:", unit.GetID() + ""); _ShowLabel("类型:", EGameUnitTypeUtils.GetStrByType(unit.gameunitType)); _ShowLabel("名字:", unit.debugShowInfo.name); _ShowLabel("配置ID:", unit.debugShowInfo.configId); _ShowLabel("阵营ID:", unit.commonData.troopId + ""); _ShowIcon(unit.debugShowInfo.iconPath); _ShowLabel("单位高度:", unit.fightData.unitHeight + ""); _ShowLabel("防御力:", unit.fightData.defense + ""); _ShowLabel("攻击力:", unit.fightData.attack + ""); _ShowLabel("穿甲级别:", unit.fightData.attackPowerLevel + ""); _ShowLabel("护甲级别:", unit.fightData.defensePowerLevel + ""); _ShowLabel("配置是否允许撤离:", unit.fightData.canEvacuate ? "是" : "否"); _ShowLabel("是否可以撤离:", unit.unitUIData.standEvacuatePoint != null ? "是" : "否"); _ShowLabel("移动速度:", unit.fightData.moveSpeed + ""); _ShowDamageRecord(); _ShowBelongBuild(); _ShowUnitExt(); if (GUILayout.Button("显示攻击范围")) { var centerCellIndex = unit.transData.cellIndex; var attackDistance = unit.fightData.attackDistance; var attackArea = AreaManager.instance.attackAreaManager.GetAttackArea(centerCellIndex, attackDistance); var isIgnoreBlock = unit.fightData.isAttackIgnoreBlock; var attackCells = isIgnoreBlock ? attackArea.totalCells : attackArea.canAttackCells; _ShowDebugArea(attackCells); } _ShowProgress("生命值:", unit.aliveData.currentHp, unit.aliveData.maxHp); _ShowProgress("护甲值:", unit.aliveData.currentShield, unit.aliveData.maxShield); _ShowProgress("士气值:", unit.aliveData.currentMorale, unit.aliveData.maxMorale); var allBuff = unit.buffManager.totalBuffList; _ShowLabel("Buff数量:", allBuff.Count + "个"); for (int i = 0; i < allBuff.Count; i++) { var buff = allBuff[i]; _ShowBuff(buff); } GUILayout.EndVertical(); GUILayout.EndScrollView(); } private void _ShowUnitExt() { switch (_targetUnit.gameunitType) { case EGameUnitType.Vehicle: _ShowVehicleExt(); break; } } private void _ShowVehicleExt() { var normalVehicle = _targetUnit as NormalVehicle; if (normalVehicle == null) { EditorGUILayout.HelpBox("当前单位不是普通载具", MessageType.Error); return; } _ShowLabel("炮台ID:", normalVehicle.battery.rawConfig.ID + ""); _ShowLabel("炮台名字:", normalVehicle.battery.rawConfig.NameRead); _ShowLabel("是否可以平A:", normalVehicle.battery.rawConfig.CanAttack ? "是" : "否"); _ShowLabel("攻击距离:", normalVehicle.fightData.attackDistance + "格"); } private void OnGUI() { if (_CheckCanShow()) { _ShowInFight(); } else { _ShowNotInFight(); // 关闭窗口 Close(); } } } }