您当前的位置: 首页 >  unity

Jave.Lin

暂无认证

  • 1浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

[译文] Unity - Mecanim Transitions interruptions - Unity Mecanim状态机转换中断(主要是Intteruption Source)

Jave.Lin 发布时间:2019-05-18 12:57:53 ,浏览量:1

References

Unity Blog - Wait, I’ve changed my mind! State Machine Transition interruptions

翻译:有道、百度 + 自己调整

Wait, I’ve changed my mind! State Machine Transition interruptions

Catherine Proulx, July 13, 2016

等等,我改变主意了!状态机转换中断

–凯瑟琳·普罗克斯,2016年7月13日

I recently investigated a tricky bug reported by a user involving the combination of empty states, override layers, and transition interruptions. As I was digging in, I found that our documentation about transition interruptions in the animation system was a bit… minimalist. A long conversation with my team later, we concluded that a blog post was in order.

我最近调查了一个用户报告的棘手的bug,它涉及空状态、覆盖层和转换中断的组合。在我深入研究的过程中,我发现我们关于动画系统中转换中断的文档有点……极简主义。后来与我的团队进行了一次长时间的交谈,我们得出结论,一篇博客文章已经准备就绪。

So let’s dive into some intricate details of State Machine Transitions and interruptions!

因此,让我们深入研究状态机转换和中断的一些复杂细节!

By default in the animation system, transitions cannot be interrupted: once you start going from one state to the other, there’s no way out. Like a passenger on a transatlantic flight, you’re cozily nestled in your seat until you reach your destination and you can’t change your mind. For most users, this is fine.

在动画系统中,默认情况下,转换不能被中断:一旦你开始从一种状态转换到另一种状态,就没办法终端了。就像跨大西洋航班上的乘客一样,你舒适地坐在座位上,直到到达目的地,你不能改变主意。对于大多数用户来说,这很好。

But if you need more control over transitions, Mecanim can be configured in a variety of ways to meet your needs. If you’re unhappy with your current destination, you can hop in the pilot’s seat and can change plans midway through your flight. This means more responsive animations, but also many opportunities to get lost in the complexity.

但是,如果您需要对转换进行更多的控制,Mecanim可以通过多种方式进行配置,以满足您的需要。如果你对目前的目的地不满意,你可以坐在飞行员的座位上,在飞行中途改变计划。这意味着动画系统需要更强的功能,但同时会增加系统复杂度,导致学些成本会变大。

So let’s walk through a few examples to sort that out. We can begin with a fairly simple state machine with four states, labeled A to D, and triggers hooked to every transition on the state machine.

所以让我们通过几个例子来解决这个问题。我们可以从一个相当简单的状态机开始,它有四个状态,标签A状态到D状态,并且触发器参数与状态机上的每个转换挂钩。

在这里插入图片描述 By default, when we trigger the A->B transition, our state machine transitions towards B and nothing can keep it from reaching its destination. But if we go on the A->B transition inspector and change the interruption source from “None” to “Current State”, our journey from A to B can be interrupted by some triggers on state A.

默认情况下,当我们触发A->B转换时,状态机将向B转换,任何东西都无法阻止它到达目的地。但是,如果我们现在在inspector中将A->B转换的中断源设置为:从原来的“无”(None)更改为“当前状态”(Current State),我们从A到B的过程可能会被状态A上的一些触发器中断。

在这里插入图片描述 Why only “some”? Because the “Ordered Interruption” checkbox is also checked by default. This means only transitions on state A that have a higher priority than the current one are allowed. Looking at the inspector of state A, we can see that this only applies to the A->C transition.

为什么只有“一些”?因为“有序中断”(Ordered Interruption)复选框在默认情况下也被选中。这意味着只允许在优先级高于当前优先级的状态A上进行转换。看看状态A的检查器,我们可以看到这只适用于A->C转换。

在这里插入图片描述 So if we activate the A->B trigger, then shortly after the A->D trigger, our transition remains uninterrupted. However, if we press the A->C trigger instead, then the transition is immediately interrupted and the state machine starts transitioning towards C.

因此,如果我们激活A->B触发器,然后在A->D触发器之后不久,我们的转换将保持不间断。但是,如果我们按下A->C触发器,则转换立即中断,状态机开始向C转换。

Internally, the animation system records the pose at the time of the interruption, and will now blend between that static pose (X) and the new destination animation. image04

在内部,动画系统记录中断时的姿势,现在将在静态姿势(X)和新目标动画之间混合。图像04

在这里插入图片描述 Why a static pose, instead of a possibly smoother blend between the current and new transitions? Simply put: performance. When a game faces a cascade of interruptions, keeping track of several dynamic transitions taking place simultaneously would quickly made the animation system unscalable.

为什么是静态姿势,而不是当前和新过渡之间可能更平滑的混合?简而言之:性能。当一个游戏面临一连串的中断时,同时跟踪几个动态转换将很快使动画系统不可伸缩。

Now, if we uncheck that “Ordered Interruption” checkbox, then both A->C and A->D can interrupt the transition. However, if they are both triggered on the same frame, A->C will still take precedence because it has a higher priority.

