{"id":19612563,"url":"https://github.com/chenjd/ttui-framework","last_synced_at":"2025-04-27T23:30:47.684Z","repository":{"id":74015560,"uuid":"48682731","full_name":"chenjd/TTUI-Framework","owner":"chenjd","description":"基于注册分发机制的Unity3D的UI消息框架，目的是便于管理消息以及和MonoBehaviour进行解耦。","archived":false,"fork":false,"pushed_at":"2015-12-28T15:03:32.000Z","size":1606,"stargazers_count":18,"open_issues_count":1,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-02T05:11:40.071Z","etag":null,"topics":[],"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/chenjd.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}},"created_at":"2015-12-28T08:35:13.000Z","updated_at":"2022-12-21T08:04:49.000Z","dependencies_parsed_at":"2023-03-16T11:30:40.656Z","dependency_job_id":null,"html_url":"https://github.com/chenjd/TTUI-Framework","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenjd%2FTTUI-Framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenjd%2FTTUI-Framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenjd%2FTTUI-Framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenjd%2FTTUI-Framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenjd","download_url":"https://codeload.github.com/chenjd/TTUI-Framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224091944,"owners_count":17254149,"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":[],"created_at":"2024-11-11T10:47:04.345Z","updated_at":"2024-11-11T10:47:04.739Z","avatar_url":"https://github.com/chenjd.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TTUI-Framework\n##TTUI Framework是什么？\n**Ting Ting UI Framework**是一个供Unity3D引擎使用的简易的UI消息分发架构。基于NGUI。它的目录如下：\n\t\n\t//放置在Unity项目的Assets文件夹下：\n\t.\n\t├── .gitignore                    \n\t├── README.md\n\t├── NGUI\t\t\t\t\t//使用的NGUI\n\t├── Resources\t\t\t\t//存放测试中使用的UI页面\n\t│   └── TTUITest.prefab\n\t├── TTUI\t\t\t\t//TTUI的文件夹\n\t│\t├── Src                        // sources \n\t│\t│   ├── Constant              // 常量\u0026辅助类  \n\t│\t│   │   ├── TTUIFrameID.cs   //UI的ID在这里定义\n\t│\t│   │   └── TTUIHelper.cs   //辅助类\n\t│ |   ├── Factory\n\t│\t|   |   ├── TTUIFactory.cs\t//抽象类，用于批量注册UI信息\n\t│\t│   |   └── TTUIBuilder.cs\t//注册UI信息的具体执行者\n\t│ |   ├── Manager\t\t\t\t//管理器模块\n\t│\t|   |   ├── TTUIFrameManager.cs\t//UI页面管理模块\n\t│\t│   |   └── TTUIMsgManager.cs\t//UI消息管理模块\n\t│ |   ├── Message\t\t\t\t//定义UI的Message\n\t│\t│   |   └── TTUIMessage.cs\t//所有UI消息的基类，自定义的UI消息需要继承该类\n\t│ |   ├── UI\t\t\t\t\t//定义UI的页面\n\t│\t│   |   └── TTUIFrame.cs\t//所有UI类型的基类，定义了最基本的一些功能\n\t│ |   └── TTUICore.cs\t\t\t//提供了对UI各个控制模块的引用，操作入口\n\t│ └──Test                  //测试脚本\n\t│     ├── Frame       //UI页面类，继承自TTUIFrame\n\t|     |   └── TTUITestFrame.cs\n\t│     ├── Item         //MonoBehaviour脚本，用来接受用户的点击\n\t|     |   ├── TTUITestItem.cs\t//创建消息，并发送到消息管理器\n\t|     |   └── TTUITestItem1.cs\n\t│     ├── MonoScript         //捆绑在测试UI资源上的MonoBehav脚本\n\t|     |   └── TTUITestScript.cs \n\t│     ├── Msg         //测试UI消息，继承自TTUIMessage\n\t|     |   └──  TTUITestMsg.cs    \n\t│     └── TTUITestFactory.cs\t//继承自TTUIFactory，用来注册测试的UI信息\n\t|\t  |\n\t|     └── TTUITestMain.cs    //测试入口 \n\t|   \n\t│       \n\t└── TTUITestScene.unity\t\t\t\t//测试场景\n\n\n##TTUI Framework如何测试？\n###1.基本概念\n####1.1 TTUIFrame\n由于主要的思想是将UI资源注册、将逻辑和具体UI分离，因此我在**TTUIFrameID.cs**文件中首先定义了一些UI页面的ID：\n\n\t//TTUIFrameID.cs\n\tpublic class TTUIFrameID {\n\t    public const int InitTestFrame = 0x01;\n\t    public const int InitTestFrame2 = 0x02;\n\t    //TODO\n\t}\n\t\n并且对每个UI页面进行了一层抽象，创建了一个不依赖于MonoBehaviour的UIFrame类——**TTUIFrame**。所有的具体UI页面的类都必须继承它。\n例如在测试中，我定义的**TTUITestFrame**便继承于它。\n这样，我们就可以通过注册UI的ID以及UI对应的UIFrame类来管理我们的UI系统了。而负责这个业务的类便是**TTUIFrameManager**类。\n\n####1.2 TTUIMessage\n除了将UIFrame注册管理之外，我还需要将消息和它对应的回调方法进行注册管理。因此也需要提供一个ID以及一个委托对象（作为回调函数）。\n其中ID的部分使用了我在辅助类**TTUIHelper**中提供的哈希函数，将字符串转换成为ID进行注册。\n\t\n\t//TTUIMessage.cs\n\tpublic abstract class TTUIMessage  {\n\t    \n\t    public TTUIMessage(string name)\n\t    {\n\t\t\tthis.ID = TTUIHelper.StringHash(name);\n\t    }\n\t    ...\n    \n同样，我还会提供一个类**TTUIMsgManager**用来管理UI消息。\n\n###2.注册分发\n####2.1注册UIFrame类\n由于UI资源实例化的工作是通过抽象出来的UIFrame类来处理的，因此在注册UIFrame类时即需要关联UI的ID和其对应的UIFrame类，同时也要提供相应的资源路径信息。这里我使用了一个抽象工厂**TTUIFactory**来实现批量注册多个UI，在具体的环境中，用户需要继承该工厂，自己添加自定义的UI信息。例如Test中的**TTUITestFactory**，只添加了一个UI：\n\t\n\tpublic class TTUITestFactory : TTUIFactory {\n\t\n\t\t#region Public Methods\n\t\n\t    /// \u003csummary\u003e\n\t\t/// 以FrameID作为key，创建FrameID和对应的UI类之间的联系。\n\t    /// \u003c/summary\u003e\n\t\tpublic override void BuildCommonUIFrame()\n\t    {\n\t\t\tBuildUIFrame\u003cTTUITestFrame\u003e(TTUIFrameID.InitTestFrame);\n\t\t\t//TODO\n\t    }\n\t\n\t\t/// \u003csummary\u003e\n\t\t///以FrameID作为key，注册UI资源的地址，用于创建id和prefab之间的关联\n\t\t///使用时，在次方法下添加具体的k-v(id-资源路径）。\n\t\t/// \u003c/summary\u003e\n\t\tpublic override void RegisterUIFrameAssetes()\n\t\t{\n\t\t\tRegisterAssets(TTUIFrameID.InitTestFrame, \"TTUITest\");\t\n\t\t\t//TODO\n\t\t}\n\t\n\t  \t#endregion\n\t\n\t}\n\n\n###3.使用Test\n_需要注意的是，我并没有上传meta文件，因此可能会出现脚本引用丢失的问题_。但是我想这应该不是什么大问题。\n需要注意的是，将测试入口**TTUITestMain.cs**脚本挂载好。在**TTUITestMain.cs**文件中：\n首先创建TTUI中各个模块的引用：\n\n\tTTUICore.Create();\n之后，在利用自己定义的TTUITestFactory工厂来注册页面信息：\n\n\tTTUITestFactory uifact = new TTUITestFactory();\n\tuifact.BuildCommonUIFrame();\n\tuifact.RegisterUIFrameAssetes();\n同时，不要忘了要在Update函数中更新UI的各个模块：\n\n\t\tTTUICore.Update();\t\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenjd%2Fttui-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenjd%2Fttui-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenjd%2Fttui-framework/lists"}