2023-10-14 22:04:18 +08:00
|
|
|
|
### 用键盘代替鼠标来进行游戏操作(Vimlike)
|
|
|
|
|
|
2023-10-08 14:41:14 +08:00
|
|
|
|
### 类似 C# 的 `Linq` 语句
|
|
|
|
|
``` python
|
|
|
|
|
static func square(x):
|
|
|
|
|
return x * x
|
|
|
|
|
|
|
|
|
|
static func is_even(x):
|
|
|
|
|
return x%2 == 0
|
|
|
|
|
|
|
|
|
|
static func sum(accum, y):
|
|
|
|
|
return accum + y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func test():
|
|
|
|
|
var arr : Array
|
|
|
|
|
var boolean : bool
|
|
|
|
|
var item : int
|
|
|
|
|
var obj;
|
|
|
|
|
var number = [1,2,3,4,5,6]
|
|
|
|
|
|
|
|
|
|
arr = number.map(square) # 映射
|
|
|
|
|
arr = number.filter(is_even) # 过滤
|
|
|
|
|
obj = number.reduce(sum,0) # 合并/合并/组合 元素 初始值为0
|
|
|
|
|
number.sort()#排序
|
|
|
|
|
number.sort_custom(func(a,b):return a>b) #自定义排序
|
|
|
|
|
item = number.find(func(item): return item == 5, 0)#获得 其中一个==5 的值, 从 0 开始查询
|
|
|
|
|
boolean = number.all(func(item):return item == 5)#所有==5
|
|
|
|
|
boolean = number.any(func(item):return item == 5)#任何一个==5
|
|
|
|
|
number.shuffle()#乱序
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 单线程异步
|
|
|
|
|
这里的异步本质是等待信号, 完全可以等待一帧的信号来实现逐帧的异步方法, 或者等待Timer实现逐秒的异步操作
|
|
|
|
|
``` python
|
|
|
|
|
func asyns_tween_property(scene_tree : SceneTree, object:Object, tween_property:String, value:Variant, move_time:float):
|
|
|
|
|
var tween = scene_tree.create_tween()
|
|
|
|
|
tween.tween_property(object,tween_property, value, move_time)
|
|
|
|
|
await tween.finished
|
2023-10-14 22:04:18 +08:00
|
|
|
|
```
|