public void OnAnimationState(AIAnimationState animData) { string animName = animData.name; if (animData != prevAnim) { if (animData.crossFadeIn || (prevAnim != null && prevAnim.crossFadeOut)) { animator.CrossFade(animName, animData.transitionTime); } prevAnim = animData; } }
/// <summary> /// Tells the system to play an AIAnimationState /// </summary> /// <param name="animState">Animation state.</param> /// If the 'onPlayAnimation' delegate is defined it will call that.\n /// If 'onPlayAnimation' is not defined it will attempt to call the method 'animationCallbackMethodName' defined on the 'animationCallbackComponent' public void PlayAnimation(AIAnimationState animState) { if (onPlayAnimation != null) { onPlayAnimation?.Invoke(animState); } else if (animationCallbackComponent != null && animState != null) { if (!string.IsNullOrEmpty(animationCallbackMethodName)) { animationCallbackComponent.SendMessage(animationCallbackMethodName, animState); } } }
protected override void Action(AIBehaviors fsm) { Transform target = fsm.GetClosestPlayer(objectFinder.GetTransforms()); string attackAnimationName = animationStates[0].name; bool useAnimationTime = skinnedMeshRenderer == null || skinnedMeshRenderer.isVisible; if (!useAnimationTime && attackAnimation != null) { useAnimationTime = attackAnimation.cullingType == AnimationCullingType.AlwaysAnimate; } if (target != null) { HandlePreviousStateMovement(fsm, target); } AIAnimationState animState = fsm.animationStates.GetStateWithName(attackAnimationName); fsm.PlayAnimation(animState); if (scriptWithAttackMethod != null) { if (!string.IsNullOrEmpty(methodName)) { if (useAnimationTime && attackAnimation != null && attackAnimation[attackAnimationName] != null) { curAnimPosition = attackAnimation[attackAnimationName].normalizedTime % 1.0f; } else { curAnimPosition %= 1.0f; curAnimPosition += Time.deltaTime / animationLength; } if (previousSamplePosition > attackPoint || curAnimPosition < attackPoint) { previousSamplePosition = curAnimPosition; return; } previousSamplePosition = curAnimPosition; TriggerCooldown(); Attack(fsm, target); } } }
public void OnAnimationState(AIAnimationState animState) { if (hasAnimationComponent && animState != null) { string stateName = animState.name; if (anim[stateName] != null) { anim[stateName].wrapMode = animState.animationWrapMode; anim[stateName].speed = animState.speed; anim.CrossFade(stateName); } else { Debug.LogWarning("The animation state \"" + stateName + "\" couldn't be found."); } } }