NLDClient-yudde/ProjectNLD/Assets/Editor/ResCheck/ResCheckWindow.cs

150 lines
5.2 KiB
C#

using System;
using Framework;
using Gameplay;
using Gameplay.Utils;
using UnityEditor;
using UnityEngine;
namespace ResCheck
{
public class ResCheckWindow : EditorWindow
{
[MenuItem("Tools/*角色工具/角色资源检查", false, (int)NLDMenuID.CharacterResCheck)]
public static void ShowWindow()
{
_style_normal = new GUIStyle();
_style_normal.normal.textColor = Color.green;
_style_error = new GUIStyle();
_style_error.normal.textColor = Color.red;
var window = GetWindow<ResCheckWindow>();
window.titleContent = new UnityEngine.GUIContent("资源检查");
window.Show();
window.minSize = new Vector2(600, 300);
window._DoCheck();
}
private static GUIStyle _style_normal;
private static GUIStyle _style_error;
private string _sPlayersCheckResult = "";
private void _ShowSPlayers()
{
GUILayout.Label("角色展示模型检查:");
var checkPath = "Assets/Art/Character/Prefabs/Players_S";
GUILayout.Label(checkPath);
if (string.IsNullOrEmpty(_sPlayersCheckResult))
{
GUILayout.Label("检查结果:一切正常", _style_normal);
}
else
{
GUILayout.Label("检查结果:" + _sPlayersCheckResult, _style_error);
}
}
private string _playerIconCheckResult = "";
private void _ShowPlayerIcon()
{
GUILayout.Label("角色头像检查:");
var checkPath = "Assets/Art_Out/UI/Texture/Icon/HeadPic/";
GUILayout.Label(checkPath);
if (string.IsNullOrEmpty(_playerIconCheckResult))
{
GUILayout.Label("检查结果:一切正常", _style_normal);
}
else
{
GUILayout.Label("检查结果:" + _playerIconCheckResult, _style_error);
}
}
private string _playerPosterCheckResult = "";
private void _ShowPlayerPoster()
{
GUILayout.Label("角色海报检查:");
var checkPath = "Assets/Art/UI/Texture/Poster";
GUILayout.Label(checkPath);
if (string.IsNullOrEmpty(_playerPosterCheckResult))
{
GUILayout.Label("检查结果:一切正常", _style_normal);
}
else
{
GUILayout.Label("检查结果:" + _playerPosterCheckResult, _style_error);
}
}
private void _DoCheck()
{
_sPlayersCheckResult = "";
_playerIconCheckResult = "";
_playerPosterCheckResult = "";
var allPlayers = EditorTableManager.instance.tables.CharacterAttri.DataList;
for (int i = 0; i < allPlayers.Count; i++)
{
var player = allPlayers[i];
// 检查SPlayer
{
var skinData = EditorTableManager.instance.tables.SkinCfg.Get(Constants.DEFULT_SKINID, player.RoleID);
var path = PathEx.GetCharacterDisplayModelPath(skinData.NameID);
if (AssetDatabase.LoadAssetAtPath<GameObject>(path) == null)
{
_sPlayersCheckResult += player.RoleID + ",";
}
}
// 检查Icon
{
var iconPath = CommonUtils.GetDefaultHeadPathByUid((uint)player.RoleID);
if (AssetDatabase.LoadAssetAtPath<Sprite>(iconPath) == null)
{
_playerIconCheckResult += player.RoleID + ",";
}
}
// 检查Poster
{
var posterPath = CommonUtils.GetCharacterPicPath(player.RoleID, CommonUtils.ECharacterPicPathType.Poster);
if (AssetDatabase.LoadAssetAtPath<Sprite>(posterPath) == null)
{
_playerPosterCheckResult += player.RoleID + ",";
}
}
}
if (_sPlayersCheckResult.Length > 0)
{
_sPlayersCheckResult = _sPlayersCheckResult.Substring(0, _sPlayersCheckResult.Length - 1);
}
if (_playerIconCheckResult.Length > 0)
{
_playerIconCheckResult = _playerIconCheckResult.Substring(0, _playerIconCheckResult.Length - 1);
}
if (_playerPosterCheckResult.Length > 0)
{
_playerPosterCheckResult = _playerPosterCheckResult.Substring(0, _playerPosterCheckResult.Length - 1);
}
}
private void OnGUI()
{
EditorGUILayout.HelpBox("此工具用于检查资源是否缺失,请在检查结果中找到对应的资源并处理", MessageType.Warning);
_ShowSPlayers();
GUILayout.Space(10);
_ShowPlayerIcon();
GUILayout.Space(10);
_ShowPlayerPoster();
if (GUILayout.Button("刷新"))
{
_DoCheck();
}
}
}
}