146 lines
4.3 KiB
C#
146 lines
4.3 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections.Concurrent;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.IO;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using UnityEditor;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public sealed class FilePathChecker : EditorWindow
|
||
|
|
{
|
||
|
|
public const int MaxPathLen = 255;
|
||
|
|
public const int MaxFileNameLen = 63;
|
||
|
|
private List<string> files;
|
||
|
|
private int curmaxPathLen = 180;
|
||
|
|
private int curmaxFileNameLen = 50;
|
||
|
|
private ConcurrentBag<string> showFiles = new();
|
||
|
|
|
||
|
|
private Vector2 silderPos = Vector2.zero;
|
||
|
|
|
||
|
|
private Tuple<string, bool>[] filters = new Tuple<string, bool>[]
|
||
|
|
{
|
||
|
|
new ("路径长度", false),
|
||
|
|
new ("文件名长度", true),
|
||
|
|
new ("材质", true),
|
||
|
|
new ("模型", false),
|
||
|
|
new ("场景", false),
|
||
|
|
new ("其它",false),
|
||
|
|
};
|
||
|
|
|
||
|
|
[MenuItem("Window/路径检查")]
|
||
|
|
private static void OpenFilePathCheckerWindow()
|
||
|
|
{
|
||
|
|
var wnd = GetWindow<FilePathChecker>();
|
||
|
|
wnd.titleContent = new GUIContent("资源路径检查");
|
||
|
|
}
|
||
|
|
|
||
|
|
private FilePathChecker()
|
||
|
|
{
|
||
|
|
ConcurrentBag<string> fileBag = new ConcurrentBag<string>();
|
||
|
|
Parallel.ForEach(Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories), item =>
|
||
|
|
{
|
||
|
|
if (item.EndsWith(".meta"))
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
fileBag.Add("Assets" + item.Replace('\\', '/').Replace(Application.dataPath.Replace('\\', '/'), ""));
|
||
|
|
});
|
||
|
|
|
||
|
|
files = fileBag.ToList();
|
||
|
|
FilterResult();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void FilterResult()
|
||
|
|
{
|
||
|
|
showFiles.Clear();
|
||
|
|
Parallel.ForEach(files, f =>
|
||
|
|
{
|
||
|
|
if (filters[0].Item2 && f.Length > curmaxPathLen || filters[1].Item2 && Path.GetFileNameWithoutExtension(f).Length > curmaxFileNameLen)
|
||
|
|
{
|
||
|
|
if (filters[2].Item2 && f.EndsWith(".mat"))
|
||
|
|
{
|
||
|
|
showFiles.Add(f);
|
||
|
|
}
|
||
|
|
else if (filters[3].Item2 && (f.ToLower() is string s && (s.EndsWith(".fbx") || s.EndsWith(".obj"))))
|
||
|
|
{
|
||
|
|
showFiles.Add(f);
|
||
|
|
}
|
||
|
|
else if (filters[4].Item2 && (f.ToLower() is string s1 && (s1.EndsWith(".unity") || s1.EndsWith(".scene"))))
|
||
|
|
{
|
||
|
|
showFiles.Add(f);
|
||
|
|
}
|
||
|
|
else if (filters[5].Item2)
|
||
|
|
{
|
||
|
|
showFiles.Add(f);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnGUI()
|
||
|
|
{
|
||
|
|
EditorGUILayout.BeginVertical();
|
||
|
|
|
||
|
|
EditorGUILayout.BeginHorizontal();
|
||
|
|
EditorGUILayout.LabelField("路径长度");
|
||
|
|
var _curmaxPathLen = EditorGUILayout.IntSlider(curmaxPathLen, 16, MaxPathLen);
|
||
|
|
if (_curmaxPathLen != curmaxPathLen)
|
||
|
|
{
|
||
|
|
curmaxPathLen = _curmaxPathLen;
|
||
|
|
FilterResult();
|
||
|
|
}
|
||
|
|
EditorGUILayout.EndHorizontal();
|
||
|
|
|
||
|
|
EditorGUILayout.BeginHorizontal();
|
||
|
|
EditorGUILayout.LabelField("文件名长度");
|
||
|
|
var _curmaxFileNameLen = EditorGUILayout.IntSlider(curmaxFileNameLen, 1, MaxFileNameLen);
|
||
|
|
if (_curmaxFileNameLen != curmaxFileNameLen)
|
||
|
|
{
|
||
|
|
curmaxFileNameLen = _curmaxFileNameLen;
|
||
|
|
FilterResult();
|
||
|
|
}
|
||
|
|
|
||
|
|
EditorGUILayout.EndHorizontal();
|
||
|
|
EditorGUILayout.Space();
|
||
|
|
EditorGUILayout.BeginHorizontal();
|
||
|
|
|
||
|
|
for (int i = 0; i < filters.Length; i++)
|
||
|
|
{
|
||
|
|
var filter = filters[i];
|
||
|
|
var v = EditorGUILayout.Toggle(filter.Item1, filter.Item2);
|
||
|
|
if (v != filter.Item2)
|
||
|
|
{
|
||
|
|
filters[i] = new Tuple<string, bool>(filter.Item1, v);
|
||
|
|
FilterResult();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
EditorGUILayout.EndHorizontal();
|
||
|
|
EditorGUILayout.Space();
|
||
|
|
|
||
|
|
silderPos = EditorGUILayout.BeginScrollView(silderPos);
|
||
|
|
foreach (var item in showFiles)
|
||
|
|
{
|
||
|
|
FileItem(item);
|
||
|
|
}
|
||
|
|
|
||
|
|
EditorGUILayout.EndScrollView();
|
||
|
|
|
||
|
|
EditorGUILayout.EndVertical();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
private void FileItem(string path)
|
||
|
|
{
|
||
|
|
EditorGUILayout.BeginHorizontal();
|
||
|
|
EditorGUILayout.LabelField(path);
|
||
|
|
if (GUILayout.Button("Ping"))
|
||
|
|
{
|
||
|
|
EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path));
|
||
|
|
}
|
||
|
|
EditorGUILayout.EndHorizontal();
|
||
|
|
}
|
||
|
|
}
|