Last active
July 3, 2017 16:35
-
-
Save onionmk2/c44955803780073d7c23ca12a730c157 to your computer and use it in GitHub Desktop.
Behavior Designer Animation Action sample.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Linq; | |
using System.Reflection; | |
using BehaviorDesigner.Runtime.Tasks; | |
using UnityEngine; | |
internal class DamageAction : Action | |
{ | |
private Animator animator; | |
private bool isCoroutineRunning; | |
private bool isAnimationRunning; | |
public override void OnStart() | |
{ | |
animator = GetComponent<Animator>(); | |
StartCoroutine(PlayAnimation()); | |
} | |
public override TaskStatus OnUpdate() | |
{ | |
return isCoroutineRunning ? TaskStatus.Running : TaskStatus.Success; | |
} | |
private IEnumerator PlayAnimation() | |
{ | |
isCoroutineRunning = true; | |
// start playing animation | |
{ | |
var hash = AnimatorSettingConst.Alicia.StateHashes.Body_Damage; | |
animator.Play(hash); | |
isAnimationRunning = true; | |
} | |
// wait until end of the Body_Damage animation | |
while (isAnimationRunning) | |
{ | |
yield return null; | |
yield return new WaitAnimation(animator, 0); | |
isAnimationRunning = false; | |
} | |
// Body_Damage以外への、何らかのstateへの移行を「開始」しない限り、 | |
// currentAnimatorState.normalizedTime が1を超えて増え続け、 | |
// normalizedTimeが常に1を超えているので、次回のWaitAnimationが即終了することになる。 | |
// 移行を開始することで、normalizedTimeをリセットできる...らしい。(CrossFade中で問題ないらしい) | |
{ | |
var hash = AnimatorSettingConst.Alicia.StateHashes.Body_Idle; | |
animator.CrossFade(hash, 100f); | |
} | |
isCoroutineRunning = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment