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

241 lines
7.8 KiB
C#

using System;
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;
namespace FightDebug
{
public class FightDebugWindowV2 : EditorWindow
{
private Vector2 _scrollPos1;
private Vector2 _scrollPos2;
[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)
{
EditorGUILayout.LabelField("无技能管理器");
return;
}
if (skillManager.positiveSkill == null)
{
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 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);
_ShowWaveIndex(unit);
_ShowLabel("等级:", unit.commonData.level + "");
_ShowLabel("攻击力:", unit.fightData.attack + "");
_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.unitUIData.showEvacuateBtn)
{
if (GUILayout.Button("撤离", GUILayout.Height(40)))
{
EventManager.Instance.Send(EventManager.EventName.INFIGHT_UI_EVACUATE_UNIT, unit);
}
}
if (GUILayout.Button("显示详情", GUILayout.Height(40)))
{
SingleUnitWindow.ShowWindow(unit);
}
if (GUILayout.Button("直接杀死", GUILayout.Height(40)))
{
unit.ForceKill();
}
GUILayout.EndVertical();
}
private bool _CheckIconPathValid(string iconPath)
{
if (string.IsNullOrEmpty(iconPath))
{
return false;
}
if (!iconPath.StartsWith("Assets/"))
{
return false;
}
var iconObj = AssetDatabase.LoadAssetAtPath<Texture2D>(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<Texture2D>(defaultIconPath);
}
if (!iconPath.StartsWith("Assets/"))
{
return AssetDatabase.LoadAssetAtPath<Texture2D>(defaultIconPath);
}
var iconObj = AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath);
if (iconObj == null)
{
return AssetDatabase.LoadAssetAtPath<Texture2D>(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();
}
}
}
}