mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-23 03:04:29 +08:00
- 将所有小写的命名空间导入更正为首字母大写格式 - 统一 GFramework 框架的命名空间引用规范 - 修复 core、ecs、godot 等模块的命名空间导入错误 - 标准化文档示例代码中的 using 语句格式 - 确保所有文档中的命名空间引用保持一致性 - 更新 global using 语句以匹配正确的命名空间格式
4.5 KiB
4.5 KiB
安装配置
GFramework 提供多种安装方式,您可以根据项目需求选择合适的包进行安装。
包选择说明
GFramework 采用模块化设计,不同包提供不同的功能:
| 包名 | 说明 | 适用场景 |
|---|---|---|
GeWuYou.GFramework |
聚合元包 | 快速试用、原型开发 |
GeWuYou.GFramework.Core |
核心框架 | 生产项目推荐 |
GeWuYou.GFramework.Game |
游戏模块 | 需要游戏特定功能 |
GeWuYou.GFramework.Godot |
Godot集成 | Godot项目必需 |
GeWuYou.GFramework.SourceGenerators |
源码生成器 | 推荐安装 |
安装方式
1. 使用 .NET CLI(推荐)
# 核心能力(推荐最小起步)
dotnet add package GeWuYou.GFramework.Core
dotnet add package GeWuYou.GFramework.Core.Abstractions
# 游戏扩展
dotnet add package GeWuYou.GFramework.Game
dotnet add package GeWuYou.GFramework.Game.Abstractions
# Godot 集成(仅 Godot 项目需要)
dotnet add package GeWuYou.GFramework.Godot
# 源码生成器(可选,但推荐)
dotnet add package GeWuYou.GFramework.SourceGenerators
2. 使用 PackageReference
在您的 .csproj 文件中添加:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<!-- 核心框架 -->
<PackageReference Include="GeWuYou.GFramework.Core" Version="1.0.0" />
<PackageReference Include="GeWuYou.GFramework.Core.Abstractions" Version="1.0.0" />
<!-- 游戏模块 -->
<PackageReference Include="GeWuYou.GFramework.Game" Version="1.0.0" />
<PackageReference Include="GeWuYou.GFramework.Game.Abstractions" Version="1.0.0" />
<!-- Godot 集成 -->
<PackageReference Include="GeWuYou.GFramework.Godot" Version="1.0.0" />
<!-- 源码生成器 -->
<PackageReference Include="GeWuYou.GFramework.SourceGenerators" Version="1.0.0"
PrivateAssets="all" ExcludeAssets="runtime" />
</ItemGroup>
</Project>
3. 使用 NuGet Package Manager
在 Visual Studio 中:
- 右键点击项目 → 管理 NuGet 程序包
- 搜索
GeWuYou.GFramework - 选择需要的包进行安装
环境要求
运行时要求
- .NET 6.0 或更高版本
- Godot 4.5+(仅 Godot 项目)
开发工具
- Visual Studio 2022 或 VS Code
- .NET 6.0 SDK
- Godot 4.5+(可选,仅 Godot 项目需要)
项目配置
1. 基础配置
创建 GlobalUsings.cs 文件:
global using GFramework.Core;
global using GFramework.Core.Architecture;
global using GFramework.Core.Command;
global using GFramework.Core.Events;
global using GFramework.Core.Model;
global using GFramework.Core.Property;
global using GFramework.Core.System;
global using GFramework.Core.Utility;
2. Godot 项目配置
如果使用 Godot 集成,需要在项目设置中启用 C# 支持:
- 在 Godot 编辑器中打开项目设置
- 导航到
Mono→Editor Settings - 确保启用了 C# 支持
3. 源码生成器配置
源码生成器会自动工作,无需额外配置。如果需要自定义生成器行为,可以在项目文件中添加:
<PropertyGroup>
<GFrameworkLogLevel>Debug</GFrameworkLogLevel>
<GFrameworkGenerateEnums>true</GFrameworkGenerateEnums>
</PropertyGroup>
验证安装
创建一个简单的测试来验证安装是否成功:
using GFramework.Core.Architecture;
// 定义简单的架构
public class TestArchitecture : Architecture
{
protected override void Init()
{
// 注册一个简单的模型
RegisterModel(new TestModel());
}
}
public class TestModel : AbstractModel
{
public BindableProperty<string> Message { get; } = new("Hello GFramework!");
}
// 测试代码
var architecture = new TestArchitecture();
architecture.Initialize();
var model = architecture.GetModel<TestModel>();
Console.WriteLine(model.Message.Value); // 输出: Hello GFramework!
常见问题
1. 包版本冲突
如果遇到版本冲突,建议:
dotnet restore --force
dotnet clean
dotnet build
2. Godot 集成问题
确保:
- Godot 版本 >= 4.5
- 已正确安装 Godot C# 模板
- 项目引用了正确的 Godot 包
3. 源码生成器不工作
检查:
- 确保安装了
GeWuYou.GFramework.SourceGenerators - 重启 IDE
- 清理并重新构建项目