{"id":20150268,"url":"https://github.com/akof1314/unityassetdanshari","last_synced_at":"2025-04-05T20:07:46.953Z","repository":{"id":41053270,"uuid":"147473074","full_name":"akof1314/UnityAssetDanshari","owner":"akof1314","description":"Unity Asset Danshari 资源断舍离","archived":false,"fork":false,"pushed_at":"2024-09-05T00:27:17.000Z","size":12202,"stargazers_count":318,"open_issues_count":0,"forks_count":92,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-29T18:09:05.668Z","etag":null,"topics":["unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akof1314.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-05T06:50:18.000Z","updated_at":"2025-03-25T07:04:17.000Z","dependencies_parsed_at":"2024-11-14T00:15:31.926Z","dependency_job_id":null,"html_url":"https://github.com/akof1314/UnityAssetDanshari","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akof1314%2FUnityAssetDanshari","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akof1314%2FUnityAssetDanshari/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akof1314%2FUnityAssetDanshari/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akof1314%2FUnityAssetDanshari/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akof1314","download_url":"https://codeload.github.com/akof1314/UnityAssetDanshari/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393570,"owners_count":20931812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["unity"],"created_at":"2024-11-13T22:51:16.331Z","updated_at":"2025-04-05T20:07:46.929Z","avatar_url":"https://github.com/akof1314.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity Asset Danshari 资源断舍离\n\nUnityAssetDanshari 是一个 Unity 资源清理重复以及引用被引用查找工具。内核使用 ripgrep 文本搜索工具，使得资源查找速度飞快。\nUnityAssetDanshari is a Unity merge duplicated assets and find reference tool.\n\n## 背景\n在游戏制作过程，随着资源越来越多，可能存在重复的资源，也需要删除不被使用的资源，但是如果使用 Unity 的 API 去查找引用关系将会很耗时间，另外，资源都是对应使用的，比如 UI 图片只在 UI 界面上进行引用，所以不需要去查找其他地方是否引用到。\n\n## 安装\n\n- 通过【Package Manager】包管理器，添加git URL地址：https://github.com/akof1314/UnityAssetDanshari.git\n\n## 首次使用\n\n提前准备 ripgrep 的二进制文件[https://github.com/BurntSushi/ripgrep/releases](https://github.com/BurntSushi/ripgrep/releases)， 也可以直接使用示例工程自带的 Windows 版二进制文件。\n\n![](./Documentation~/Images/MainWindows.png)\n\n工具入口为菜单栏【美术工具/资源断舍离】，如果导入了示例工程，则打开会包含默认的配置项。点击右上角的`ripgrep`按钮，可以进行配置`ripgrep路径`。如果没有配置`ripgrep路径`则会使用默认的普通文件搜索方式，速度相当慢。\n\n## 默认配置项\n\n工具配置文件保存在`\"UserSettings/AssetDanshariSetting.asset\"`，为了能够团队默认能够有一样的配置内容，可以绑定创建配置事件。\n\n```csharp\n[InitializeOnLoadMethod]\nprivate static void InitOnLoad()\n{\n    AssetDanshariHandler.onCreateSetting += OnCreateSetting;\n    AssetDanshariHandler.onDependenciesLoadDataMore += OnDependenciesLoadDataMore;\n    AssetDanshariHandler.onDependenciesContextDraw += OnDependenciesContextDraw;\n}\n```\n\n用户自定义配置事件，可以指定rg到工程的统一外部工具路径。\n\n```csharp\nprivate static AssetDanshariSetting OnCreateSetting()\n{\n    var setting = ScriptableObject.CreateInstance\u003cAssetDanshariSetting\u003e();\n    setting.ripgrepPath = \"Assets/Samples/Asset Danshari/1.0.0/Simple Demo/rg/rg.exe\";\n    setting.assetReferenceInfos.Add(new AssetDanshariSetting.AssetReferenceInfo()\n    {\n        referenceFolder = \"\\\"Assets/Samples/Asset Danshari/1.0.0/Simple Demo/Prefab\\\" || \\\"Assets/Samples/Asset Danshari/1.0.0/Simple Demo/Samples\\\"\",\n        assetFolder = \"\\\"Assets/Samples/Asset Danshari/1.0.0/Simple Demo/PNG\\\"\",\n        assetCommonFolder = \"\\\"Assets/Samples/Asset Danshari/1.0.0/Simple Demo/PNG/Common\\\"\"\n    });\n    return setting;\n}\n```\n\n## 检查列表\n\n列表按资源的使用环境进行分组。\n- 将`Project`窗口里的文件或文件夹路径拖到目录框\n- 多路径方式可以多选后再拖入，也可以按住`Ctrl`进行添加\n- 【公共资源目录】是用来放公共资源的路径，比如 UI 图片资源存在被多个界面引用的时候，可以快捷操作移动资源到公共目录\n\n## 引用查找\n\n对【引用目录】下的每个资源进行检查是否引用到了【资源目录】下的资源，比如 UI 界面预制引用 UI 图片。\n\n![](https://img-blog.csdnimg.cn/20181110160138165.png)\n\n双击项，可以自动在【Project】窗口定位到资源。\n\n## 被引用查找\n\n对【资源目录】下的每个资源进行分析，看是否被【引用目录】下的资源进行引用，比如 UI 图片被哪些 UI 界面进行引用。\n\n![](https://img-blog.csdnimg.cn/20181110160334244.png)\n\n【删除选中资源】菜单项功能，是直接对资源进行删除，当发现没有被使用到时，可以这样快捷删除资源。\n\n右上角【过滤为空】按钮，可以过滤显示没有被使用的资源，方便快速查看。\n\n## 检查重复\n\n对资源文件进行逐块 Hash128 检查重复，再对重复的资源进行操作。\n\n![](https://img-blog.csdnimg.cn/20181110160230435.png)\n\n\n【资源被引用查找】菜单项功能，是在【被引用查找】窗口里定位到此资源的使用情况，方便进行决定保留还是删除，注意，需要先打开了【被引用查找】窗口才可以定位到。\n\n【仅使用此资源，其余删除】菜单项功能，将会删除其余重复的资源，并且将所有引用到这些删除资源的地方都改成引用保留的那一个。\n\n当美术对同一资源进行切图两次，会导致文件 Hash128 值不一样，就无法被工具所检测到。出现这种情况的时候，肉眼发现到两个资源其实是一样的，可以在这个窗口右上角点击【手动添加】按钮。\n\n![](https://img-blog.csdnimg.cn/20181110160308811.png)\n\n手动进行添加资源路径，将资源文件拖动到文本框，再点击【确定】。就会自动定位到新增的数据，接着就可以按处理重复资源一样进行操作。\n\n## 扩展被引用来源\n\n![](./Documentation~/Images/CustomDependSource.png)\n\n资源不止被另外的资源直接引用，还可能配置在表里、代码里进行动态使用，在这种情况下，可以绑定`onDependenciesLoadDataMore`事件，对传入的资源路径进行判别处理，参照示例工程代码。\n\n## API 调用\n\n每次需要拖曳文件/目录到窗口可能会觉得不方便，或者想要集成到自己的工具里，可以使用公开的 API，调用三个不同的窗口。\n\n```csharp\n/// \u003csummary\u003e\n/// 显示引用查找窗口\n/// \u003c/summary\u003e\n/// \u003cparam name=\"refPaths\"\u003e引用的文件、目录集合\u003c/param\u003e\n/// \u003cparam name=\"resPaths\"\u003e资源的文件、目录集合\u003c/param\u003e\n/// \u003cparam name=\"commonPaths\"\u003e公共资源目录集合\u003c/param\u003e\npublic static void DisplayReferenceWindow(string refPaths, string resPaths, string commonPaths = \"\")\n\n/// \u003csummary\u003e\n/// 显示被引用查找窗口\n/// \u003c/summary\u003e\npublic static void DisplayDependenciesWindow(string refPaths, string resPaths, string commonPaths = \"\")\n\n/// \u003csummary\u003e\n/// 显示重复资源检查窗口\n/// \u003c/summary\u003e\npublic static void DisplayDuplicateWindow(string refPaths, string resPaths, string commonPaths = \"\")\n```\n\n![](./Documentation~/Images/ApiDemo.gif)\n\n示例工程举例实现右键资源文件来查看被引用情况。\n\n```csharp\n[MenuItem(\"Assets/查找该资源的被引用\")]\nprivate static void FindReferenceAll()\n{\n    string[] paths = new string[Selection.objects.Length];\n    for (var i = 0; i \u003c Selection.objects.Length; i++)\n    {\n        var o = Selection.objects[i];\n        paths[i] = AssetDatabase.GetAssetPath(o);\n    }\n\n    AssetDanshariWindow.DisplayDependenciesWindow(\n        AssetDanshariUtility.PathArrayToStr(new []{\"Assets\"}),\n        AssetDanshariUtility.PathArrayToStr(paths));\n}\n```\n\n## 当前限制\n\n二进制配置文件，如：Lighting data, Terrain data 之类，无法查找其引用资源关系。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakof1314%2Funityassetdanshari","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakof1314%2Funityassetdanshari","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakof1314%2Funityassetdanshari/lists"}