现在,如果我们取消选中“有序中断”(Ordered Interruption)复选框,那么A->C和A->D都可以中断转换。但是,如果它们都在同一帧上触发,则A->C仍然优先,因为它具有更高的优先级。

If we change the interruption source to “Next State”, A->C and A->D can no longer interrupt the transition, regardless of their order. However, if we press the B->D trigger, we will immediately start transitioning from A to D, without completing the transition towards B.

如果我们将中断源更改为“下一个状态”(Next State),A->C和A->D就不能再中断转换,不管它们的顺序如何。但是,如果我们按下b->d触发器,我们将立即开始从a转换到d,就算还没完成a向b的转换。

Transition order matters on state B too. The “Ordered Interruption” checkbox is not available anymore (any triggered transition on B can interrupt the transition because they do not have a priority ranking relative to A->B), but the order of the transitions on B will determine which transition wins if both are triggered within the same frame. In this case, if B->D and B->C are triggered in the same frame, B->D will be selected.

B状态的转换优先级也很重要。“有序中断”(Ordered Interruption)复选框不去掉选中后(B上的任何触发的转换都可以中断转换,因为它们没有相对于A->B的优先级排名),但B上的转换顺序将决定如果两个都在同一帧内触发,哪个转换会获胜。在这种情况下,如果在同一帧中触发b->d和b->c,则选择b->d。

在这里插入图片描述 Finally, for complete control, we can set the Interruption Source to “Current State Then Next State”, or “Next State Then Current State”. In that case, the transitions will be analyzed independently on one state, then the other.

最后,为了完全控制,我们可以将中断源设置为“先当前状态再是下一个状态”(Current State Then Next State),或者“先下一个状态再是当前状态”(Next State Then Current State)。在这种情况下,转换将在一种状态下进行独立分析,然后在另一种状态下进行分析。

So, let’s assume we have the following configuration.

那么,假设我们有以下配置。

在这里插入图片描述 During the A->B transition, a very excited player triggers four transitions within the same frame: A->C, A->D, B->C and B->D. What happens?

在A->B转换过程中,一个非常兴奋的玩家在同一帧内触发四个转换:A->C、A->D、B->C和B->D。接下来会发生什么?

First, “Ordered Interruption” is checked, so we can ignore A->D right away: it has lower priority than A->B. The current state gets resolved first, so we do not even have to look at state B to know that transition A->C wins.

首先,选中“有序中断”(Ordered Interruption),这样我们就可以立即忽略a->d:它的优先级低于a->b。当前状态(Current State)的中断源首先是可以的,所以我们甚至不必查看状态b就知道转换a->c获胜。

在这里插入图片描述 在这里插入图片描述 However, with the same configuration, if only B->C and B->D get triggered, transition B->D will take place (it has greater precedence than B->C).

但是,在相同的配置下,如果只触发b->c和b->d,则会发生转换b->d(它的优先级高于b->c)。

Now, this is only for one transition… All other transitions can also be interruptible too, with their own specific rules. So if we make transition A->C interruptible from the next state, we can have transition A->B interrupted by A->C which in turn could be interrupted by C->D.

现在,这只适用于一个转换……所有其他转换也可以被中断,和制定设置后的特定规则。因此,如果我们A->C转换的中断源设置为:下一个状态中断(Next State),我们可以得到转换A->B被A->C中断,而A->C又可以被C->D中断。

One important thing to keep in mind: regardless of interruptions taking place, the source state remains the same until the transition is complete, and Animator.GetCurrentAnimatorStateInfo() will always return that source state.

要记住一件重要的事情:不管中断源你设置了什么,如果状态在处于转换结束前,源(当前)状态是不会变得,即,在这期间,你调用animator.getcurrentAnimatorStateInfo()将始终返回该源(当前)状态。

In short, transition interruptions settings are powerful and offer a lot of flexibility, but they can quickly become very confusing. So use transition interruptions wisely, and when in doubt, test it out in the Editor.

简言之,转换中断设置功能强大且具有很大的灵活性,但它们很容易就会概念混乱。因此,明智地使用转换中断,当有疑问时,在编辑器中测试它。

感言

不得不说,官方的手册说明真的太“精简”了。 精简到没人能看懂,但是还好的是,后来又人在Unity Blog写了这篇文章。 才得以理解。

源官方手册说明点击以下链接 官方手册对Transition Interruption说明

我把那个Interrruption Source的设置类似放这,大家看看就知道有多精简到看不懂

ValueFunctionNoneDon’t add any more transitions.Current StateQueue the transitions from the current state.Next StateQueue the transitions from the next state.Current State then Next StateQueue the transitions from the current state, then queue the ones from the next state.Next State then Current StateQueue the transitions from the next state, then queue the ones from the current state.

总之,学习路上最令人觉得恶心的就是那些,说一半又不说清楚的文章、教程。

在看完上面教程后,可以再去看看这篇说明,相当于一个总结吧: https://blog.csdn.net/u010906268/article/details/72976268

关注
打赏
1664331872
查看更多评论
立即登录/注册

微信扫码登录

0.0424s