{"id":19831861,"url":"https://github.com/ialex32x/unityfs","last_synced_at":"2025-05-01T16:32:32.663Z","repository":{"id":38806796,"uuid":"174104203","full_name":"ialex32x/unityfs","owner":"ialex32x","description":"一个热更新框架","archived":true,"fork":false,"pushed_at":"2022-12-09T07:39:12.000Z","size":1011,"stargazers_count":80,"open_issues_count":5,"forks_count":26,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-15T23:41:30.658Z","etag":null,"topics":["assetbundle","resource-management","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/ialex32x.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-06T08:31:30.000Z","updated_at":"2025-03-15T06:28:12.000Z","dependencies_parsed_at":"2023-01-25T19:31:01.361Z","dependency_job_id":null,"html_url":"https://github.com/ialex32x/unityfs","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ialex32x%2Funityfs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ialex32x%2Funityfs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ialex32x%2Funityfs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ialex32x%2Funityfs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ialex32x","download_url":"https://codeload.github.com/ialex32x/unityfs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251907014,"owners_count":21663197,"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":["assetbundle","resource-management","unity"],"created_at":"2024-11-12T11:35:27.916Z","updated_at":"2025-05-01T16:32:30.986Z","avatar_url":"https://github.com/ialex32x.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unityfs\r\n\r\n**与旧版本(0.9.4)不兼容**\r\n\r\n提供一个轻量实用的资源和文件访问层, 简化资源热更新项目的开发流程. \r\n开发过程中可以使用编辑器模式直接访问工程内的任意资源, 并在发布时无缝切换到通过 AssetBundle 访问资源.\r\n配置文件与脚本代码独立压缩打包, 运行期直接读取压缩包访问文件, 且不受 Unity 文件命名限制.\r\n\r\n# 目标特性\r\n* 资源管理\r\n    * 异步加载资源/场景\r\n    * 自动管理资源加载/卸载\r\n    * 自动管理资源更新\r\n    * 资源对象池\r\n* 下载\r\n    * 按优先级下载资源\r\n    * 断点续传\r\n    * 多下载源重试\r\n    * 支持边玩边下\r\n    * 空闲时自动后台下载 \r\n* 打包\r\n    * 可视化打包管理\r\n    * 按条件分包\r\n    * 按资源数量分包\r\n    * 根据资源访问分析自动配置首包\r\n    * 资源包加密 \r\n    * 冗余资源报告\r\n\r\n# 进度\r\n功能基本完成. \u003cbr/\u003e\r\n\r\n# Examples\r\n\r\n## 初始化\r\n```csharp\r\n\r\n    // 可用下载地址列表 (会依次重试, 次数超过地址数量时反复重试最后一个地址)\r\n    // 适用于 CDN 部署还没有全部起作用时, 退化到直接文件服务器地址\r\n    var urls = UnityFS.Utils.Helpers.URLs(\r\n        // \"http://localhost:8081/\",\r\n        \"http://localhost:8080/\"\r\n    );\r\n\r\n    // 下载存储目录\r\n    var dataPath = string.IsNullOrEmpty(Application.temporaryCachePath) ? Application.persistentDataPath : Application.temporaryCachePath;\r\n    var localPathRoot = Path.Combine(dataPath, \"bundles\");\r\n    Debug.Log($\"open localPathRoot: {localPathRoot}\");\r\n\r\n    UnityFS.ResourceManager.Initialize(developMode, localPathRoot, urls, this);\r\n    UnityFS.ResourceManager.Open();\r\n\r\n```\r\n\r\n## 资源加载\r\nUnityFS.ResourceManager 返回的资源会自动管理加载卸载与资源包依赖: \u003cbr/\u003e\r\n* IFileSystem\r\n* UAsset\r\n\r\n当资源实例不存在强引用时将进入GC流程, 对应资源包将被自动卸载.\r\n\r\n### 加载文件 (脚本/配置等)\r\nIFileSystem 中的文件可以同步加载 (实际对应zip包中的文件). \r\n\r\n```csharp\r\n// 获取核心脚本代码包\r\nvar fs = UnityFS.ResourceManager.FindFileSystem(\"Assets/Examples/Scripts/code.js\");\r\nfs.completed += self =\u003e\r\n{\r\n    // 可以在这里由脚本接管后续启动流程\r\n    // 需要保持对 fs 的引用, 无引用时将在GC后自动释放对应包\r\n    ScriptEngine.Initialize(fs); \r\n    ScriptEngine.RunScript(\"Assets/Examples/Scripts/code.js\");\r\n\r\n    // 判断文件是否存在\r\n    var exists = fs.Exists(\"Assets/Examples/not_exist.file\");\r\n    Debug.Log($\"file exists? {exists}\");\r\n\r\n    // 读取文件内容 (zip包中的文件可以同步读取)\r\n    var data = fs.ReadAllBytes(\"Assets/Examples/Config/test.txt\");\r\n    Debug.Log(System.Text.Encoding.UTF8.GetString(data));\r\n};\r\n```\r\n\r\n```csharp\r\n// 可以用 LoadAsset 载入文件内容 (通常位于zip包中)\r\nvar testFile = UnityFS.ResourceManager.LoadAsset(\"Assets/Examples/Config/test.txt\");\r\ntestFile.completed += self =\u003e\r\n{\r\n    var text = System.Text.Encoding.UTF8.GetString(testFile.ReadAllBytes());\r\n    Debug.Log($\"用 LoadAsset 形式加载一个文件: {text}\");\r\n};\r\n```\r\n\r\n\r\n### 加载资源 (异步)\r\n\r\n```csharp\r\n// 方式1. 得到原始 UAsset 对象\r\nUnityFS.ResourceManager.LoadAsset(\"Assets/Examples/Prefabs/Cube 1.prefab\", self =\u003e\r\n{\r\n    UnityFS.Utils.AssetHandle.CreateInstance(self, 5.0f);\r\n});\r\n\r\n// 方式2. 通过辅助方法直接创建 GameObject (返回的是一个代理 GameObject)\r\nUnityFS.ResourceManager.Instantiate(\"Assets/Examples/Prefabs/Cube 1.prefab\").DestroyAfter(10.0f);\r\n```\r\n\r\n### 加载场景 (异步)\r\n```csharp\r\n// LoadScene/LoadSceneAdditive 分别对应 Single/Additive 场景加载模式\r\nvar scene = UnityFS.ResourceManager.LoadSceneAdditive(\"Assets/Examples/Scenes/test2.unity\");\r\nscene.completed += self =\u003e\r\n{\r\n    Debug.Log(\"scene loaded\");\r\n};\r\n\r\nStartCoroutine(UnityFS.Utils.Helpers.InvokeAfter(() =\u003e\r\n    {\r\n        // 场景对象需要手工卸载 (异步完成)\r\n        // 场景对应的资源包则在所有场景实例对象GC后自动卸载\r\n        scene.UnloadScene(); \r\n        scene = null;\r\n    }, 20f)\r\n);\r\n```\r\n\r\n# 打包编辑器\r\n![editorwindow](Assets/Examples/Textures/editorwindow.png)\r\n\r\n# 资源冗余分析\r\n![buildreport](Assets/Examples/Textures/buildreport.png)\r\n\r\n# Unity 版本\r\nUnity 2017.4+\r\n\r\n# License\r\nMIT\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fialex32x%2Funityfs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fialex32x%2Funityfs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fialex32x%2Funityfs/lists"}