zoukankan      html  css  js  c++  java
  • Unity 查找资源引用工具

    Unity 查找资源引用工具

    问题由来

    • 想查看组件被那些预设场景使用
    • 想查看图片被那些预设场景使用
    • 想查看资源被那些预设场景使用

    解决方法

    • 遍历项目中所有资源判断是否引用

    解决流程

    • 获取选中对象GUID
    • 使用Thread遍历项目中所有的资源
    • 判断资源是否包含GUID

    使用方式

    • 选中脚本
    • 右键
    • ZQ -> 工具 -> 查找资源引用

    源码

    using System.Collections.Generic;
    using System.IO;
    using System.Threading;
    using UnityEditor;
    using UnityEngine;
    
    public static class FindreAssetFerencesTool
    {
        static string[] assetGUIDs;
        static string[] assetPaths;
        static string[] allAssetPaths;
        static Thread thread;
    
        [MenuItem("ZQ/工具/查找资源引用", false)]
        [MenuItem("Assets/ZQ/工具/查找资源引用", false, 1)]
        static void FindreAssetFerencesMenu()
        {
            Debug.LogError("查找资源引用");
    
            if (Selection.assetGUIDs.Length == 0)
            {
                Debug.LogError("请先选择任意一个组件,再右键点击此菜单");
                return;
            }
    
            assetGUIDs = Selection.assetGUIDs;
    
            assetPaths = new string[assetGUIDs.Length];
    
            for (int i = 0; i < assetGUIDs.Length; i++)
            {
                assetPaths[i] = AssetDatabase.GUIDToAssetPath(assetGUIDs[0]);
            }
    
            allAssetPaths = AssetDatabase.GetAllAssetPaths();
    
            thread = new Thread(new ThreadStart(FindreAssetFerences));
            thread.Start();
        }
    
    
        static void FindreAssetFerences()
        {
            List<string> logInfo = new List<string>();
            string path;
            string log;
            for (int i = 0; i < allAssetPaths.Length; i++)
            {
                path = allAssetPaths[i];
    
                Debug.Log("正在查找文件:" + path);
    
                if (path.EndsWith(".prefab") || path.EndsWith(".unity"))
                {
                    string content = File.ReadAllText(path);
                    if (content == null)
                    {
                        continue;
                    }
    
                    for (int j = 0; j < assetGUIDs.Length; j++)
                    {
                        if (content.IndexOf(assetGUIDs[j]) > 0)
                        {
                            log = string.Format("{0} 引用了 {1}", path, assetPaths[j]);
                            logInfo.Add(log);
                        }
                    }
                }
            }
    
            for (int i = 0; i < logInfo.Count; i++)
            {
                Debug.LogError(logInfo[i]);
            }
    
            Debug.LogError("选择对象引用数量:" + logInfo.Count);
    
            Debug.LogError("查找完成");
        }
    }
    
  • 相关阅读:
    线程池小结(一)
    [转]ViewPager学习笔记(一)——懒加载
    [转]Private Libraries、Referenced Libraries、Dependency Libraries的区别
    关于context你必须知道的一切
    【转】在mac上配置安卓SDK
    【转】HTTP中的长连接和短连接分析
    中间件解析FDMEMTABLE.delta生成SQL的方法
    delphi 中配置文件的使用(*.ini)和TIniFile 用法
    Delphi 字符串加密与解密函数
    Delphi编写的等长加密与解密
  • 原文地址:https://www.cnblogs.com/zouqiang/p/12023787.html
Copyright © 2011-2022 走看看