基本的に、このソリューションを機能させるには、次の2つのことを行う必要があります。
- アニメーションを開始します。
- 次のアニメーションを再生する前に、アニメーションが終了するのを待ちます。
これを行う方法の例は次のとおりです。
animation.PlayQueued("Something");
yield WaitForAnimation(animation);
そして、の定義は次のWaitForAnimation
ようになります。
C#:
private IEnumerator WaitForAnimation (Animation animation)
{
do
{
yield return null;
} while (animation.isPlaying);
}
JS:
function WaitForAnimation (Animation animation)
{
yield; while ( animation.isPlaying ) yield;
}
do-whileループは、PlayQueuedと同じフレームのリターンが呼び出されるanimation.isPlaying
ことを示した実験から得られました。false
少しいじくり回すだけで、次のようにこれを単純化するアニメーションの拡張メソッドを作成できます。
public static class AnimationExtensions
{
public static IEnumerator WhilePlaying( this Animation animation )
{
do
{
yield return null;
} while ( animation.isPlaying );
}
public static IEnumerator WhilePlaying( this Animation animation,
string animationName )
{
animation.PlayQueued(animationName);
yield return animation.WhilePlaying();
}
}
最後に、これをコードで簡単に使用できます。
IEnumerator Start()
{
yield return animation.WhilePlaying("Something");
}
ソース、代替案および議論。