Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active Dec 23, 2020
Embed
What would you like to do?
アニメーションの終了を待つ奴
using UnityEngine;
using System.Collections;
public class Sample : MonoBehaviour
{
private static readonly int hashAttack = Animator.StringToHash("Attack");
private static readonly int hashIdle = Animator.StringToHash("Idle");
[SerializeField]
UnityEngine.UI.Text text;
IEnumerator AttackAnimationFlow()
{
text.text = "攻撃中";
var animator = GetComponent<Animator> ();
animator.Play (hashAttack);
yield return null; // ステートの反映に1フレームいる。解せぬ
yield return new WaitForAnimation (animator, 0);
text.text = "待機中";
}
}
public class WaitForAnimation : CustomYieldInstruction
{
Animator m_animator;
int m_lastStateHash = 0;
int m_layerNo = 0;
public WaitAnimation(Animator animator, int layerNo)
{
Init(animator, layerNo, animator.GetCurrentAnimatorStateInfo(layerNo).nameHash);
}
void Init(Animator animator, int layerNo, int hash)
{
m_layerNo = layerNo;
m_animator = animator;
m_lastStateHash = hash;
}
public override bool keepWaiting {
get {
var currentAnimatorState = m_animator.GetCurrentAnimatorStateInfo (m_layerNo);
return currentAnimatorState.fullPathHash == m_lastStateHash &&
(currentAnimatorState.normalizedTime < 1 );
}
}
}
@akiyama-domi5

This comment has been minimized.

Copy link

@akiyama-domi5 akiyama-domi5 commented Oct 8, 2020

public WaitAnimation(Animator animator, int layerNo)
		{
			Init(animator, layerNo, animator.GetCurrentAnimatorStateInfo(layerNo).nameHash);
		}

みすってますよ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment