- Unity 版本:本项目使用 Unity 6000.3.13f1 创建。
- 推荐字体:Noto Sans SC
- Google Fonts 下载链接
- 注:你也可以根据需要使用其他中文字体。
- 创建项目:新建一个本地 UPR (Universal Project Report) 项目。
- 资源导入:
- 将下载的资源文件复制到工程的
Assets文件夹中。 - 依次导入以下三个核心插件:
DOTween,UniTask,Localization。
- 将下载的资源文件复制到工程的
- 输入系统配置:
- 依次点击:
Project Settings->Player->Active Input Handling。 - 将选项改为 Both。
- 注意:修改后 Unity 会自动重启以应用设置。
- 依次点击:
- 在
Project Settings->Localization->Active Setting中点击添加 Localization Settings。 - 在
Available Locales中点击 Add All,确保 Chinese (Simplified) (zh) 和 English (en) 出现。
- Addressable 标记:
在
Assets/Localization/Tables文件夹下,选中以下文件,并在 Inspector 面板左上角勾选 Addressable:AuthorMessageTable Shared Data / AuthorMessageTable_en / AuthorMessageTable_zhPlayerMessageTable Shared Data / PlayerMessageTable_en / PlayerMessageTable_zh
- 预加载 (Preload) 设置:
- 选中
AuthorMessageTable,点击 Inspector 中的 Open In Table Editor。 - 在窗口中勾选 Preload。并在
Selected collection中确保两张表均已勾选。
- 选中
- 刷新资源:右键点击
Assets/Localization/Tables文件夹,选择 Reimport。
- 生成 SDF 字体:右键点击字体文件 ->
Create->TextMeshPro-> Font Asset。系统会自动生成对应的SDF资产。 - 替换字体资产:在
Prefab文件夹中找到ChooseBox,TexBoxLeft,TextBoxRight。将其TextMeshPro - Text脚本中的 Font Asset 替换为新生成的SDF资产。
- 打开
ChatWindowsSample场景,点击 Play。 - 点击画面右上角 方块图标 弹出窗口,点击 AddMessage 验证显示。
- 场景路径:打开
SimpleChatScene场景。 - 性能测试 (Performance Test):
- 场景中的
Main Camera默认挂载了PerformanceTestController。 - 运行后,系统会自动推入 200 条 中文对话框以进行性能压力测试。
- 注:脚本会自动尝试点击选项,若失灵请手动点击。
- 场景中的
- 交互故事 (Interactive Story):
- 将
Main Camera上的脚本更换为FairyTaleController。 - 重要:确保在 Inspector 中手动绑定
ChatUI引用。 - 运行后可体验一个简单的中文交互式小故事。
- 将
- 技术说明:
- 这两个例子展示了如何通过
CustomizedMessageSender类直接输入自定义对话内容,实现不依赖本地化表 (Localization Tables) 的动态文本推送。
- 这两个例子展示了如何通过
- Unity Version: Created with Unity 6000.3.13f1.
- Recommended Font: Noto Sans SC
- Download from Google Fonts
- Note: Other Chinese fonts are also supported.
- Create Project: Create a new local UPR project.
- Import Assets: Copy files to
Assetsand importDOTween,UniTask, andLocalization. - Input System: Set
Active Input Handlingto Both inProject Settings -> Player. Unity will restart.
- Settings: Add Localization Settings in Project Settings. Add Chinese (Simplified) (zh) and English (en) in
Available Locales. - Addressables: In
Assets/Localization/Tables, mark all Table files as Addressable in the Inspector. - Preload: Open
AuthorMessageTablein Table Editor, check Preload, and ensure both tables are selected underSelected collection. - Reimport: Right-click the Tables folder and select Reimport.
- SDF Generation: Right-click your font ->
Create -> TextMeshPro -> Font Asset. - Assign Font: In the
Prefabfolder, updateChooseBox,TexBoxLeft, andTextBoxRightby replacing their Font Asset with the newSDFasset.
- Open
ChatWindowsSamplescene and press Play. - Click the Square Icon (top-right) and use AddMessage to test.
- Scene Path: Open the
SimpleChatScene. - Performance Test:
- The
Main Camerais equipped with thePerformanceTestControllerby default. - It automatically injects 200 Chinese dialogue boxes to simulate a stress test.
- Note: The script attempts to auto-click options; click manually if it stalls.
- The
- Interactive Story:
- Replace the controller on
Main CamerawithFairyTaleController. - Crucial: Manually bind the
ChatUIreference in the Inspector. - This runs a simple interactive narrative in Chinese.
- Replace the controller on
- Technical Highlight:
- These examples demonstrate the
CustomizedMessageSenderclass, allowing you to inject custom dialogue content dynamically without relying on Localization Tables.
- These examples demonstrate the
