更新Readme
和CPS验证场景
This commit is contained in:
142
README.md
142
README.md
@@ -12,7 +12,7 @@
|
||||
该项目为`基准演示`,主要通过一些场景展现该软件的所有功能
|
||||
|
||||
由于Godot未提供相关的编辑器功能(例如`暴露可编辑的class`和`自定义接口实例`),该项目的进度并没有`Unity`的实现速度快
|
||||
|
||||
***
|
||||
## Installation 安装过程
|
||||
1.首先你需要安装 **Godot4.0.3 Net** 👉[GodotEngine.Net](https://godotengine.org/download/windows/)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
3.最后在**Godot**中导入**iFactory.Godot**
|
||||
|
||||
4.安装完成⭐
|
||||
|
||||
***
|
||||
## Features 功能与模块
|
||||
### 场景介绍
|
||||
* #### 基于AGV小车提供的三维环境感知场景
|
||||
@@ -139,5 +139,141 @@
|
||||
- [ ] 基于HTML或类HTML的`用户界面框架`——统一技术栈,使用html编写用户界面,例如`Html`和`Unity.UI Toolkit`的关系
|
||||
- [ ] `标识解析`——支持手动注册与解析标识
|
||||
- [ ] `实训平台`——提供线上教学线下考试的服务
|
||||
***
|
||||
## Getting Started 使用指南
|
||||
所有注释和指南都包括在代码中,用例正在编写中
|
||||
所有注释和指南都包括在代码中,用例正在编写中
|
||||
### 依赖注入
|
||||
基于`Microsoft.Extensions.DependencyInjection`的依赖注入服务
|
||||
用例:
|
||||
#### 注册服务
|
||||
```csharp
|
||||
public interface IService{}
|
||||
public class MyService:Node,IService
|
||||
{
|
||||
//注入服务
|
||||
BITApp.ServiceCollection.AddSingleton<IService>(this);
|
||||
}
|
||||
```
|
||||
#### 注入服务
|
||||
##### 初始化加载(可能遇到服务还没注入的情况)
|
||||
```csharp
|
||||
public class MyService:Node
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
var myService = BITApp.ServiceProvider.GetService<IService>();
|
||||
}
|
||||
}
|
||||
```
|
||||
##### 基于封装的懒加载
|
||||
```csharp
|
||||
public class MyService:Node
|
||||
{
|
||||
//声明懒加载服务
|
||||
private readonly ServiceLoader<IService> myService=new();
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
//如果服务未加载,则跳过执行
|
||||
if(myService.Loaded is false)return;
|
||||
//获取服务
|
||||
var _myService = myService.Value;
|
||||
//执行
|
||||
_myService.DoSomething();
|
||||
}
|
||||
}
|
||||
```
|
||||
***
|
||||
### 实体,数据与系统的结构
|
||||
> Root/场景
|
||||
> > `Service` \ `System` 处理逻辑和数据的服务或系统
|
||||
> > > `RotationService` 获取数据并应用角度的服务
|
||||
>
|
||||
> > `Entity` 存放数据的基本实体
|
||||
> > > `RotationComponent`存放数据的组件,例如角度偏移`Offset`和角度权重`Weight`等数据
|
||||
### 创建基本组件
|
||||
组件需要继承自`EntityComponent`或者`IEntityComponent`,这样`Entity`才能识别并注册组件
|
||||
```csharp
|
||||
//基本的角度组件
|
||||
/// <summary>
|
||||
/// ECS中iFactory.Rotation的角度组件
|
||||
/// </summary>
|
||||
public partial class RotationComponent : EntityComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取角度的路径
|
||||
/// </summary>
|
||||
[Export] public string Path { get; private set; }
|
||||
/// <summary>
|
||||
/// 角度的绝对权重,例如90* (0,0,1) = 0,0,90
|
||||
/// </summary>
|
||||
[Export] public Vector3 Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// 角度的相对偏移
|
||||
/// </summary>
|
||||
[Export] public Vector3 Offset { get; private set; }
|
||||
/// <summary>
|
||||
/// 默认角度的缓存
|
||||
/// </summary>
|
||||
public Vector3 OriginalEuler { get; private set; }
|
||||
public override void _Ready()
|
||||
{
|
||||
//保存默认角度
|
||||
OriginalEuler = Rotation;
|
||||
}
|
||||
}
|
||||
```
|
||||
### 创建服务
|
||||
基于场景的服务,可直接放入场景中的节点即可
|
||||
|
||||
基于全局的服务,可在Godot.ProjectSettings.AutoLoad中添加自动加载
|
||||
#### 非ECS服务
|
||||
```csharp
|
||||
public partial class RotationService:Node
|
||||
{
|
||||
//在构造函数中注入依赖
|
||||
public ApplyRotationService()
|
||||
{
|
||||
BITApp.ServiceCollection.AddSingleton(this);
|
||||
}
|
||||
//非基于ECS的注册方式,例如Node在_Ready回调中调用该方法注册
|
||||
public static void Register(IObj obj);
|
||||
//基于非ECS的注册方式,例如Node在Dispose方法中调用该方法注销
|
||||
public static void UnRegister(IObj obj)
|
||||
//通常情况下,Register和UnRegister最好使用Queue作为队列的方式注册和注销元素,而非List<T>.Add和List<T>.Remove
|
||||
//使用消息队列可以解决异步中动态注册和注销导致队列被更改的问题
|
||||
public override _Process(double delta)
|
||||
{
|
||||
//在这里遍历已注册的元素,并
|
||||
foreach(var element in registriedElement)
|
||||
{
|
||||
//你的Code,不,是你的Code
|
||||
element.Rotation = new(0,1,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
#### 基于ECS的服务(System)
|
||||
目前`IEntitiesService`的实例为`GodotEntitiesService`
|
||||
```csharp
|
||||
public partial class RotationService:Node
|
||||
{
|
||||
//在构造函数中注入依赖
|
||||
public ApplyRotationService()
|
||||
{
|
||||
BITApp.ServiceCollection.AddSingleton(this);
|
||||
}
|
||||
public override _Process(double delta)
|
||||
{
|
||||
foreach(var entity in EntitiesManager.Query<RotationComponent>())
|
||||
{
|
||||
if(entity.TryGetComponent<RotationComponent>(out var rotationComponent)
|
||||
{
|
||||
//获取该组件的角度
|
||||
var angle = //你的Code
|
||||
//应用组件计算后的角度
|
||||
rotationComponent.Rotation = angle * rotationComponent.Weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user