转自:http://www.xuanyusong.com/archives/4207
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
using UnityEngine; using System.Collections; using UnityEditor; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; public class FindReferences { [MenuItem("Assets/Find References", false, 10)] static private void Find() { EditorSettings.serializationMode = SerializationMode.ForceText; string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (!string.IsNullOrEmpty(path)) { string guid = AssetDatabase.AssetPathToGUID(path); List<string> withoutExtensions = new List<string>() { ".prefab"/*, ".unity", ".mat", ".asset"*/ }; string[] files = Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray(); int startIndex = 0; EditorApplication.update = delegate () { string file = files[startIndex]; bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", file, (float)startIndex / (float)files.Length); if (Regex.IsMatch(File.ReadAllText(file), guid)) { Debug.Log(file, AssetDatabase.LoadAssetAtPath<Object>(GetRelativeAssetsPath(file))); } startIndex++; if (isCancel || startIndex >= files.Length) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; startIndex = 0; Debug.Log("匹配结束"); } }; } } [MenuItem("Assets/Find References", true)] static private bool VFind() { string path = AssetDatabase.GetAssetPath(Selection.activeObject); return (!string.IsNullOrEmpty(path)); } static private string GetRelativeAssetsPath(string path) { return "Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/'); } } |
- 本文固定链接: http://www.u3d8.com/?p=1977
- 转载请注明: 网虫虫 在 u3d8.com 发表过