Godot Best practices

Get Forward Vector

python 复制代码
transform.x
# 等价手算
var rad = node.rotation
var forward = Vector2(cos(rad), sin(rad))

Await and Unity Style Coroutine

python 复制代码
func coroutine(on_update: Callable, duration: float = 1):
	var elapse_time = 0
	while elapse_time < 1:
		elapse_time += get_process_delta_time() / duration
		on_update.call(elapse_time)
		await get_tree().process_frame # 等待下一帧

# normal call - 后续逻辑会在 while loop 执行一次后立刻执行
coroutine(func(): print("do coroutine"))
# test debug
start
do coroutine
end
do coroutine
do coroutine
...
# await call - 后续逻辑会等到 coroutine 执行完成之后才会执行
await coroutine(func(): print("do coroutine"))
# test debug
start
do coroutine
do coroutine
...
end
相关推荐
小李也疯狂1 天前
Unity 中的立方体贴图(Cubemaps)
unity·游戏引擎·贴图·cubemap
呆呆敲代码的小Y1 天前
【Unity工具篇】| 超实用工具LuBan,快速上手使用
游戏·unity·游戏引擎·unity插件·luban·免费游戏·游戏配置表
EQ-雪梨蛋花汤1 天前
【Unity优化】Unity多场景加载优化与资源释放完整指南:解决Additive加载卡顿、预热、卸载与内存释放问题
unity·游戏引擎
我的offer在哪里1 天前
用 Unity 从 0 做一个「可以玩的」游戏,需要哪些步骤和流程
游戏·unity·游戏引擎
泡泡茶壶ᐇ1 天前
Unity游戏开发入门指南:从零开始理解游戏引擎核心概念
unity·游戏引擎
Var_al2 天前
抖小Unity WebGL分包命令行工具实践指南
unity·游戏引擎·webgl
天人合一peng2 天前
unity 通过代码修改button及其名字字体的属性
unity·游戏引擎
GLDbalala2 天前
Unity基于自定义管线实现经典经验光照模型
unity·游戏引擎
心疼你的一切2 天前
Unity异步编程神器:Unitask库深度解析(功能+实战案例+API全指南)
深度学习·unity·c#·游戏引擎·unitask
呆呆敲代码的小Y2 天前
【Unity 实用工具篇】 | Book Page Curl 快速实现翻书效果
游戏·unity·游戏引擎·u3d·免费游戏·翻书插件