Files
MinFt/Client/Assets/Editor/SearchWindows.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

230 lines
9.2 KiB
C#

using DG.Tweening.Plugins.Core.PathCore;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class SearchWindows : EditorWindow
{
[MenuItem("Assets/Search Reference")]
public static void OpenWindow()
{
(EditorWindow.GetWindow(typeof(SearchWindows)) as SearchWindows).Search = Selection.activeObject;
}
public static string assetSrcFolderPath;
public static string assetSrcFolderAllPath;
public Object Search;
List<Object> SearchOut = new List<Object>();
List<Object> SearchOutAll = new List<Object>();
List<Object> SearchOutOne = new List<Object>();
Vector2 scrollPosition1;
Vector2 scrollPosition2;
private void OnGUI()
{
SearchOne();
SearchAllNo();
SearchAllIn();
}
void SearchOne()
{
EditorGUILayout.BeginHorizontal();
GUILayout.Label("Search:", EditorStyles.boldLabel);
Search = EditorGUILayout.ObjectField(Search, typeof(Object), true);
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("Search!"))
{
if (Search != null)
{
SearchOutOne.Clear();
List<string> @out = new List<string>();
string path = AssetDatabase.GetAssetPath(Search);
if (!string.IsNullOrEmpty(path))
{
string guid = AssetDatabase.AssetPathToGUID(path);
string meta = AssetDatabase.GetTextMetaFilePathFromAssetPath(path);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = Application.dataPath;
p.StartInfo.FileName = $"rg ";
p.StartInfo.Arguments = $"-l {guid}";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
while (!p.StandardOutput.EndOfStream)
{
string line = $"Assets/{p.StandardOutput.ReadLine().Replace("\\", "/")}";
if (line != meta)
{
var item = AssetDatabase.LoadAssetAtPath(line, typeof(Object));
if (item != null)
SearchOutOne.Add(item);
}
}
}
}
}
if (SearchOutOne.Count > 0)
{
scrollPosition2 = EditorGUILayout.BeginScrollView(scrollPosition2);
GUILayout.Label($"Out: {SearchOutOne.Count}", EditorStyles.boldLabel);
foreach (var o in SearchOutOne)
{
EditorGUILayout.ObjectField(o, typeof(Object), true);
}
EditorGUILayout.EndScrollView();
}
}
void SearchAllNo()
{
EditorGUILayout.BeginHorizontal();
//assetSrcFolderPath = EditorGUILayout.TextField(assetSrcFolderPath);
//if (GUILayout.Button("选择"))
//{
// assetSrcFolderPath = EditorUtility.OpenFolderPanel("选择文件夹", assetSrcFolderPath, "");
//}
// 获取拖进去的文件夹路径
if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (Event.current.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
foreach (string path in DragAndDrop.paths)
{
if (Directory.Exists(path))
{
assetSrcFolderPath = path;
break;
}
}
}
}
// 显示文件夹路径
EditorGUILayout.LabelField("Folder Path: " + assetSrcFolderPath);
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("开始查询没有被引用") && assetSrcFolderPath != null)
{
SearchOut.Clear();
var files = Directory.GetFiles(assetSrcFolderPath, "*.*").Where(file => !file.EndsWith(".meta")).ToArray();
bool isHas = false;
foreach (var path in files)
{
if (!string.IsNullOrEmpty(path))
{
isHas = false;
string guid = AssetDatabase.AssetPathToGUID(path);
string meta = AssetDatabase.GetTextMetaFilePathFromAssetPath(path);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = Application.dataPath;
p.StartInfo.FileName = $"rg ";
p.StartInfo.Arguments = $"-l {guid}";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
while (!p.StandardOutput.EndOfStream)
{
string line = $"Assets/{p.StandardOutput.ReadLine().Replace("\\", "/")}";
if (line != meta && !line.Contains("AssetGroups"))
{
var item = AssetDatabase.LoadAssetAtPath(line, typeof(Object));
if (item != null)
{
isHas = true;
break;
}
}
}
if (!isHas)
{
SearchOut.Add(AssetDatabase.LoadAssetAtPath(path, typeof(Object)));
}
}
}
}
if (SearchOut.Count > 0)
{
scrollPosition1 = EditorGUILayout.BeginScrollView(scrollPosition1);
GUILayout.Label($"Out: {SearchOut.Count}", EditorStyles.boldLabel);
foreach (var o in SearchOut)
{
EditorGUILayout.ObjectField(o, typeof(Object), true);
}
EditorGUILayout.EndScrollView();
}
}
void SearchAllIn()
{
EditorGUILayout.BeginHorizontal();
// 获取拖进去的文件夹路径
if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)
{
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
if (Event.current.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
foreach (string path in DragAndDrop.paths)
{
if (Directory.Exists(path))
{
assetSrcFolderAllPath = path;
break;
}
}
}
}
// 显示文件夹路径
EditorGUILayout.LabelField("Folder Path: " + assetSrcFolderAllPath);
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("开始查询引用") && assetSrcFolderAllPath != null)
{
SearchOutAll.Clear();
var files = Directory.GetFiles(assetSrcFolderAllPath, "*.*").Where(file => !file.EndsWith(".meta")).ToArray();
foreach (var path in files)
{
if (!string.IsNullOrEmpty(path))
{
string guid = AssetDatabase.AssetPathToGUID(path);
string meta = AssetDatabase.GetTextMetaFilePathFromAssetPath(path);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = Application.dataPath;
p.StartInfo.FileName = $"rg ";
p.StartInfo.Arguments = $"-l {guid}";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
while (!p.StandardOutput.EndOfStream)
{
string line = $"Assets/{p.StandardOutput.ReadLine().Replace("\\", "/")}";
if (line != meta && !line.Contains("AssetGroups"))
{
var item = AssetDatabase.LoadAssetAtPath(line, typeof(Object));
if (item != null)
{
SearchOutAll.Add(item);
Debug.Log($"<color=red>SearchOutAll: {item.name} ==> {path}</color>");
}
}
}
}
}
}
if (SearchOutAll.Count > 0)
{
scrollPosition1 = EditorGUILayout.BeginScrollView(scrollPosition1);
GUILayout.Label($"Out: {SearchOutAll.Count}", EditorStyles.boldLabel);
foreach (var o in SearchOutAll)
{
EditorGUILayout.ObjectField(o, typeof(Object), true);
}
EditorGUILayout.EndScrollView();
}
}
}