{"id":624,"date":"2016-09-30T16:52:42","date_gmt":"2016-09-30T08:52:42","guid":{"rendered":"http:\/\/39.100.100.179\/?p=624"},"modified":"2016-10-11T09:26:37","modified_gmt":"2016-10-11T01:26:37","slug":"%e6%9f%a5%e6%89%be%e8%b5%84%e6%ba%90%e8%a2%ab%e5%93%aa%e9%87%8c%e5%bc%95%e7%94%a8%e4%ba%86","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=624","title":{"rendered":"\u67e5\u627e\u8d44\u6e90\u88ab\u54ea\u91cc\u5f15\u7528\u4e86"},"content":{"rendered":"<p>\u539f\u6587\u8f6c\u81ea\u96e8\u677e\uff1a<a href=\"http:\/\/www.xuanyusong.com\/archives\/4207\">http:\/\/www.xuanyusong.com\/archives\/4207<\/a><\/p>\n<p>Unity\u63d0\u4f9b\u4e86\u4e00\u4e2a\u65b9\u6cd5 AssetDatabase.GetDependencies()\uff0c\u4f46\u662f\u5b83\u53ea\u80fd\u67e5\u627e\u8fd9\u4e2a\u8d44\u6e90\u5f15\u7528\u4e86\u90a3\u4e9b\u8d44\u6e90\u3002 \u4f46\u662f\u6211\u60f3\u8981\u7684\u662f\u67e5\u627e\u67d0\u4e2a\u8d44\u6e90\u88ab\u90a3\u4e9b\u8d44\u6e90\u5f15\u7528\u4e86\uff0c\u8fd9\u662f\u4e24\u79cd\u76f8\u53cd\u7684\u67e5\u627e\u516c\u5f0f\u3002 \u5176\u5b9e\u7f51\u4e0a\u4e5f\u6709\u5f88\u591a\u8fd9\u6837\u7684\u63d2\u4ef6\u4e86\uff0c\u4f3c\u4e4e\u4ee3\u7801\u91cf\u90fd\u592a\u591a\u4e86\u3002\u6628\u5929\u665a\u4e0a\u52a0\u73ed\u65f6\u8111\u6d1e\u6253\u5f00\uff0c\u60f3\u5230\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u901a\u8fc7GUID\u5168\u5c40\u641c\u7d22\u5339\u914d\u3002\u3002\u51e0\u884c\u4ee3\u7801\u5c31\u80fd\u641e\u5b9a\uff5e\uff5e<\/p>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u53f3\u952e\u968f\u4fbf\u9009\u62e9\u4e00\u4e2a\u8d44\u6e90\uff0c\u70b9\u51fb Find References\u3002<a href=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2016\/09\/Snip20160629_2.png\" data-lightbox=\"image_lg\"><img title=\"\u67e5\u627e\u8d44\u6e90\u88ab\u54ea\u91cc\u5f15\u7528\u4e86 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\" alt=\"\u67e5\u627e\u8d44\u6e90\u88ab\u54ea\u91cc\u5f15\u7528\u4e86 - \u7b2c1\u5f20  | u3d8\u6280\u672f\u5206\u4eab\"  loading=\"lazy\" class=\"aligncenter size-full wp-image-625\"  data-src=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2016\/09\/Snip20160629_2.png\" width=\"477\" height=\"347\" srcset=\"http:\/\/www.u3d8.com\/wp-content\/uploads\/2016\/09\/Snip20160629_2.png 477w, http:\/\/www.u3d8.com\/wp-content\/uploads\/2016\/09\/Snip20160629_2-300x218.png 300w\" sizes=\"(max-width: 477px) 100vw, 477px\" \/><\/a><\/p>\n<p>\u7136\u540e\u5f00\u59cb\u5339\u914d\u8d44\u6e90\u3002<\/p>\n<p>\u5339\u914d\u7ed3\u675f\u540e\u4f1a\u628a\u5339\u914d\u5230\u7684\u8d44\u6e90Log\u51fa\u6765\u3002\u4ee5\u4e0b\u4ee3\u7801\u76f4\u63a5\u653e\u5230\u4f60\u7684\u5de5\u7a0b\u91cc\u5c31\u53ef\u4ee5\u76f4\u63a5\u7528\u3002<\/p>\n<pre class=\"lang:c# decode:true \">using UnityEngine;\r\nusing System.Collections;\r\nusing UnityEditor;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Text.RegularExpressions;\r\nusing System.Collections.Generic;\r\n \r\npublic class FindReferences\r\n{\r\n  \r\n    [MenuItem(\"Assets\/Find References\", false, 10)]\r\n    static private void Find()\r\n    {\r\n        EditorSettings.serializationMode = SerializationMode.ForceText;\r\n        string path = AssetDatabase.GetAssetPath(Selection.activeObject);\r\n        if (!string.IsNullOrEmpty(path))\r\n        {\r\n            string guid = AssetDatabase.AssetPathToGUID(path);\r\n            List&lt;string&gt; withoutExtensions = new List&lt;string&gt;(){\".prefab\",\".unity\",\".mat\",\".asset\"};\r\n            string[] files = Directory.GetFiles(Application.dataPath, \"*.*\", SearchOption.AllDirectories)\r\n                .Where(s =&gt; withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray();\r\n            int startIndex = 0;\r\n \r\n            EditorApplication.update = delegate()\r\n            {\r\n                string file = files[startIndex];\r\n            \r\n                 bool isCancel = EditorUtility.DisplayCancelableProgressBar(\"\u5339\u914d\u8d44\u6e90\u4e2d\", file, (float)startIndex \/ (float)files.Length);\r\n \r\n                if (Regex.IsMatch(File.ReadAllText(file), guid))\r\n                {\r\n                    Debug.Log(file, AssetDatabase.LoadAssetAtPath&lt;Object&gt;(GetRelativeAssetsPath(file)));\r\n                }\r\n \r\n                startIndex++;\r\n                if (isCancel || startIndex &gt;= files.Length)\r\n                {\r\n                    EditorUtility.ClearProgressBar();\r\n                    EditorApplication.update = null;\r\n                    startIndex = 0;\r\n                    Debug.Log(\"\u5339\u914d\u7ed3\u675f\");\r\n                }\r\n \r\n            };\r\n        }\r\n    }\r\n \r\n    [MenuItem(\"Assets\/Find References\", true)]\r\n    static private bool VFind()\r\n    {\r\n        string path = AssetDatabase.GetAssetPath(Selection.activeObject);\r\n        return (!string.IsNullOrEmpty(path));\r\n    }\r\n \r\n    static private string GetRelativeAssetsPath(string path)\r\n    {\r\n        return \"Assets\" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), \"\").Replace('\\\\', '\/');\r\n    }\r\n}<\/pre>\n<p>\u7f8e\u4e2d\u4e0d\u8db3\u7684\u5730\u65b9\u5c31\u662f\u67e5\u627e\u901f\u5ea6\u4e86\u3002\u3002\u5176\u5b9e\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u7684\u901f\u5ea6\u8fd8\u662f\u5f88\u5feb\uff0c\u6162\u7684\u5730\u65b9\u662fFile.ReadAllText(file) \u5982\u679c\u5927\u5bb6\u6709\u66f4\u597d\u7684\u529e\u6cd5\uff0c\u6b22\u8fce\u63a8\u8350\uff5e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u8f6c\u81ea\u96e8\u677e\uff1ahttp:\/\/www.xuanyusong.com\/archive &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=624\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,23],"tags":[176,175],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/624"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=624"}],"version-history":[{"count":3,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions"}],"predecessor-version":[{"id":709,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/624\/revisions\/709"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=624"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}