我喜欢协程。它们就像是自我维持的代码,但问题是它们是在unity框架中的特定时间调用的。根据this的说法,大多数协程都是在更新之后但在动画之前调用的。我想有一个协程类型的系统,可以在内部动画更新之后,但在场景渲染之前调用。这是因为我在动画之后编辑3D模型变换(不依赖于动画)。该怎么做呢?我在C#工作。
发布于 2016-07-07 00:11:54
正如您自己提供的链接中所描述的,这是不可能的。引擎按照它的工作方式工作,这不能从“脚本级别”改变。
然而,如果你坚持使用协程,你可以做的就是让它们只是“准备你的代码的执行”,而把这项工作留给LateUpdate()。
要做到这一点,你应该这样做(有点伪代码,因为它是未经测试的)
bool hasToUpdate = false; //class variable
private void LateUpdate() {
if (hasToUpdate == false) { return; } //I don't like "!" or leave "{}"
//do the stuff you want to do between 'game logic' and 'rendering'
//the thing you most probably do now in your coroutine code
hasToUpdate = false;
}
private void YourCoroutine() {
//if happened what you want / there was the expected
//user interaction, yield returned, etc, set class variables
//to the proper value (if there's anything like that), etc:
//i.e. move out values from coroutine code to class
//level and set calculated values you need to set, then:
hasToUpdate = true;
}这样,你的协程任务将在你想要的地方执行,并且以你想要的方式执行,但是,即使这应该可以工作,它对我来说也“有点老生常谈”。
不管怎么说。如果没有具体的问题或没有代码,很难说出更多信息,但我希望这会有所帮助。干杯。
https://stackoverflow.com/questions/38227687
复制相似问题