NLDClient-yudde/ProjectNLD/Assets/Editor/FightDebug/SingleUnitSearchLightDebugP...

217 lines
7.2 KiB
C#

using System.Collections.Generic;
using System.Text;
using cfg.LevelCfg;
using GamePlay.Building.Fight.Impl.Builds;
using Gameplay.Character;
using Gameplay.Unit;
using UnityEditor;
using UnityEngine;
namespace FightDebug
{
public class SingleUnitSearchLightDebugPanel
{
private int _targetCellIndex = -1;
private string _targetError = "";
public void Reset()
{
_targetCellIndex = -1;
_targetError = "";
}
public void Draw(GameUnit unit)
{
var searchLight = unit as UnitBuildSearchLight;
if (searchLight == null)
{
return;
}
_DrawSearchLight(searchLight);
}
private void _DrawSearchLight(UnitBuildSearchLight searchLight)
{
GUILayout.BeginVertical("box");
GUILayout.Label("探照灯调试", EditorStyles.boldLabel);
var enterUnit = searchLight.enterUnit;
var canControl = enterUnit != null && enterUnit.commonData.troopId == ETroopsId.Self;
var cellIndexes = searchLight.DebugLightUpCellIndexes;
var cellIndexListText = _BuildCellIndexListText(cellIndexes);
_ShowLabel("建筑阵营:", _GetTroopName(searchLight.commonData.troopId));
_ShowLabel("进驻单位:", enterUnit != null ? enterUnit.GetDescString() : "无");
if (enterUnit != null)
{
_ShowLabel("进驻单位ID:", enterUnit.GetID() + "", true);
_ShowLabel("进驻单位阵营:", _GetTroopName(enterUnit.commonData.troopId));
}
_ShowLabel("允许调试控制:", canControl ? "是" : "否");
_ShowLabel("中心格子数量:", searchLight.DebugLightUpCellCount + "");
_ShowLabel("中心格子列表:", cellIndexListText, true);
_ShowLabel("当前中心格子:", searchLight.nowLookCellIndex + "", true);
_ShowLabel("当前索引:", searchLight.DebugCurrentIndex + "");
_ShowLabel("上一个中心格子:", searchLight.DebugLastLightUpCellIndex + "");
_ShowLabel("待目标格子:", searchLight.DebugControlTargetCellIndex + "", true);
_ShowLabel("照亮范围:", searchLight.lightUpDistance + "格");
_ShowLabel("停留时间:", searchLight.DebugPosStayTime.ToString("F2") + "秒");
_ShowLabel("当前停留计时:", searchLight.DebugNowStayTime.ToString("F2") + "秒");
_ShowLabel("循环模式:", _GetLoopTypeName(searchLight.DebugLoopType));
_ShowLabel("当前旋转方向:", _GetRotateDirName(searchLight.DebugNowRotateDir));
if (_targetCellIndex < 0 && searchLight.nowLookCellIndex >= 0)
{
_targetCellIndex = searchLight.nowLookCellIndex;
}
GUILayout.BeginHorizontal();
GUILayout.Label("目标中心格子:", GUILayout.Width(140));
_targetCellIndex = EditorGUILayout.IntField(_targetCellIndex);
GUILayout.EndHorizontal();
EditorGUI.BeginDisabledGroup(!canControl);
if (GUILayout.Button("设置目标位置"))
{
_TrySetTarget(searchLight);
}
EditorGUI.EndDisabledGroup();
if (!canControl)
{
EditorGUILayout.HelpBox("仅当探照灯内部进驻己方单位时允许设置目标位置。", MessageType.Info);
}
if (!string.IsNullOrEmpty(_targetError))
{
EditorGUILayout.HelpBox(_targetError, MessageType.Warning);
}
GUILayout.EndVertical();
}
private void _TrySetTarget(UnitBuildSearchLight searchLight)
{
_targetError = "";
var enterUnit = searchLight.enterUnit;
if (enterUnit == null)
{
_targetError = "探照灯内部没有进驻单位,无法设置目标位置。";
return;
}
if (enterUnit.commonData.troopId != ETroopsId.Self)
{
_targetError = "探照灯内部不是己方单位,无法设置目标位置。";
return;
}
if (!_ContainsCellIndex(searchLight.DebugLightUpCellIndexes, _targetCellIndex))
{
_targetError = "目标格子不在探照灯可照亮中心格子列表内。";
return;
}
searchLight.SetLightUpCellIndex(_targetCellIndex);
}
private void _ShowLabel(string label, string value, bool showCopy = false)
{
GUILayout.BeginHorizontal();
GUILayout.Label(label, GUILayout.Width(140));
GUILayout.Label(value);
if (showCopy)
{
if (GUILayout.Button("复制", GUILayout.Width(60)))
{
EditorGUIUtility.systemCopyBuffer = value;
}
}
GUILayout.EndHorizontal();
}
private bool _ContainsCellIndex(IReadOnlyList<int> cellIndexes, int cellIndex)
{
if (cellIndexes == null)
{
return false;
}
for (int i = 0; i < cellIndexes.Count; i++)
{
if (cellIndexes[i] == cellIndex)
{
return true;
}
}
return false;
}
private string _BuildCellIndexListText(IReadOnlyList<int> cellIndexes)
{
if (cellIndexes == null || cellIndexes.Count <= 0)
{
return "";
}
var builder = new StringBuilder(cellIndexes.Count * 4);
for (int i = 0; i < cellIndexes.Count; i++)
{
if (i > 0)
{
builder.Append(",");
}
builder.Append(cellIndexes[i]);
}
return builder.ToString();
}
private string _GetTroopName(int troopId)
{
switch (troopId)
{
case ETroopsId.Self:
return "己方";
case ETroopsId.Enemy:
return "敌方";
case ETroopsId.Neutral:
return "中立";
default:
return "未知(" + troopId + ")";
}
}
private string _GetLoopTypeName(UnitBuildSearchLight.ELooperType loopType)
{
switch (loopType)
{
case UnitBuildSearchLight.ELooperType.Loop:
return "循环";
case UnitBuildSearchLight.ELooperType.PingPong:
return "折返";
default:
return "未知(" + loopType + ")";
}
}
private string _GetRotateDirName(UnitBuildSearchLight.ERotateDir rotateDir)
{
switch (rotateDir)
{
case UnitBuildSearchLight.ERotateDir.Left:
return "左";
case UnitBuildSearchLight.ERotateDir.Right:
return "右";
default:
return rotateDir.ToString();
}
}
}
}