Replies: 1 comment
-
|
可以,这个很实用, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Ant 中的 prefab instance 创建都是异步的,需要在
on_ready回调函数中写异步创建完毕后的业务逻辑。我这几天自己用的时候,做了点封装,让代码写起来更舒服一些。目前的写法类似 test/simple 中的用法:
通常,创建 instance 发生在场景初始化或由某个消息触发,这个流程一般是独立的。但这个独立流程中,会有多个 instance 的创建的过程,这些 instance 可能相互依赖,必须等前一个创建完毕,才方便设置后面的状态。
我把这批 instance 创建过程抽象成一个叫
async_instance的过程,用 coroutine 简化它的编写流程,我写了这么一个辅助模块:然后,前面的创建代码就可以改为:
如果是同时创建两个 instance ,不必等第一个创建 ready 后再创建下一个,可以写成:
或者,inst2 可以使用 async:create_instance 省掉写 async.wait()
Beta Was this translation helpful? Give feedback.
All reactions