前言
Godot 官方 教程
Godot 2d 官方案例C#重构 专栏
Godot 2d 重构 github地址
实现效果

技术点说明
异步函数
Godot的事件不能在Task中运行,因为会导致跨线程的问题。
//这样是不行的,因为跨线程了,而且会阻塞UI线程,具体原因不知
void Button(){
Task.run(()=>{
Task.Delay(1000);
Label.Text = "Hello Godot";
}).Wait();
}
//为了实现异步效果,这样子可以
void async void Button(){
await Task.Delay(1000);
Label.Text = "Hello Godot";
}
但是使用async void 会导致无法捕获到异常抛出,具体情况看一下相关视频
停止在 C# 中使用 async void!改为这样做。
C#异步编程的入门概念及核心理念
信号控制
//设置信号,注意delegate命名是要以EventHandler结尾
[Signal]
public delegate void StartGameEventHandler();
//主动触发信号,是去掉后面的EventHandler之后的名称
EmitSignal(SignalName.StartGame);
线段返回随机点位置
使用[Path2d]和[PathFollow2D]组合,批量获取点
如果上下级结构

在Path上面添加点来描述路径



获取路径上的随机点
public PathFollow2D MobPathFollow2D;
//设置随机位置
MobPathFollow2D.Progress = GD.Randi();
这个时候返回的值为
- MobPathFollow2D
- Position:随机点的2D位置
- Rotation:随机点的路径切线方向

![2023年中国人力资源咨询发展历程及市场规模前景分析[图]](https://img-blog.csdnimg.cn/img_convert/2ab417914ba1299e9cfe55bf9219f1b3.png)














![[数据挖掘、数据分析] clickhouse在go语言里的实践](https://img-blog.csdnimg.cn/20590f632f7f4299a7867cfad9832d9e.png)


![2023年中国水稻收割机产量、销量及市场规模分析[图]](https://img-blog.csdnimg.cn/img_convert/c96b2b29f57ec31935a1d87b4375b5de.png)