Unity3D-查找资源被那里引用

来源:互联网 发布:数据库是什么意思 编辑:程序博客网 时间:2024/04/30 00:19
using UnityEngine;using UnityEditor;using System.IO;using System.Linq;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.xuanyusong.com/archives/4207
转载请注明: 雨松MOMO 2016年06月29日 于 雨松MOMO程序研究院 发表

0 0
原创粉丝点击