docs: 更新文档链接和代码块格式

- 修复了文档中多个文件的链接指向,统一使用相对路径格式
- 移除了代码块中的语言标识符以保持一致性
- 更新了存储模块文档中的类名显示方式
- 修正了架构文档中的跨文档引用链接
- 调整了事件、命令、查询等核心模块的文档链接结构
- 规范化了所有代码示例的格式和引用方式
This commit is contained in:
GeWuYou 2026-02-11 14:44:46 +08:00
parent 75826961d4
commit d1cdac8082
21 changed files with 194 additions and 196 deletions

View File

@ -23,4 +23,4 @@ GFramework 框架的抽象层定义模块,包含所有核心组件的接口定
## 详细文档 ## 详细文档
参见 [docs/core/](../docs/core/) 目录下的详细文档。 参见 [docs/zh-CN/abstractions/](../docs/zh-CN/abstractions/) 目录下的详细文档。

View File

@ -28,4 +28,4 @@ GFramework 框架的核心模块提供MVC架构的基础设施。
## 详细文档 ## 详细文档
参见 [docs/core/](../docs/core/) 目录下的详细文档。 参见 [docs/zh-CN/core/](../docs/zh-CN/core/) 目录下的详细文档。

View File

@ -13,4 +13,4 @@ GFramework 框架的游戏通用模块,提供游戏开发常用的功能。
## 详细文档 ## 详细文档
参见 [docs/game/](../docs/game/) 目录下的详细文档。 参见 [docs/zh-CN/game/](../docs/zh-CN/game/) 目录下的详细文档。

View File

@ -1,11 +1,11 @@
# GFramework 存储模块使用指南 # GFramework 存储模块使用指南
本模块提供了基于文件系统的存储功能,包括两个主要类:[FileStorage](./FileStorage.cs) 本模块提供了基于文件系统的存储功能包括两个主要类FileStorage
[ScopedStorage](./ScopedStorage.cs) 和 ScopedStorage。
## FileStorage ## FileStorage
[FileStorage](./FileStorage.cs) 是一个基于文件系统的存储实现,它将数据以序列化形式保存到磁盘上的指定目录。 FileStorage 是一个基于文件系统的存储实现,它将数据以序列化形式保存到磁盘上的指定目录。
### 特性 ### 特性
@ -59,7 +59,7 @@ storage.WriteAsync("player_score", 1200);
## ScopedStorage ## ScopedStorage
[ScopedStorage](./ScopedStorage.cs) 是一个装饰器模式的实现,它为所有存储键添加前缀,从而实现逻辑分组和命名空间隔离。 ScopedStorage 是一个装饰器模式的实现,它为所有存储键添加前缀,从而实现逻辑分组和命名空间隔离。
### 特性 ### 特性
@ -122,13 +122,13 @@ settingsStorage.Write("level", "high");
## 注意事项 ## 注意事项
1. **序列化器选择**:确保使用的 [ISerializer](../GFramework.Game.Abstractions/serializer/ISerializer.cs) 1. **序列化器选择**:确保使用的 ISerializer
实现能够正确处理你要存储的数据类型。 实现能够正确处理你要存储的数据类型。
2. **错误处理**[FileStorage](./FileStorage.cs)`Read<T>(string key)` 方法会在键不存在时抛出异常,可以使用 2. **错误处理**FileStorage 的 `Read<T>(string key)` 方法会在键不存在时抛出异常,可以使用
`Read<T>(string key, T defaultValue)` 来避免异常。 `Read<T>(string key, T defaultValue)` 来避免异常。
3. **线程安全**[FileStorage](./FileStorage.cs) 通过细粒度锁机制保证线程安全,每个键都有独立的锁,因此不同键的操作可以并发执行。 3. **线程安全**FileStorage 通过细粒度锁机制保证线程安全,每个键都有独立的锁,因此不同键的操作可以并发执行。
4. **文件权限**:确保应用程序对指定的存储目录有读写权限。 4. **文件权限**:确保应用程序对指定的存储目录有读写权限。
5. **路径安全**[FileStorage](./FileStorage.cs) 会自动防止路径遍历攻击,因此键不能包含 `..`,并且特殊字符会被替换为下划线。 5. **路径安全**FileStorage 会自动防止路径遍历攻击,因此键不能包含 `..`,并且特殊字符会被替换为下划线。
6. **存储键格式**:键可以包含 `/` 作为分隔符,这将被转换为相应的目录层级,例如 `"player/profile"` 会存储在 6. **存储键格式**:键可以包含 `/` 作为分隔符,这将被转换为相应的目录层级,例如 `"player/profile"` 会存储在
`player/profile.dat` 文件中。 `player/profile.dat` 文件中。
7. **异步操作**尽管异步读写操作使用了异步IO但仍会使用锁来保证对同一键的并发访问安全。 7. **异步操作**尽管异步读写操作使用了异步IO但仍会使用锁来保证对同一键的并发访问安全。

View File

@ -16,4 +16,4 @@ GFramework 框架的 Godot 引擎集成模块提供Godot特定的功能和扩
## 详细文档 ## 详细文档
参见 [docs/godot/](../docs/godot/) 目录下的详细文档。 参见 [docs/zh-CN/godot/](../docs/zh-CN/godot/) 目录下的详细文档。

View File

