discuz!cms
老妇性hqmaturetube,中出视频在线观看
匯寶盆 > 免費分享區(qū) > CG教程 > Unity > unity技巧:查找資源被哪里引用
unity技巧:查找資源被哪里引用

花落滿茵席

資源數(shù):26個

目錄CONTENTS

一、unity技巧:查找資源被哪里引用

在線預(yù)覽PREVIEW

unity技巧:查找資源被哪里引用

unity技巧:查找資源被哪里引用

Unity提供了一個方法 AssetDatabase.GetDependencies(),但是它只能查找這個資源引用了那些資源。 但是我想要的是查找某個資源被那些資源引用了,這是兩種相反的查找公式。 其實網(wǎng)上也有很多這樣的插件了,似乎代碼量都太多了。昨天晚上加班時腦洞打開,想到了一個簡單的方法。通過GUID全局搜索匹配,幾行代碼就能搞定。

右鍵隨便選擇一個資源,點擊 Find References,然后開始匹配資源。

匹配結(jié)束后會把匹配到的資源Log出來。以下代碼直接放到你的工程里就可以直接用。

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 withoutExtensions = new List(){".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("匹配結(jié)束");

                }

 

            };

        }

    }

 

    [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('\', '/');

    }

}

美中不足的地方就是查找速度了,其實正則表達式匹配的速度還是很快,慢的地方是File.ReadAllText(file) 如果大家有更好的辦法,歡迎推薦。

今天我無意發(fā)現(xiàn)了一個更快的方法,可惜只能在mac上用。比我上面的方法要快N倍啊,快的喪心病狂啊~歡迎大家用啊

using UnityEngine;

using System.Collections;

using UnityEditor;

using System.Collections.Generic;

public class FindProject {

#if UNITY_EDITOR_OSX

[MenuItem("Assets/Find References In Project", false, 2000)]

private static void FindProjectReferences()

{

string appDataPath = Application.dataPath;

string output

預(yù)覽結(jié)束,完整教程請 購買下載
資源參數(shù)
    教程名稱:unity技巧:查找資源被哪里引用 語       言:中文 頁數(shù)/時長: 4頁
    軟件版本: Unity 上傳時間:2017/05/22 價格:¥0
    文件格式: .rtf 文件大?。?50kb
下載

使用說明:

1. 本站所有資源(包括3D模型、CG教程、插件軟件、材質(zhì)貼圖、工程文件等)由設(shè)計師上傳,僅供學(xué)習(xí)、參考,請勿用于非法用途。

2. 本站付費類資源第一次需有償下載,重復(fù)下載不再收費。

3. 若出現(xiàn)3d模型類資源打不開,請確認您的軟件版本是否過低。

4. 本站歡迎設(shè)計師注冊開店,上傳作品進行交流、交易。

5. 如在使用過程中,遇到任何問題,請下拉頁面至評論區(qū)留言,或咨詢QQ:2353487910。

關(guān)鍵詞: unity技巧,unity教程

您還未登錄

全部評論: 0