{"id":14960685,"url":"https://github.com/zgz682000/puerts-component","last_synced_at":"2025-10-12T11:50:27.063Z","repository":{"id":54925221,"uuid":"522752894","full_name":"zgz682000/puerts-component","owner":"zgz682000","description":"puerts框架的扩展插件，通过ts装饰器将ts类的成员变量显示在Unity Inspector面板上，实现类似MoneBehaviour的拖拽赋值功能","archived":false,"fork":false,"pushed_at":"2023-04-26T02:06:42.000Z","size":47882,"stargazers_count":49,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-27T23:21:01.717Z","etag":null,"topics":["puerts","typescript","unity","unity3d","unity3d-editor","unity3d-plugin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zgz682000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-08-09T00:46:11.000Z","updated_at":"2024-08-22T12:17:12.000Z","dependencies_parsed_at":"2024-09-22T11:40:45.475Z","dependency_job_id":null,"html_url":"https://github.com/zgz682000/puerts-component","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.1428571428571429,"last_synced_commit":"607d5064ba999e44949019494291e795d1f6a7ce"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgz682000%2Fpuerts-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgz682000%2Fpuerts-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgz682000%2Fpuerts-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgz682000%2Fpuerts-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zgz682000","download_url":"https://codeload.github.com/zgz682000/puerts-component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219868059,"owners_count":16555878,"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":["puerts","typescript","unity","unity3d","unity3d-editor","unity3d-plugin"],"created_at":"2024-09-24T13:22:45.503Z","updated_at":"2025-10-12T11:50:22.029Z","avatar_url":"https://github.com/zgz682000.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Puerts Component\n\n* 介绍\n\n    [puerts框架](https://github.com/Tencent/puerts)的扩展插件，通过ts装饰器将ts类的成员变量显示在Unity Inspector面板上，实现类似MoneBehaviour和ScriptableObject的拖拽赋值功能\n\n* 效果展示\n    \n    先看一下如何在ts代码中定义组件属性：\n    ![效果展示-代码](./img/效果展示-代码.png)\n\n    这段代码对应的inspector面板上的显示效果如下：\n    ![效果展示-面板](./img/效果展示-面板.jpg)\n    \n* 还能带来哪些好处\n    * 方便地从ts代码中引用unity场景中的物体和资源\n    * 在ts代码中接收unity组件的生命周期回调\n    * ScriptableObject也可以写ts版本啦\n    * 方便地从c#测调用ts代码中的方法\n\n* 特点\n    * 功能设计相对独立，不依赖于项目中如何使用puerts插件，如何加载和编译ts代码\n    * 面板显示所使用的类型信息只在Editor环境下有效，运行时不产生额外的内存消耗\n    * 面板支持显示的属性类型可根据需要自行扩展，目前内置支持所有`UnityEngine.Object`的子类和几种基本数据类型，如字符串、数字、布尔、`Vector2`、`Vector3`等\n\n* 如何运行Demo\n    * `git clone` 本项目\n    * macOS `cd` 到 `Assets/Puerts/Editor/Plugins/macOS` 文件夹下，运行 `sudo xattr -r -d com.apple.quarantine puerts.bundle`\n    * 在Unity工程中打开 `Assets/Demo/TestPrefab.prefab` 即可在TsComponent组件的Inspector面板中看到 `TsProjDemo/src/test-component.cts` 文件中定义的属性呈现的效果\n    * 打开 `Assets/Demo/TestAsset.asset` 即可在TsAsset组件的Inspector面板中看到 `TsProjDemo/src/test-assett.cts` 文件中定义的属性呈现的效果\n    * 打开 `Assets/Demo/SampleScene.unity` 并行，如果Console面板中能打印出 `index running` 和 `TestComponent Start` 说明运行成功\n\n* 如何将插件集成到自己项目中\n    * 首先确保项目中已经集成了[puerts框架](https://github.com/Tencent/puerts)\n    * 将 `Assets/PuertsComponent` 文件夹放入项目任意位置\n    * 在项目的tsconfig.json中加入如下配置，其中的PATH/TO替换为PuertsComponent所在的文件夹相对与tsconfig.json的路径\n        ```\n        \"paths\": {\n            \"puerts-component/*\" : [\n                \"PATH/TO/PuertsComponent/Typing/puerts-component/*\"\n            ]\n        }\n        ```\n    * 同时确保运行时 `JsEnv.ILoader` 可以通过 `Resources.Load` 加载 `puerts-component/`开头的文件\n\n* 使用注意\n    * 被 `@Transporter()` 装饰器修饰的类必须是其所在文件的默认导出类 `export default class`\n    * `@ListProperty()` 装饰器的第二个参数表示列表的维度，默认为1，表示一维数组\n    * demo中和插件中使用cts和cjs作为后缀单纯是为了方便，因为Resources.Load无法加载js后缀的文件\n    * 每次修改完ts组件中的属性（例如增加属性，修改属性名，修改属性装饰器类型等行为）后，需要点击Inspector面板上的Reload按钮才能刷新出对应的变化\n\n* 已知缺陷\n    * 报警告 `Serialization depth limit 10 exceeded at ...` 意思是序列化组件时出现了递归。这是因为属性中使用了嵌套结构来表示数组。但从实际序列化出来的yml格式的文本来看并没有因此影响序列化结果的大小。所以暂时没有去解决，也没想出什么办法能代替目前的嵌套结构。\n    * 需要确保TsComponent和TsAsset所在的物体都在JsEnv创建之后才被加载。\n    * 如果项目中存在多个JsEnv同时运行的情况，则TsComponent和TsAsset需要一定的修改才能支持。另外由于挂TsAsset的资源文件在整个运行时生命周期中`OnEnable`只在此资源被首次加载时执行一次，需要额外的处理才能使该资源文件被后创建的JsEnv引用到。\n\n* 计划\n    * 将按钮或其他unity事件指定为ts函数\n    * 支持属性类型\n        * ts枚举类型\n        * ts任意类结构","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzgz682000%2Fpuerts-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzgz682000%2Fpuerts-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzgz682000%2Fpuerts-component/lists"}