@ -7,7 +7,7 @@
[![Godot](https://img.shields.io/badge/Godot-4.6-green)](https://godotengine.org/) [![Godot](https://img.shields.io/badge/Godot-4.6-green)](https://godotengine.org/)
[![.NET](https://img.shields.io/badge/.NET-6.0+-purple)](https://dotnet.microsoft.com/) [![.NET](https://img.shields.io/badge/.NET-6.0+-purple)](https://dotnet.microsoft.com/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue)](LICENSE) [![License](https://img.shields.io/badge/License-Apache%202.0-blue)](LICENSE)
[![zread](https://img.shields.io/badge/Ask_Zread-_.svg?style=flat-square&color=00b0aa&labelColor=000000&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQuOTYxNTYgMS42MDAxSDIuMjQxNTZDMS44ODgxIDEuNjAwMSAxLjYwMTU2IDEuODg2NjQgMS42MDE1NiAyLjI0MDFWNC45NjAxQzEuNjAxNTYgNS4zMTM1NiAxLjg4ODEgNS42MDAxIDIuMjQxNTYgNS42MDAxSDQuOTYxNTZDNS4zMTUwMiA1LjYwMDEgNS42MDE1NiA1LjMxMzU2IDUuNjAxNTYgNC45NjAxVjIuMjQwMUM1LjYwMTU2IDEuODg2NjQgNS4zMTUwMiAxLjYwMDEgNC45NjE1NiAxLjYwMDFaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik00Ljk2MTU2IDEwLjM5OTlIMi4yNDE1NkMxLjg4ODEgMTAuMzk5OSAxLjYwMTU2IDEwLjY4NjQgMS42MDE1NiAxMS4wMzk5VjEzLjc1OTlDMS42MDE1NiAxNC4xMTM0IDEuODg4MSAxNC4zOTk5IDIuMjQxNTYgMTQuMzk5OUg0Ljk2MTU2QzUuMzE1MDIgMTQuMzk5OSA1LjYwMTU2IDE0LjExMzQgNS42MDE1NiAxMy43NTk5VjExLjAzOTlDNS42MDE1NiAxMC42ODY0IDUuMzE1MDIgMTAuMzk5OSA0Ljk2MTU2IDEwLjM5OTlaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik0xMy43NTg0IDEuNjAwMUgxMS4wMzg0QzEwLjY4NSAxLjYwMDEgMTAuMzk4NCAxLjg4NjY0IDEwLjM5ODQgMi4yNDAxVjQuOTYwMUMxMC4zOTg0IDUuMzEzNTYgMTAuNjg1IDUuNjAwMSAxMS4wMzg0IDUuNjAwMUgxMy43NTg0QzE0LjExMTkgNS42MDAxIDE0LjM5ODQgNS4zMTM1NiAxNC4zOTg0IDQuOTYwMVYyLjI0MDFDMTQuMzk4NCAxLjg4NjY0IDE0LjExMTkgMS42MDAxIDEzLjc1ODQgMS42MDAxWiIgZmlsbD0iI2ZmZiIvPgo8cGF0aCBkPSJNNCAxMkwxMiA0TDQgMTJaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik00IDEyTDEyIDQiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPgo8L3N2Zz4K&logoColor=ffffff)](https://zread.ai/GeWuYou/GFramework) [![zread](https://img.shields.io/badge/Ask_Zread-_.svg?style=flat-square&color=00b0aa&labelColor=000000&logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTQuOTYxNTYgMS42MDAxSDIuMjQxNTZDMS44ODgxIDEuNjAwMSAxLjYwMTU2IDEuODg2NjQgMS42MDE1NiAyLjI0MDFWNC45NjAxQzEuNjAxNTYgNS4zMTM1NiAxLjg4ODEgNS42MDAxIDIuMjQxNTYgNS42MDAxSDQuOTYxNTZDNS5zMTUwMiA1LjYwMDEgNS42MDE1NiA1LjMxMzU2IDUuNjAxNTYgNC45NjAxVjIuMjQwMUM1LjYwMTU2IDEuODg2NjQgNS4zMTUwMiAxLjYwMDEgNC45NjE1NiAxLjYwMDFaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik00Ljk2MTU2IDEwLjM5OTlIMi4yNDE1NkMxLjg4ODEgMTAuMzk5OSAxLjYwMTU2IDEwLjY4NjQgMS42MDE1NiAxMS4wMzk5VjEzLjc1OTlDMS42MDE1NiAxNC4xMTM0IDEuODg4MSAxNC4zOTk5IDIuMjQxNTYgMTQuMzk5OUg0Ljk2MTU2QzUuMzE1MDIgMTQuMzk5OSA1LjYwMTU2IDE0LjExMzQgNS42MDE1NiAxMy43NTk5VjExLjAzOTlDNS42MDE1NiAxMC42ODY0IDUuMzE1MDIgMTAuMzk5OSA0Ljk2MTU2IDEwLjM5OTlaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik0xMy43NTg0IDEuNjAwMUgxMS4wMzg0QzEwLjY4NSAxLjYwMDEgMTAuMzk4NCAxLjg4NjY0IDEwLjM5ODQgMi4yNDAxVjQuOTYwMUMxMC4zOTg0IDUuMzEzNTYgMTAuNjg1IDUuNjAwMSAxMS4wMzg0IDUuNjAwMUgxMy43NTg0QzE0LjExMTkgNS42MDAxIDE0LjM5ODQgNS4zMTM1NiAxNC4zOTg0IDQuOTYwMVYyLjI0MDFDMTQuMzk4NCAxLjg4NjY0IDE0LjExMTkgMS42MDAxIDEzLjc1ODQgMS42MDAxWiIgZmlsbD0iI2ZmZiIvPgo8cGF0aCBkPSJNNCAxMkwxMiA0TDQgMTJaIiBmaWxsPSIjZmZmIi8%2BCjxwYXRoIGQ9Ik00IDEyTDEyIDQiIHN0cm9rZT0iI2ZmZiIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPgo8L3N2Zz4K&logoColor=ffffff)](https://zread.ai/GeWuYou/GFramework)
--- ---
## 项目简介 ## 项目简介
@ -37,11 +37,11 @@ GFramework 采用清晰分层与模块化设计,强调:
## 文档导航 ## 文档导航
- 入门教程:[`docs/tutorials/getting-started.md`](docs/tutorials/getting-started.md) - 入门教程:[`docs/zh-CN/tutorials/getting-started.md`](docs/zh-CN/tutorials/getting-started.md)
- Godot 集成:[`docs/tutorials/godot-integration.md`](docs/tutorials/godot-integration.md) - Godot 集成:[`docs/zh-CN/godot/index.md`](docs/zh-CN/godot/index.md)
- 进阶模式:[`docs/tutorials/advanced-patterns.md`](docs/tutorials/advanced-patterns.md) - 进阶模式:[`docs/zh-CN/core/index.md`](docs/zh-CN/core/index.md)
- 最佳实践:[`docs/best-practices/architecture-patterns.md`](docs/best-practices/architecture-patterns.md) - 最佳实践:[`docs/zh-CN/best-practices/architecture-patterns.md`](docs/zh-CN/best-practices/architecture-patterns.md)
- API 参考:[`docs/api-reference/`](docs/api-reference/) - API 参考:[`docs/zh-CN/api-reference/`](docs/zh-CN/api-reference/)
> 如果你更偏好按模块阅读,建议从各子项目 `README.md` 开始,再回到 `docs/` 查阅专题文档。 > 如果你更偏好按模块阅读,建议从各子项目 `README.md` 开始,再回到 `docs/` 查阅专题文档。

View File

@ -1,25 +1,25 @@
{ {
"hash": "74ecdc37", "hash": "6e3217ee",
"configHash": "1c302118", "configHash": "ff691e50",
"lockfileHash": "42b6a898", "lockfileHash": "42b6a898",
"browserHash": "b3e735e5", "browserHash": "d5f41485",
"optimized": { "optimized": {
"vue": { "vue": {
"src": "../../../node_modules/vue/dist/vue.runtime.esm-bundler.js", "src": "../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js", "file": "vue.js",
"fileHash": "5c6400c6", "fileHash": "ed53cbd8",
"needsInterop": false "needsInterop": false
}, },
"vitepress > @vue/devtools-api": { "vitepress > @vue/devtools-api": {
"src": "../../../node_modules/@vue/devtools-api/dist/index.js", "src": "../../../node_modules/@vue/devtools-api/dist/index.js",
"file": "vitepress___@vue_devtools-api.js", "file": "vitepress___@vue_devtools-api.js",
"fileHash": "673694b5", "fileHash": "e7446b18",
"needsInterop": false "needsInterop": false
}, },
"vitepress > @vueuse/core": { "vitepress > @vueuse/core": {
"src": "../../../node_modules/@vueuse/core/dist/index.js", "src": "../../../node_modules/@vueuse/core/dist/index.js",
"file": "vitepress___@vueuse_core.js", "file": "vitepress___@vueuse_core.js",
"fileHash": "7fde5c45", "fileHash": "6dc472ff",
"needsInterop": false "needsInterop": false
} }
}, },

View File

@ -79,7 +79,7 @@ Task InitializeAsync();
## 核心类 ## 核心类
### [`Architecture`](Architecture.cs) ### [`Architecture`](./architecture.md)
架构基类,实现了 `IArchitecture` 接口,提供完整的架构功能实现。 架构基类,实现了 `IArchitecture` 接口,提供完整的架构功能实现。
@ -268,7 +268,7 @@ public void InstallModule(IArchitectureModule module)
**使用示例:** **使用示例:**
```csharp ```
// 定义模块 // 定义模块
public class NetworkModule : IArchitectureModule public class NetworkModule : IArchitectureModule
{ {
@ -301,7 +301,7 @@ public void RegisterLifecycleHook(IArchitectureLifecycle hook)
**使用示例:** **使用示例:**
```csharp ```
// 定义生命周期钩子 // 定义生命周期钩子
public class PerformanceMonitorHook : IArchitectureLifecycle public class PerformanceMonitorHook : IArchitectureLifecycle
{ {
@ -342,7 +342,7 @@ public ArchitecturePhase CurrentPhase { get; }
**使用示例:** **使用示例:**
```csharp ```
var architecture = new GameArchitecture(); var architecture = new GameArchitecture();
// 检查架构是否已就绪 // 检查架构是否已就绪
@ -372,7 +372,7 @@ public IArchitectureContext Context { get; }
**使用示例:** **使用示例:**
```csharp ```
// 通过 Context 访问服务 // 通过 Context 访问服务
var context = architecture.Context; var context = architecture.Context;
var eventBus = context.EventBus; var eventBus = context.EventBus;
@ -383,7 +383,7 @@ var environment = context.Environment;
**高级特性:** **高级特性:**
``csharp ```
// 1. 使用自定义配置 // 1. 使用自定义配置
var config = new ArchitectureConfiguration(); var config = new ArchitectureConfiguration();
var architecture = new GameArchitecture(configuration: config); var architecture = new GameArchitecture(configuration: config);

View File

@ -6,7 +6,7 @@ Command 包实现了命令模式Command Pattern用于封装用户操作
## 核心接口 ## 核心接口
### 1. [`ICommand`](ICommand.cs) ### 1. [`ICommand`](./command.md)
无返回值命令接口,定义了命令的基本契约。 无返回值命令接口,定义了命令的基本契约。
@ -16,7 +16,7 @@ Command 包实现了命令模式Command Pattern用于封装用户操作
void Execute(); // 执行命令 void Execute(); // 执行命令
``` ```
### 2. [`ICommand<TResult>`](ICommand.cs) ### 2. [`ICommand<TResult>`](./command.md)
带返回值的命令接口,用于需要返回执行结果的命令。 带返回值的命令接口,用于需要返回执行结果的命令。
@ -28,9 +28,9 @@ TResult Execute(); // 执行命令并返回结果
## 核心类 ## 核心类
### 1. [`AbstractCommand<TInput>`](AbstractCommand.cs) ### 1. [`AbstractCommand<TInput>`](./command.md)
无返回值命令的抽象基类,提供了命令的基础实现。它继承自 [ContextAwareBase](file:///d:/Project/Rider/GFramework/GFramework.Core.Abstractions/rule/IContextAware.cs#L4-L28) 无返回值命令的抽象基类,提供了命令的基础实现。它继承自 [ContextAwareBase](./rule.md)
,具有上下文感知能力。 ,具有上下文感知能力。
**使用示例:** **使用示例:**
@ -83,9 +83,9 @@ public class GameController : IController
} }
``` ```
### 2. [`AbstractCommand<TInput, TResult>`](AbstractCommand.cs) ### 2. [`AbstractCommand<TInput, TResult>`](./command.md)
带返回值命令的抽象基类,同样继承自 [ContextAwareBase](file:///d:/Project/Rider/GFramework/GFramework.Core.Abstractions/rule/IContextAware.cs#L4-L28)。 带返回值命令的抽象基类,同样继承自 [ContextAwareBase](./rule.md)。
**使用示例:** **使用示例:**

View File

@ -8,18 +8,18 @@ Controller 包定义了控制器Controller的接口规范。控制器是 M
## 核心接口 ## 核心接口
### [`IController`](IController.cs) ### [`IController`](./controller.md)
控制器接口,定义了控制器需要实现的所有功能契约。 控制器接口,定义了控制器需要实现的所有功能契约。
**继承的能力接口:** **继承的能力接口:**
- [`ICanSendCommand`](../command/ICanSendCommand.cs) - 可发送命令 - [`ICanSendCommand`](./command.md) - 可发送命令
- [`ICanGetSystem`](../system/ICanGetSystem.cs) - 可获取系统 - [`ICanGetSystem`](./system.md) - 可获取系统
- [`ICanGetModel`](../model/ICanGetModel.cs) - 可获取模型 - [`ICanGetModel`](./model.md) - 可获取模型
- [`ICanRegisterEvent`](../events/ICanRegisterEvent.cs) - 可注册事件 - [`ICanRegisterEvent`](./events.md) - 可注册事件
- [`ICanSendQuery`](../query/ICanSendQuery.cs) - 可发送查询 - [`ICanSendQuery`](./query.md) - 可发送查询
- [`ICanGetUtility`](../utility/ICanGetUtility.cs) - 可获取工具 - [`ICanGetUtility`](./utility.md) - 可获取工具
**能力说明:** **能力说明:**
@ -110,7 +110,7 @@ public class PlayerController : IController
### UI 控制器示例 ### UI 控制器示例
```csharp ``csharp
// UI 面板控制器 // UI 面板控制器
public class MainMenuController : IController public class MainMenuController : IController
{ {
@ -160,7 +160,7 @@ public class MainMenuController : IController
### 复杂交互控制器 ### 复杂交互控制器
```csharp ``csharp
// 战斗控制器 // 战斗控制器
public class CombatController : IController public class CombatController : IController
{ {
@ -269,7 +269,7 @@ public class CombatController : IController
### 事件注销 ### 事件注销
```csharp ``csharp
public class MyController : IController public class MyController : IController
{ {
[Inject] private IArchitecture _architecture; [Inject] private IArchitecture _architecture;
@ -321,7 +321,7 @@ public class MyController : IController
### 数据绑定模式 ### 数据绑定模式
```csharp ``csharp
public class ScoreController : IController public class ScoreController : IController
{ {
[Inject] private IArchitecture _architecture; [Inject] private IArchitecture _architecture;
@ -344,7 +344,7 @@ public class ScoreController : IController
### 状态机模式 ### 状态机模式
```csharp ``csharp
public class PlayerStateController : IController public class PlayerStateController : IController
{ {
[Inject] private IArchitecture _architecture; [Inject] private IArchitecture _architecture;
@ -376,7 +376,7 @@ public class PlayerStateController : IController
在 Godot 项目中,可以使用 GFramework.Godot 提供的扩展: 在 Godot 项目中,可以使用 GFramework.Godot 提供的扩展:
```csharp ``csharp
using GFramework.Godot; using GFramework.Godot;
public partial class GodotPlayerController : Node, IController public partial class GodotPlayerController : Node, IController

View File

@ -23,7 +23,7 @@ void Initialize(); // 初始化环境
## 核心类 ## 核心类
### [`EnvironmentBase`](EnvironmentBase.cs) ### [`EnvironmentBase`](./environment.md)
环境基础抽象类,实现了 IEnvironment 接口,提供环境值的存储和获取功能。 环境基础抽象类,实现了 IEnvironment 接口,提供环境值的存储和获取功能。
@ -68,7 +68,7 @@ public abstract class EnvironmentBase : ContextAwareBase, IEnvironment
} }
``` ```
### [`DefaultEnvironment`](DefaultEnvironment.cs) ### [`DefaultEnvironment`](./environment.md)
默认环境实现类,继承自 EnvironmentBase。 默认环境实现类,继承自 EnvironmentBase。
@ -90,7 +90,7 @@ public class DefaultEnvironment : EnvironmentBase
### 1. 定义自定义环境 ### 1. 定义自定义环境
```csharp ```
public class GameEnvironment : EnvironmentBase public class GameEnvironment : EnvironmentBase
{ {
public override string Name { get; } = "Game"; public override string Name { get; } = "Game";
@ -112,7 +112,7 @@ public class GameEnvironment : EnvironmentBase
### 2. 在架构中使用环境 ### 2. 在架构中使用环境
```csharp ```
public class GameArchitecture : Architecture public class GameArchitecture : Architecture
{ {
protected override void Init() protected override void Init()
@ -130,7 +130,7 @@ public class GameArchitecture : Architecture
### 3. 使用环境值 ### 3. 使用环境值
```csharp ```
public class NetworkSystem : AbstractSystem public class NetworkSystem : AbstractSystem
{ {
private string _serverAddress; private string _serverAddress;
@ -183,7 +183,7 @@ public class NetworkSystem : AbstractSystem
## 错误示例 ## 错误示例
```csharp ```
// ❌ 错误:获取必需值但不存在 // ❌ 错误:获取必需值但不存在
public class BadExampleSystem : AbstractSystem public class BadExampleSystem : AbstractSystem
{ {

View File

@ -6,7 +6,7 @@ Events 包提供了一套完整的事件系统实现了观察者模式Obse
## 核心接口 ## 核心接口
### 1. [`IEvent`](file:///d:/Project/Rider/GFramework/GFramework.Core.Abstractions/events/IEvent.cs#L7-L11) ### 1. [`IEvent`](./events.md)
基础事件接口,定义了事件注册的基本功能。 基础事件接口,定义了事件注册的基本功能。
@ -16,7 +16,7 @@ Events 包提供了一套完整的事件系统实现了观察者模式Obse
IUnRegister Register(Action onEvent); // 注册事件处理函数 IUnRegister Register(Action onEvent); // 注册事件处理函数
``` ```
### 2. [`IUnRegister`](file:///d:/Project/Rider/GFramework/GFramework.Core.Abstractions/events/IUnRegister.cs#L6-L10) ### 2. [`IUnRegister`](./events.md)
注销接口,用于取消事件注册。 注销接口,用于取消事件注册。
@ -26,9 +26,7 @@ IUnRegister Register(Action onEvent); // 注册事件处理函数
void UnRegister(); // 执行注销操作 void UnRegister(); // 执行注销操作
``` ```
### 3. [ ### 3. [`IUnRegisterList`](./events.md)
`IUnRegisterList`](file:///d:/Project/Rider/GFramework/GFramework.Core.Abstractions/events/IUnRegisterList.cs#L6-L10)
注销列表接口,用于批量管理注销对象。 注销列表接口,用于批量管理注销对象。
@ -38,7 +36,7 @@ void UnRegister(); // 执行注销操作
IList<IUnRegister> UnregisterList { get; } // 获取注销列表 IList<IUnRegister> UnregisterList { get; } // 获取注销列表
``` ```
### 4. [`IEventBus`](file:///d:/Project/Rider/GFramework/GFramework.Core.Abstractions/events/IEventBus.cs#L6-L22) ### 4. [`IEventBus`](./events.md)
事件总线接口,提供基于类型的事件发送和注册。 事件总线接口,提供基于类型的事件发送和注册。
@ -52,7 +50,7 @@ void Send<T>() where T : new(); // 发送事件(自动创建实例
## 核心类 ## 核心类
### 1. [`EasyEvent`](EasyEvent.cs) ### 1. [`EasyEvent`](./events.md)
无参事件类,支持注册、注销和触发无参事件。 无参事件类,支持注册、注销和触发无参事件。
@ -75,7 +73,7 @@ onClicked.Trigger();
unregister.UnRegister(); unregister.UnRegister();
``` ```
### 2. [`Event<T>`](EasyEventGeneric.cs) ### 2. [`Event<T>`](./events.md)
单参数泛型事件类,支持一个参数的事件。 单参数泛型事件类,支持一个参数的事件。
@ -95,7 +93,7 @@ onScoreChanged.Register(newScore =>
onScoreChanged.Trigger(100); onScoreChanged.Trigger(100);
``` ```
### 3. [`Event<T, TK>`](EasyEventGeneric.cs) ### 3. [`Event<T, TK>`](./events.md)
双参数泛型事件类。 双参数泛型事件类。
@ -226,7 +224,7 @@ unregisterList.UnRegisterAll();
### 定义事件类 ### 定义事件类
```csharp ``csharp
// 简单事件 // 简单事件
public struct GameStartedEvent { } public struct GameStartedEvent { }
@ -249,7 +247,7 @@ public struct LevelCompletedEvent
### Model 中发送事件 ### Model 中发送事件
```csharp ``csharp
public class PlayerModel : AbstractModel public class PlayerModel : AbstractModel
{ {
public BindableProperty<int> Health { get; } = new(100); public BindableProperty<int> Health { get; } = new(100);
@ -275,7 +273,7 @@ public class PlayerModel : AbstractModel
### System 中发送事件 ### System 中发送事件
```csharp ``csharp
public class CombatSystem : AbstractSystem public class CombatSystem : AbstractSystem
{ {
protected override void OnInit() { } protected override void OnInit() { }
@ -297,7 +295,7 @@ public class CombatSystem : AbstractSystem
### Controller 中注册事件 ### Controller 中注册事件
```csharp ``csharp
public partial class GameController : Node, IController public partial class GameController : Node, IController
{ {
private IUnRegisterList _unregisterList = new UnRegisterList(); private IUnRegisterList _unregisterList = new UnRegisterList();
@ -345,7 +343,7 @@ public partial class GameController : Node, IController
### 1. 事件链式组合 ### 1. 事件链式组合
```csharp ``csharp
// 使用 Or 组合多个事件 // 使用 Or 组合多个事件
var onAnyDamage = new OrEvent() var onAnyDamage = new OrEvent()
.Or(onPhysicalDamage) .Or(onPhysicalDamage)
@ -360,7 +358,7 @@ onAnyDamage.Register(() =>
### 2. 事件过滤 ### 2. 事件过滤
```csharp ``csharp
// 只处理高伤害事件 // 只处理高伤害事件
this.RegisterEvent<DamageDealtEvent>(e => this.RegisterEvent<DamageDealtEvent>(e =>
{ {
@ -373,7 +371,7 @@ this.RegisterEvent<DamageDealtEvent>(e =>
### 3. 事件转发 ### 3. 事件转发
```csharp ``csharp
public class EventBridge : AbstractSystem public class EventBridge : AbstractSystem
{ {
protected override void OnInit() protected override void OnInit()
@ -393,7 +391,7 @@ public class EventBridge : AbstractSystem
### 4. 临时事件监听 ### 4. 临时事件监听
```csharp ``csharp
public class TutorialController : Node, IController public class TutorialController : Node, IController
{ {
public override void _Ready() public override void _Ready()
@ -411,7 +409,7 @@ public class TutorialController : Node, IController
### 5. 条件事件 ### 5. 条件事件
```csharp ``csharp
public class AchievementSystem : AbstractSystem public class AchievementSystem : AbstractSystem
{ {
private int _killCount = 0; private int _killCount = 0;
@ -439,7 +437,7 @@ public class AchievementSystem : AbstractSystem
### 使用 UnRegisterList ### 使用 UnRegisterList
```csharp ``csharp
public class MyController : Node, IController public class MyController : Node, IController
{ {
// 统一管理所有注销对象 // 统一管理所有注销对象
@ -465,7 +463,7 @@ public class MyController : Node, IController
### 使用 Godot 节点生命周期 ### 使用 Godot 节点生命周期
```csharp ``csharp
public override void _Ready() public override void _Ready()
{ {
// 当节点退出场景树时自动注销 // 当节点退出场景树时自动注销

View File

@ -6,10 +6,10 @@ Extensions 包提供了一系列扩展方法,简化了框架各个接口的使
## 扩展方法类别 ## 扩展方法类别
### 1. ContextAware 扩展 ([`ContextAwareExtensions.cs`](ContextAwareExtensions.cs)) ### 1. ContextAware 扩展 ([`ContextAwareExtensions.cs`](./extensions.md))
为 [`IContextAware`](../../GFramework.Core.Abstractions/rule/IContextAware.cs) 为 [`IContextAware`](./rule.md)
提供扩展方法,允许直接从实现了 [IContextAware](file:///d:/Project/Rider/GFramework/GFramework.Core.Abstractions/rule/IContextAware.cs) 提供扩展方法,允许直接从实现了 [IContextAware](./rule.md)
的对象获取架构组件。 的对象获取架构组件。
#### GetSystem 扩展方法 #### GetSystem 扩展方法
@ -81,7 +81,7 @@ public class GameModel : AbstractModel, IContextAware
#### SendCommand 扩展方法 #### SendCommand 扩展方法
```csharp ```
// 发送无返回值的命令 // 发送无返回值的命令
public static void SendCommand(this IContextAware contextAware, ICommand command) public static void SendCommand(this IContextAware contextAware, ICommand command)
@ -107,13 +107,13 @@ public class GameController : IController
#### SendQuery 扩展方法 #### SendQuery 扩展方法
```csharp ```
public static TResult SendQuery<TResult>(this IContextAware contextAware, IQuery<TResult> query) public static TResult SendQuery<TResult>(this IContextAware contextAware, IQuery<TResult> query)
``` ```
**使用示例:** **使用示例:**
```csharp ```
public class InventoryController : IController public class InventoryController : IController
{ {
public void ShowInventory() public void ShowInventory()
@ -129,7 +129,7 @@ public class InventoryController : IController
#### SendEvent 扩展方法 #### SendEvent 扩展方法
```csharp ```
// 发送无参事件 // 发送无参事件
public static void SendEvent<T>(this IContextAware contextAware) where T : new() public static void SendEvent<T>(this IContextAware contextAware) where T : new()
@ -139,7 +139,7 @@ public static void SendEvent<T>(this IContextAware contextAware, T e) where T :
**使用示例:** **使用示例:**
```csharp ```
public class PlayerModel : AbstractModel, IContextAware public class PlayerModel : AbstractModel, IContextAware
{ {
public void TakeDamage(int damage) public void TakeDamage(int damage)
@ -164,13 +164,13 @@ public class PlayerModel : AbstractModel, IContextAware
#### RegisterEvent 扩展方法 #### RegisterEvent 扩展方法
```csharp ```
public static IUnRegister RegisterEvent<TEvent>(this IContextAware contextAware, Action<TEvent> handler) public static IUnRegister RegisterEvent<TEvent>(this IContextAware contextAware, Action<TEvent> handler)
``` ```
**使用示例:** **使用示例:**
```csharp ```
public class GameController : IController public class GameController : IController
{ {
private IUnRegisterList _unregisterList = new UnRegisterList(); private IUnRegisterList _unregisterList = new UnRegisterList();
@ -192,13 +192,13 @@ public class GameController : IController
#### UnRegisterEvent 扩展方法 #### UnRegisterEvent 扩展方法
```csharp ```
public static void UnRegisterEvent<TEvent>(this IContextAware contextAware, Action<TEvent> onEvent) public static void UnRegisterEvent<TEvent>(this IContextAware contextAware, Action<TEvent> onEvent)
``` ```
### GetEnvironment 扩展方法 ### GetEnvironment 扩展方法
```csharp ```
public static T? GetEnvironment<T>(this IContextAware contextAware) where T : class public static T? GetEnvironment<T>(this IContextAware contextAware) where T : class
public static IEnvironment GetEnvironment(this IContextAware contextAware) public static IEnvironment GetEnvironment(this IContextAware contextAware)
``` ```
@ -209,7 +209,7 @@ public static IEnvironment GetEnvironment(this IContextAware contextAware)
#### IfType 扩展方法 #### IfType 扩展方法
```csharp ```
// 最简单的类型判断 // 最简单的类型判断
public static bool IfType<T>(this object obj, Action<T> action) public static bool IfType<T>(this object obj, Action<T> action)
@ -230,7 +230,7 @@ public static void IfType<T>(
**使用示例:** **使用示例:**
```csharp ```
object obj = new MyRule(); object obj = new MyRule();
// 简单类型判断 // 简单类型判断
@ -254,7 +254,7 @@ obj.IfType<IRule>(
#### IfType`<T, TResult>` 扩展方法 #### IfType`<T, TResult>` 扩展方法
```csharp ```
public static TResult? IfType<T, TResult>( public static TResult? IfType<T, TResult>(
this object obj, this object obj,
Func<T, TResult> func Func<T, TResult> func
@ -263,7 +263,7 @@ public static TResult? IfType<T, TResult>(
**使用示例:** **使用示例:**
```csharp ```
object obj = new MyRule { Name = "TestRule" }; object obj = new MyRule { Name = "TestRule" };
string? name = obj.IfType<MyRule, string>(r => r.Name); string? name = obj.IfType<MyRule, string>(r => r.Name);
@ -271,7 +271,7 @@ string? name = obj.IfType<MyRule, string>(r => r.Name);
#### As 和 Do 扩展方法 #### As 和 Do 扩展方法
```csharp ```
// 安全类型转换 // 安全类型转换
public static T? As<T>(this object obj) where T : class public static T? As<T>(this object obj) where T : class
@ -281,7 +281,7 @@ public static T Do<T>(this T obj, Action<T> action)
**使用示例:** **使用示例:**
```csharp ```
// 安全类型转换 // 安全类型转换
obj.As<MyRule>() obj.As<MyRule>()
?.Execute(); ?.Execute();
@ -302,7 +302,7 @@ obj.As<MyRule>()
#### SwitchType 扩展方法 #### SwitchType 扩展方法
```csharp ```
public static void SwitchType( public static void SwitchType(
this object obj, this object obj,
params (Type type, Action<object> action)[] handlers params (Type type, Action<object> action)[] handlers
@ -311,7 +311,7 @@ public static void SwitchType(
**使用示例:** **使用示例:**
```csharp ```
obj.SwitchType( obj.SwitchType(
(typeof(IRule), o => HandleRule((IRule)o)), (typeof(IRule), o => HandleRule((IRule)o)),
(typeof(ISystem), o => HandleSystem((ISystem)o)), (typeof(ISystem), o => HandleSystem((ISystem)o)),
@ -325,13 +325,13 @@ obj.SwitchType(
#### OrEventExtensions #### OrEventExtensions
```csharp ```
public static OrEvent Or(this IEvent self, IEvent e) public static OrEvent Or(this IEvent self, IEvent e)
``` ```
**使用示例:** **使用示例:**
```csharp ```
// 组合多个事件:当任意一个触发时执行 // 组合多个事件:当任意一个触发时执行
var onAnyInput = onKeyPressed.Or(onMouseClicked).Or(onTouchDetected); var onAnyInput = onKeyPressed.Or(onMouseClicked).Or(onTouchDetected);
@ -352,7 +352,7 @@ var onAnyDamage = onPhysicalDamage
#### UnRegisterListExtension #### UnRegisterListExtension
```csharp ```
// 添加到注销列表 // 添加到注销列表
public static void AddToUnregisterList(this IUnRegister self, public static void AddToUnregisterList(this IUnRegister self,
IUnRegisterList unRegisterList) IUnRegisterList unRegisterList)
@ -363,7 +363,7 @@ public static void UnRegisterAll(this IUnRegisterList self)
**使用示例:** **使用示例:**
```csharp ```
public class ComplexController : IController public class ComplexController : IController
{ {
private IUnRegisterList _unregisterList = new UnRegisterList(); private IUnRegisterList _unregisterList = new UnRegisterList();
@ -396,7 +396,7 @@ public class ComplexController : IController
### Controller 示例 ### Controller 示例
```csharp ```
public partial class GameplayController : IController public partial class GameplayController : IController
{ {
private IUnRegisterList _unregisterList = new UnRegisterList(); private IUnRegisterList _unregisterList = new UnRegisterList();
@ -448,7 +448,7 @@ public partial class GameplayController : IController
### Command 示例 ### Command 示例
```csharp ```
public class ComplexGameCommand : AbstractCommand public class ComplexGameCommand : AbstractCommand
{ {
protected override void OnExecute() protected override void OnExecute()
@ -473,7 +473,7 @@ public class ComplexGameCommand : AbstractCommand
### System 示例 ### System 示例
```csharp ```
public class AchievementSystem : AbstractSystem public class AchievementSystem : AbstractSystem
{ {
protected override void OnInit() protected override void OnInit()

View File

@ -148,9 +148,9 @@ public IReadOnlyList<T> GetAllSorted<T>(Comparison<T> comparison) where T : clas
### Architecture 中的应用 ### Architecture 中的应用
IoC 容器是 [`Architecture`](../architecture/Architecture.cs) 类的核心组件,用于管理所有的 System、Model 和 Utility。 IoC 容器是 [`Architecture`](./architecture.md) 类的核心组件,用于管理所有的 System、Model 和 Utility。
```csharp ```
public abstract class Architecture : IArchitecture public abstract class Architecture : IArchitecture
{ {
// 内置 IoC 容器 // 内置 IoC 容器
@ -174,7 +174,7 @@ public abstract class Architecture : IArchitecture
### 注册组件到容器 ### 注册组件到容器
```csharp ```
public class GameArchitecture : Architecture public class GameArchitecture : Architecture
{ {
protected override void Init() protected override void Init()
@ -198,7 +198,7 @@ public class GameArchitecture : Architecture
### 从容器获取组件 ### 从容器获取组件
```csharp ```
// 通过扩展方法间接使用 IoC 容器 // 通过扩展方法间接使用 IoC 容器
public class PlayerController : IController public class PlayerController : IController
{ {
@ -218,7 +218,7 @@ public class PlayerController : IController
### 内部实现 ### 内部实现
```csharp ```
public class IocContainer public class IocContainer
{ {
// 使用字典存储类型到实例集合的映射 // 使用字典存储类型到实例集合的映射
@ -313,7 +313,7 @@ IocContainer.Get<T>()
### 基础使用 ### 基础使用
```csharp ```
// 1. 创建容器 // 1. 创建容器
var container = new IocContainer(); var container = new IocContainer();
@ -328,7 +328,7 @@ service.DoSomething();
### 接口和实现分离 ### 接口和实现分离
```csharp ```
// 定义接口 // 定义接口
public interface IDataService public interface IDataService
{ {
@ -365,7 +365,7 @@ dataService.SaveData("game data");
### 注册多个实现 ### 注册多个实现
```csharp ```
var container = new IocContainer(); var container = new IocContainer();
// 注册多个相同接口的不同实现 // 注册多个相同接口的不同实现
@ -385,7 +385,7 @@ var allServices = container.GetAll<IDataService>(); // 返回两个实例的列
检查容器中是否包含指定类型的实例。 检查容器中是否包含指定类型的实例。
```csharp ```
public bool Contains<T>() where T : class public bool Contains<T>() where T : class
``` ```
@ -399,7 +399,7 @@ public bool Contains<T>() where T : class
**使用示例:** **使用示例:**
```csharp ```
var container = new IocContainer(); var container = new IocContainer();
// 检查服务是否已注册 // 检查服务是否已注册
@ -425,7 +425,7 @@ if (!container.Contains<ISettingsService>())
判断容器中是否包含某个具体的实例对象。 判断容器中是否包含某个具体的实例对象。
```csharp ```
public bool ContainsInstance(object instance) public bool ContainsInstance(object instance)
``` ```
@ -439,7 +439,7 @@ public bool ContainsInstance(object instance)
**使用示例:** **使用示例:**
```csharp ```
var container = new IocContainer(); var container = new IocContainer();
var service = new MyService(); var service = new MyService();
@ -469,13 +469,13 @@ if (!container.ContainsInstance(anotherService))
清空容器中的所有实例。 清空容器中的所有实例。
```csharp ```
public void Clear() public void Clear()
``` ```
**使用示例:** **使用示例:**
```csharp ```
var container = new IocContainer(); var container = new IocContainer();
// 注册多个服务 // 注册多个服务
@ -544,7 +544,7 @@ Console.WriteLine($"Contains IService2: {container.Contains<IService2>()}"); //
### 本框架的 IocContainer ### 本框架的 IocContainer
```csharp ```
// 简单直接 // 简单直接
var container = new IocContainer(); var container = new IocContainer();
container.Register(new MyService()); container.Register(new MyService());
@ -563,7 +563,7 @@ var service = container.Get<MyService>();
### 完整的 IoC 框架(如 Autofac、Zenject ### 完整的 IoC 框架(如 Autofac、Zenject
```csharp ```
// 复杂但功能强大 // 复杂但功能强大
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
builder.RegisterType<MyService>().As<IMyService>().SingleInstance(); builder.RegisterType<MyService>().As<IMyService>().SingleInstance();
@ -586,7 +586,7 @@ var controller = container.Resolve<MyController>();
### 1. 在架构初始化时注册 ### 1. 在架构初始化时注册
```csharp ```
public class GameArchitecture : Architecture public class GameArchitecture : Architecture
{ {
protected override void Init() protected override void Init()
@ -609,7 +609,7 @@ public class GameArchitecture : Architecture
### 2. 使用接口类型注册 ### 2. 使用接口类型注册
```csharp ```
// ❌ 不推荐:直接使用实现类 // ❌ 不推荐:直接使用实现类
RegisterSystem(new ConcreteSystem()); RegisterSystem(new ConcreteSystem());
var system = GetSystem<ConcreteSystem>(); var system = GetSystem<ConcreteSystem>();
@ -621,7 +621,7 @@ var system = GetSystem<IGameSystem>();
### 3. 避免运行时频繁注册 ### 3. 避免运行时频繁注册
``` csharp ```
// ❌ 不好:游戏运行时频繁注册 // ❌ 不好:游戏运行时频繁注册
void Update() void Update()
{ {
@ -637,7 +637,7 @@ protected override void Init()
### 4. 检查 null 返回值 ### 4. 检查 null 返回值
```csharp ```
// 获取可能不存在的服务 // 获取可能不存在的服务
var service = container.Get<IOptionalService>(); var service = container.Get<IOptionalService>();
if (service != null) if (service != null)
@ -652,7 +652,7 @@ else
### 5. 合理使用容器冻结 ### 5. 合理使用容器冻结
```csharp ```
// 在架构初始化完成后冻结容器,防止意外修改 // 在架构初始化完成后冻结容器,防止意外修改
protected override void OnInit() protected override void OnInit()
{ {

View File

@ -6,7 +6,7 @@ Logging 包提供了灵活的日志系统,支持多级别日志记录。默认
## 核心接口 ## 核心接口
### [ILogger](ILogger.cs) ### [ILogger](./logging.md)
日志记录器接口,定义了日志记录的基本功能。 日志记录器接口,定义了日志记录的基本功能。
@ -62,7 +62,7 @@ void Fatal(string msg, Exception t);
string Name(); string Name();
``` ```
### [ILoggerFactory](ILoggerFactory.cs) ### [ILoggerFactory](./logging.md)
日志工厂接口,用于创建日志记录器实例。 日志工厂接口,用于创建日志记录器实例。
@ -72,7 +72,7 @@ string Name();
ILogger GetLogger(string name, LogLevel minLevel = LogLevel.Info); ILogger GetLogger(string name, LogLevel minLevel = LogLevel.Info);
``` ```
### [ILoggerFactoryProvider](ILoggerFactoryProvider.cs) ### [ILoggerFactoryProvider](./logging.md)
日志工厂提供程序接口,用于获取日志工厂。 日志工厂提供程序接口,用于获取日志工厂。
@ -83,7 +83,7 @@ ILoggerFactory GetLoggerFactory();
ILogger CreateLogger(string name); ILogger CreateLogger(string name);
``` ```
### [LogLevel](LogLevel.cs) ### [LogLevel](./logging.md)
日志级别枚举。 日志级别枚举。
@ -266,7 +266,7 @@ public class PlayerModel : AbstractModel
### 4. 自定义日志级别 ### 4. 自定义日志级别
```csharp ```
public class DebugLogger : AbstractLogger public class DebugLogger : AbstractLogger
{ {
public DebugLogger() : base("Debug", LogLevel.Debug) public DebugLogger() : base("Debug", LogLevel.Debug)

View File

@ -7,14 +7,14 @@ Model 包定义了数据模型层的接口和基类。Model 是 MVC 架构中的
## 核心接口 ## 核心接口
### [`IModel`](IModel.cs) ### [`IModel`](./model.md)
模型接口,定义了模型的基本行为和功能。 模型接口,定义了模型的基本行为和功能。
**继承的能力接口:** **继承的能力接口:**
- [`IContextAware`](../rule/IContextAware.cs) - 上下文感知接口 - [`IContextAware`](./rule.md) - 上下文感知接口
- [`ILogAware`](../rule/ILogAware.cs) - 日志感知接口 - [`ILogAware`](./rule.md) - 日志感知接口
**核心方法:** **核心方法:**
@ -23,16 +23,16 @@ void Init(); // 初始化模型
void OnArchitecturePhase(ArchitecturePhase phase); // 处理架构阶段事件 void OnArchitecturePhase(ArchitecturePhase phase); // 处理架构阶段事件
``` ```
### [`ICanGetModel`](ICanGetModel.cs) ### [`ICanGetModel`](./model.md)
标记接口,表示实现者可以获取模型。继承自 [`IBelongToArchitecture`](../rule/IBelongToArchitecture.cs)。 标记接口,表示实现者可以获取模型。继承自 [`IBelongToArchitecture`](./rule.md)。
## 核心类 ## 核心类
### [`AbstractModel`](AbstractModel.cs) ### [`AbstractModel`](./model.md)
抽象模型基类实现IModel接口提供模型的基础实现。该类继承自[ 抽象模型基类实现IModel接口提供模型的基础实现。该类继承自[
`ContextAwareBase`](file:///d:/Project/Rider/GFramework/GFramework.Core/rule/ContextAwareBase.cs#L11-L37),提供了上下文感知能力。 `ContextAwareBase`](./rule.md),提供了上下文感知能力。
**使用示例:** **使用示例:**

View File

@ -6,7 +6,7 @@ Property 包提供了可绑定属性BindableProperty的实现支持属
## 核心接口 ## 核心接口
### [`IReadonlyBindableProperty<T>`](IReadonlyBindableProperty.cs) ### [`IReadonlyBindableProperty<T>`](./property.md)
只读可绑定属性接口,提供属性值的读取和变更监听功能。 只读可绑定属性接口,提供属性值的读取和变更监听功能。
@ -26,7 +26,7 @@ IUnRegister RegisterWithInitValue(Action<T> action);
void UnRegister(Action<T> onValueChanged); void UnRegister(Action<T> onValueChanged);
``` ```
### [`IBindableProperty<T>`](IBindableProperty.cs) ### [`IBindableProperty<T>`](./property.md)
可绑定属性接口,继承自只读接口,增加了修改能力。 可绑定属性接口,继承自只读接口,增加了修改能力。
@ -42,7 +42,7 @@ void SetValueWithoutEvent(T newValue);
## 核心类 ## 核心类
### [`BindableProperty<T>`](BindableProperty.cs) ### [`BindableProperty<T>`](./property.md)
可绑定属性的完整实现。 可绑定属性的完整实现。
@ -86,7 +86,7 @@ var position = new BindableProperty<Vector3>(Vector3.Zero)
.WithComparer((a, b) => a.DistanceTo(b) < 0.01f); // 距离小于0.01认为相等 .WithComparer((a, b) => a.DistanceTo(b) < 0.01f); // 距离小于0.01认为相等
``` ```
### [`BindablePropertyUnRegister<T>`](BindablePropertyUnRegister.cs) ### [`BindablePropertyUnRegister<T>`](./property.md)
可绑定属性的注销器,负责清理监听。 可绑定属性的注销器,负责清理监听。
@ -174,7 +174,7 @@ public partial class PlayerUI : Control, IController
### 1. 双向绑定 ### 1. 双向绑定
```csharp ```
// Model // Model
public class SettingsModel : AbstractModel public class SettingsModel : AbstractModel
{ {
@ -203,7 +203,7 @@ public partial class VolumeSlider : HSlider, IController
### 2. 计算属性 ### 2. 计算属性
```csharp ```
public class PlayerModel : AbstractModel public class PlayerModel : AbstractModel
{ {
public BindableProperty<int> Health { get; } = new(100); public BindableProperty<int> Health { get; } = new(100);
@ -228,7 +228,7 @@ public class PlayerModel : AbstractModel
### 3. 属性验证 ### 3. 属性验证
```csharp ```
public class PlayerModel : AbstractModel public class PlayerModel : AbstractModel
{ {
private BindableProperty<int> _health = new(100); private BindableProperty<int> _health = new(100);
@ -252,7 +252,7 @@ public class PlayerModel : AbstractModel
### 4. 条件监听 ### 4. 条件监听
```csharp ```
public class CombatController : Node, IController public class CombatController : Node, IController
{ {
public override void _Ready() public override void _Ready()
@ -279,7 +279,7 @@ public class CombatController : Node, IController
### 1. 避免频繁触发 ### 1. 避免频繁触发
```csharp ```
// 使用 SetValueWithoutEvent 批量修改 // 使用 SetValueWithoutEvent 批量修改
public void LoadPlayerData(SaveData data) public void LoadPlayerData(SaveData data)
{ {
@ -295,7 +295,7 @@ public void LoadPlayerData(SaveData data)
### 2. 自定义比较器 ### 2. 自定义比较器
```csharp ```
// 避免浮点数精度问题导致的频繁触发 // 避免浮点数精度问题导致的频繁触发
var position = new BindableProperty<Vector3>() var position = new BindableProperty<Vector3>()
.WithComparer((a, b) => a.DistanceTo(b) < 0.001f); .WithComparer((a, b) => a.DistanceTo(b) < 0.001f);
@ -305,7 +305,7 @@ var position = new BindableProperty<Vector3>()
### 值变化检测 ### 值变化检测
```csharp ```
// 使用 EqualityComparer<T>.Default 进行比较 // 使用 EqualityComparer<T>.Default 进行比较
if (!EqualityComparer<T>.Default.Equals(value, MValue)) if (!EqualityComparer<T>.Default.Equals(value, MValue))
{ {
@ -316,7 +316,7 @@ if (!EqualityComparer<T>.Default.Equals(value, MValue))
### 事件触发机制 ### 事件触发机制
```csharp ```
// 当值变化时触发所有注册的回调 // 当值变化时触发所有注册的回调
_mOnValueChanged?.Invoke(value); _mOnValueChanged?.Invoke(value);
``` ```

View File

@ -19,7 +19,7 @@ TResult Do(); // 执行查询并返回结果
## 核心类 ## 核心类
### [`AbstractQuery<TInput, TResult>`](AbstractQuery.cs) ### [`AbstractQuery<TInput, TResult>`](./query.md)
抽象查询基类,提供了查询的基础实现。它接受一个泛型输入参数 TInput该参数必须实现 IQueryInput 接口。 抽象查询基类,提供了查询的基础实现。它接受一个泛型输入参数 TInput该参数必须实现 IQueryInput 接口。
@ -34,7 +34,7 @@ public abstract class AbstractQuery<TInput, TResult>(TInput input) : ContextAwar
} }
``` ```
### [`EmptyQueryInput`](EmptyQueryInput.cs) ### [`EmptyQueryInput`](./query.md)
空查询输入类,用于表示不需要任何输入参数的查询操作。 空查询输入类,用于表示不需要任何输入参数的查询操作。
@ -47,7 +47,7 @@ public sealed class EmptyQueryInput : IQueryInput
} }
``` ```
### [`QueryBus`](QueryBus.cs) ### [`QueryBus`](./query.md)
查询总线实现,负责执行查询并返回结果。 查询总线实现,负责执行查询并返回结果。
@ -156,7 +156,7 @@ public partial class ShopUI : Control, IController
### 3. 在 System 中使用 ### 3. 在 System 中使用
```csharp ``csharp
public class CombatSystem : AbstractSystem public class CombatSystem : AbstractSystem
{ {
protected override void OnInit() protected override void OnInit()
@ -185,7 +185,7 @@ this.RegisterEvent<EnemyAttackEvent>(OnEnemyAttack);
### 1. 带参数的复杂查询 ### 1. 带参数的复杂查询
```csharp ``csharp
// 查询指定范围内的敌人列表 // 查询指定范围内的敌人列表
public class GetEnemiesInRangeQuery : AbstractQuery<List<Enemy>> public class GetEnemiesInRangeQuery : AbstractQuery<List<Enemy>>
{ {
@ -209,7 +209,7 @@ var enemies = this.SendQuery(new GetEnemiesInRangeQuery
### 2. 组合查询 ### 2. 组合查询
```csharp ``csharp
// 查询玩家是否可以使用技能 // 查询玩家是否可以使用技能
public class CanUseSkillQuery : AbstractQuery<bool> public class CanUseSkillQuery : AbstractQuery<bool>
{ {
@ -256,7 +256,7 @@ public string SkillId { get; set; }
### 3. 聚合数据查询 ### 3. 聚合数据查询
```csharp ``csharp
// 查询玩家战斗力 // 查询玩家战斗力
public class GetPlayerPowerQuery : AbstractQuery<int> public class GetPlayerPowerQuery : AbstractQuery<int>
{ {
@ -295,7 +295,7 @@ public class GetPlayerInfoQuery : AbstractQuery<PlayerInfo>
### 4. 跨 System 查询 ### 4. 跨 System 查询
```csharp ``csharp
// 在 AI System 中查询玩家状态 // 在 AI System 中查询玩家状态
public class EnemyAISystem : AbstractSystem public class EnemyAISystem : AbstractSystem
{ {
@ -346,7 +346,7 @@ protected override void OnInit() { }
- **返回值**:有返回值 - **返回值**:有返回值
- **示例**:获取金币数量、检查技能冷却、查询玩家位置 - **示例**:获取金币数量、检查技能冷却、查询玩家位置
```csharp ``csharp
// ❌ 错误:在 Query 中修改状态 // ❌ 错误:在 Query 中修改状态
public class BadQuery : AbstractQuery<int> public class BadQuery : AbstractQuery<int>
{ {
@ -392,7 +392,7 @@ public class AddGoldCommand : AbstractCommand
### 1. 缓存查询结果 ### 1. 缓存查询结果
```csharp ``csharp
// 在 Model 中缓存复杂计算 // 在 Model 中缓存复杂计算
public class PlayerModel : AbstractModel public class PlayerModel : AbstractModel
{ {
@ -424,7 +424,7 @@ private int? _cachedPower;
### 2. 批量查询 ### 2. 批量查询
```csharp ``csharp
// 一次查询多个数据,而不是多次单独查询 // 一次查询多个数据,而不是多次单独查询
public class GetMultipleItemCountsQuery : AbstractQuery<Dictionary<string, int>> public class GetMultipleItemCountsQuery : AbstractQuery<Dictionary<string, int>>
{ {

View File

@ -33,7 +33,7 @@ public interface IContextAware
## 核心类 ## 核心类
### [`ContextAwareBase`](ContextAwareBase.cs) ### [`ContextAwareBase`](./rule.md)
上下文感知基类,实现了 IContextAware 接口,为需要感知架构上下文的类提供基础实现。 上下文感知基类,实现了 IContextAware 接口,为需要感知架构上下文的类提供基础实现。
@ -77,7 +77,7 @@ IContextAware (上下文感知接口)
### 1. Component 继承 ContextAwareBase ### 1. Component 继承 ContextAwareBase
```csharp ``csharp
// 组件通过继承 ContextAwareBase 获得架构上下文访问能力 // 组件通过继承 ContextAwareBase 获得架构上下文访问能力
public partial class PlayerController : Node, IController public partial class PlayerController : Node, IController
{ {
@ -99,7 +99,7 @@ public partial class PlayerController : Node, IController
### 2. Command 继承 AbstractCommand (IContextAware) ### 2. Command 继承 AbstractCommand (IContextAware)
```csharp ``csharp
// Command 继承 AbstractCommand自动成为 IContextAware // Command 继承 AbstractCommand自动成为 IContextAware
public class BuyItemCommand : AbstractCommand public class BuyItemCommand : AbstractCommand
{ {
@ -124,7 +124,7 @@ public class BuyItemCommand : AbstractCommand
### 3. 自定义组件遵循规则 ### 3. 自定义组件遵循规则
```csharp ``csharp
// 自定义管理器遵循框架规则,继承 ContextAwareBase // 自定义管理器遵循框架规则,继承 ContextAwareBase
public class SaveManager : ContextAwareBase public class SaveManager : ContextAwareBase
{ {
@ -151,7 +151,7 @@ public class SaveManager : ContextAwareBase
### 1. 组件注册规则 ### 1. 组件注册规则
```csharp ``csharp
public class GameArchitecture : Architecture public class GameArchitecture : Architecture
{ {
protected override void Init() protected override void Init()
@ -166,7 +166,7 @@ public class GameArchitecture : Architecture
### 2. Command/Query 自动注入规则 ### 2. Command/Query 自动注入规则
```csharp ``csharp
// Controller 中发送 Command // Controller 中发送 Command
public class ShopUI : Control, IController public class ShopUI : Control, IController
{ {
@ -200,7 +200,7 @@ public class BuyItemCommand : AbstractCommand
Rule 接口体现了依赖注入DI的思想 Rule 接口体现了依赖注入DI的思想
```csharp ``csharp
// 接口定义了"需要什么" // 接口定义了"需要什么"
public interface IContextAware public interface IContextAware
{ {
@ -225,7 +225,7 @@ public static class CanSendExtensions
Rule 接口遵循接口隔离原则,每个接口职责单一: Rule 接口遵循接口隔离原则,每个接口职责单一:
```csharp ``csharp
// ❌ 不好的设计:一个大接口包含所有能力 // ❌ 不好的设计:一个大接口包含所有能力
public interface IBigInterface public interface IBigInterface
{ {
@ -247,7 +247,7 @@ public interface ICanSendCommand { ... } // 只负责发送 Command
通过接口组合实现不同能力: 通过接口组合实现不同能力:
```csharp ``csharp
// Controller 需要获取 Model 和发送 Command // Controller 需要获取 Model 和发送 Command
public interface IController : ICanGetModel, ICanGetSystem, ICanSendCommand, public interface IController : ICanGetModel, ICanGetSystem, ICanSendCommand,
ICanSendQuery, ICanRegisterEvent ICanSendQuery, ICanRegisterEvent
@ -271,7 +271,7 @@ public interface ISystem : IContextAware, ICanGetModel, ICanGetUtility, ICanGetS
### 自定义规则接口 ### 自定义规则接口
```csharp ``csharp
// 定义新的规则接口 // 定义新的规则接口
public interface ICanAccessDatabase : IBelongToArchitecture public interface ICanAccessDatabase : IBelongToArchitecture
{ {

View File

@ -6,7 +6,7 @@ System 包定义了业务逻辑层Business Logic Layer。System 负责处
## 核心接口 ## 核心接口
### [`ICanGetSystem`](ICanGetSystem.cs) ### [`ICanGetSystem`](./system.md)
标记接口,表示该类型可以获取其他 System。 标记接口,表示该类型可以获取其他 System。
@ -16,7 +16,7 @@ System 包定义了业务逻辑层Business Logic Layer。System 负责处
public interface ICanGetSystem : IBelongToArchitecture public interface ICanGetSystem : IBelongToArchitecture
``` ```
### [`ISystem`](ISystem.cs) ### [`ISystem`](./system.md)
System 接口,定义了系统的基本行为。 System 接口,定义了系统的基本行为。
@ -39,7 +39,7 @@ void OnArchitecturePhase(ArchitecturePhase phase); // 处理架构阶段事件
## 核心类 ## 核心类
### [`AbstractSystem`](AbstractSystem.cs) ### [`AbstractSystem`](./system.md)
抽象 System 基类,提供了 System 的基础实现。继承自 ContextAwareBase具有上下文感知能力。 抽象 System 基类,提供了 System 的基础实现。继承自 ContextAwareBase具有上下文感知能力。
@ -60,7 +60,7 @@ public abstract class AbstractSystem : ContextAwareBase, ISystem
### 1. 定义 System ### 1. 定义 System
```csharp ```
// 战斗系统 // 战斗系统
public class CombatSystem : AbstractSystem public class CombatSystem : AbstractSystem
{ {
@ -115,7 +115,7 @@ public class CombatSystem : AbstractSystem
### 2. 注册 System ### 2. 注册 System
```csharp ```
public class GameArchitecture : Architecture public class GameArchitecture : Architecture
{ {
protected override void Init() protected override void Init()
@ -134,7 +134,7 @@ public class GameArchitecture : Architecture
### 3. 在其他组件中获取 System ### 3. 在其他组件中获取 System
```csharp ```
// 在 Controller 中 // 在 Controller 中
public partial class GameController : Node, IController public partial class GameController : Node, IController
{ {
@ -163,7 +163,7 @@ public class StartBattleCommand : AbstractCommand
### 1. 事件驱动的 System ### 1. 事件驱动的 System
```csharp ```
public class InventorySystem : AbstractSystem public class InventorySystem : AbstractSystem
{ {
protected override void OnInit() protected override void OnInit()
@ -229,7 +229,7 @@ public class InventorySystem : AbstractSystem
### 2. 定时更新的 System ### 2. 定时更新的 System
```csharp ```
public class BuffSystem : AbstractSystem public class BuffSystem : AbstractSystem
{ {
private List<BuffData> _activeBuffs = new(); private List<BuffData> _activeBuffs = new();
@ -281,7 +281,7 @@ public class BuffSystem : AbstractSystem
### 3. 跨 System 协作 ### 3. 跨 System 协作
```csharp ```
public class QuestSystem : AbstractSystem public class QuestSystem : AbstractSystem
{ {
protected override void OnInit() protected override void OnInit()
@ -366,7 +366,7 @@ public class RewardSystem : AbstractSystem
### 4. 管理复杂状态机 ### 4. 管理复杂状态机
```csharp ```
public class GameStateSystem : AbstractSystem public class GameStateSystem : AbstractSystem
{ {
private GameState _currentState = GameState.MainMenu; private GameState _currentState = GameState.MainMenu;
@ -445,7 +445,7 @@ public class GameStateSystem : AbstractSystem
- **特点**:主动,响应事件 - **特点**:主动,响应事件
- **示例**CombatSystem、QuestSystem - **示例**CombatSystem、QuestSystem
```csharp ```
// ✅ 正确的职责划分 // ✅ 正确的职责划分
// Model: 存储数据 // Model: 存储数据
@ -493,7 +493,7 @@ public class CombatSystem : AbstractSystem
### 1. 避免频繁的 GetModel/GetSystem ### 1. 避免频繁的 GetModel/GetSystem
```csharp ```
// ❌ 不好:每次都获取 // ❌ 不好:每次都获取
private void OnUpdate(GameUpdateEvent e) private void OnUpdate(GameUpdateEvent e)
{ {
@ -518,7 +518,7 @@ private void OnUpdate(GameUpdateEvent e)
### 2. 批量处理 ### 2. 批量处理
```csharp ```
public class ParticleSystem : AbstractSystem public class ParticleSystem : AbstractSystem
{ {
private List<Particle> _particles = new(); private List<Particle> _particles = new();

View File

@ -13,7 +13,7 @@ Utility 标记接口,所有工具类都应实现此接口。
**接口定义:** **接口定义:**
```csharp ``csharp
public interface IUtility public interface IUtility
{ {
// 标记接口,无方法定义 // 标记接口,无方法定义
@ -26,7 +26,7 @@ public interface IUtility
**接口定义:** **接口定义:**
```csharp ``csharp
public interface IContextUtility : IUtility public interface IContextUtility : IUtility
{ {
void Init(); // 初始化上下文工具 void Init(); // 初始化上下文工具
@ -35,7 +35,7 @@ public interface IContextUtility : IUtility
## 核心类 ## 核心类
### [`AbstractContextUtility`](AbstractContextUtility.cs) ### [`AbstractContextUtility`](./utility.md)
抽象上下文工具类,提供上下文相关的通用功能实现。继承自 ContextAwareBase 并实现 IContextUtility 接口。 抽象上下文工具类,提供上下文相关的通用功能实现。继承自 ContextAwareBase 并实现 IContextUtility 接口。
@ -139,7 +139,7 @@ public class TimeUtility : IUtility
### 2. 注册 Utility ### 2. 注册 Utility
```csharp ``csharp
public class GameArchitecture : Architecture public class GameArchitecture : Architecture
{ {
protected override void Init() protected override void Init()
@ -154,7 +154,7 @@ public class GameArchitecture : Architecture
### 3. 使用 Utility ### 3. 使用 Utility
```csharp ``csharp
// 在 System 中使用 // 在 System 中使用
public class SaveSystem : AbstractSystem public class SaveSystem : AbstractSystem
{ {
@ -223,7 +223,7 @@ public class MovePlayerCommand : AbstractCommand
### 1. 序列化/反序列化工具 ### 1. 序列化/反序列化工具
```csharp ``csharp
public class JsonUtility : IUtility public class JsonUtility : IUtility
{ {
public string Serialize<T>(T obj) public string Serialize<T>(T obj)
@ -254,7 +254,7 @@ public class JsonUtility : IUtility
### 2. 随机数工具 ### 2. 随机数工具
```csharp ``csharp
public class RandomUtility : IUtility public class RandomUtility : IUtility
{ {
private Random _random = new Random(); private Random _random = new Random();
@ -294,7 +294,7 @@ public class RandomUtility : IUtility
### 3. 字符串工具 ### 3. 字符串工具
```csharp ``csharp
public class StringUtility : IUtility public class StringUtility : IUtility
{ {
public string Truncate(string text, int maxLength, string suffix = "...") public string Truncate(string text, int maxLength, string suffix = "...")
@ -327,7 +327,7 @@ public class StringUtility : IUtility
### 4. 加密工具 ### 4. 加密工具
```csharp ``csharp
public class EncryptionUtility : IUtility public class EncryptionUtility : IUtility
{ {
private const string EncryptionKey = "YourSecretKey123"; private const string EncryptionKey = "YourSecretKey123";
@ -367,7 +367,7 @@ public class EncryptionUtility : IUtility
### 5. 对象池工具 ### 5. 对象池工具
```csharp ``csharp
public class ObjectPoolUtility : IUtility public class ObjectPoolUtility : IUtility
{ {
private Dictionary<Type, Queue<object>> _pools = new(); private Dictionary<Type, Queue<object>> _pools = new();
@ -410,7 +410,7 @@ public class ObjectPoolUtility : IUtility
### 6. 日志工具 ### 6. 日志工具
```csharp ``csharp
public class LogUtility : IUtility public class LogUtility : IUtility
{ {
public enum LogLevel public enum LogLevel
@ -503,7 +503,7 @@ public class CombatSystem : AbstractSystem
## 错误示例 ## 错误示例
```csharp ``csharp
// ❌ 错误Utility 中存储状态 // ❌ 错误Utility 中存储状态
public class BadUtility : IUtility public class BadUtility : IUtility
{ {
@ -543,7 +543,7 @@ public class IdGeneratorSystem : AbstractSystem
### 1. 缓存计算结果 ### 1. 缓存计算结果
```csharp ``csharp
public class PathfindingUtility : IUtility public class PathfindingUtility : IUtility
{ {
private Dictionary<(Vector3, Vector3), List<Vector3>> _pathCache = new(); private Dictionary<(Vector3, Vector3), List<Vector3>> _pathCache = new();
@ -582,7 +582,7 @@ public class PathfindingUtility : IUtility
### 2. 对象复用 ### 2. 对象复用
```csharp ``csharp
public class CollectionUtility : IUtility public class CollectionUtility : IUtility
{ {
private List<Vector3> _tempList = new(); private List<Vector3> _tempList = new();