Coroutine 中 "yield return 0" 和 "yield return null" 有什么区别?
What is the difference between "yield return 0" and "yield return null" in Coroutine?
我是新手,对“yield
”有点困惑。但最后我明白了它是如何使用 WaitForSeconds
但我看不出“yield return 0
”和“yield return null
”之间的区别。
他们都在等待下一帧执行吗?
抱歉我的英语不好。非常感谢。
我想你甚至可以 "yield return;",关于协程,最终结果是一样的;
产量return就像说"Return control now to the caller, but when i am called again continue from my previous state"
yield return 0
和 yield return null
都产生了单帧。最大的区别是 yield return 0
分配内存是因为 0
的装箱和拆箱发生在幕后,但是 yield return null
不 分配内存.因此,如果您关心性能,强烈建议使用 yield return null
。
我是新手,对“yield
”有点困惑。但最后我明白了它是如何使用 WaitForSeconds
但我看不出“yield return 0
”和“yield return null
”之间的区别。
他们都在等待下一帧执行吗?
抱歉我的英语不好。非常感谢。
我想你甚至可以 "yield return;",关于协程,最终结果是一样的;
产量return就像说"Return control now to the caller, but when i am called again continue from my previous state"
yield return 0
和 yield return null
都产生了单帧。最大的区别是 yield return 0
分配内存是因为 0
的装箱和拆箱发生在幕后,但是 yield return null
不 分配内存.因此,如果您关心性能,强烈建议使用 yield return null
。