Unity UIのアニメーションの終了を待つコルーチンが実行されない。
Unityで、アニメーションするダイヤログを作成中で、非表示にする際のコルーチンが実行されなくて困っています。
ただactiveになったらアニメーションをして表示され、アニメーションをしてからinactiveになるだけの非常にシンプルなものなのですが。
シンプルなだけにどこが原因かわかりません。
どなたかご教授お願いいたします。
以下のサイトを参考に作成しました。
http://tsubakit1.hateblo.jp/entry/2016/02/11/021743
http://chungames.hateblo.jp/entry/2015/11/21/234241
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
C#
1 public class WaitForAnimation : CustomYieldInstruction 2 { 3 Animator m_animator; 4 int m_lastStateHash = 0; 5 int m_layerNo = 0; 6 7 public WaitForAnimation(Animator animator, int layerNo) 8 { 9 Init(animator, layerNo, animator.GetCurrentAnimatorStateInfo(layerNo).nameHash); 10 } 11 12 void Init(Animator animator, int layerNo, int hash) 13 { 14 m_layerNo = layerNo; 15 m_animator = animator; 16 m_lastStateHash = hash; 17 } 18 19 public override bool keepWaiting 20 { 21 get 22 { 23 var currentAnimatorState = m_animator.GetCurrentAnimatorStateInfo(m_layerNo); 24 return currentAnimatorState.fullPathHash == m_lastStateHash && 25 (currentAnimatorState.normalizedTime < 1); 26 } 27 } 28 } 29 public Animator animator; 30 public CanvasGroup switchintractable; 31 public GameObject eventsystem; 32 public Button closebutton; 33 public void Start() 34 { 35 animator = GetComponent<Animator>(); 36 StartCoroutine("Show"); 37 } 38 39 public void HideDialog() 40 { 41 animator = GetComponent<Animator>(); 42 StartCoroutine("Hide"); 43 } 44 IEnumerator Show() 45 { 46 Debug.Log("animation start"); 47 switchintractable.interactable = false; 48 eventsystem.SetActive(false); 49 animator.SetTrigger("show"); 50 yield return null; // ステートの反映に1フレームいる。解せぬ 51 yield return new WaitForAnimation(animator, 0); 52 animator.ResetTrigger("show"); 53 eventsystem.SetActive(true); 54 closebutton.Select(); 55 Debug.Log("animation fix "); 56 57 } 58 IEnumerable Hide() 59 { 60 61 eventsystem.SetActive(false); 62 animator.SetTrigger("hide"); 63 Debug.Log("animation start"); 64 yield return null; // ステートの反映に1フレームいる。解せぬ 65 yield return new WaitForAnimation(animator, 0); 66 Debug.Log("animation fix "); 67 animator.ResetTrigger("hide"); 68 eventsystem.SetActive(true); 69 switchintractable.interactable = true; 70 gameObject.SetActive(false); 71 }
試したこと
コードをシンプルに書き直したり等いろいろ試してみたのですが、なぜか"Hide"コルーチンだけが実行されませんでした。
補足情報(FW/ツールのバージョンなど)
unity 2017.3.1f1 64bit personal
windows 10 home

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/16 04:22