/// <summary> /// Sets the next random animation, and when it should play /// animationPlaytime = animation playtime length * random number of times its going to repeat /// </summary> /// <param name="animator"></param> /// <param name="stateInfo"></param> /// <param name="layerIndex"></param> public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (this.IsCurrentAnimationDefault(animator, layerIndex)) { this.animationPlaytime = this.animationVariationModel.defaultAnimation.length * Random.Range(this.animationVariationModel.Min, this.animationVariationModel.Max); this.nextAnimation = this.GetNextAnimation(); } else if (animator.GetCurrentAnimatorClipInfo(layerIndex).Length > 0) { AnimationVariant currentAnimation = this.GetAnimationVariantByHashCode(animator, layerIndex); if (!currentAnimation.Equals(null) && currentAnimation.animationClip != null) { this.animationPlaytime = currentAnimation.animationClip.length * Random.Range(currentAnimation.Min, currentAnimation.Max); } else { this.PlayDefaultAnimation(animator); } } else { this.PlayDefaultAnimation(animator); } }
/// <summary> /// Randomly selects the next animation to play /// </summary> /// <returns></returns> private AnimationVariant GetNextAnimation() { AnimationVariant animationVariant = animationVariationModel.animationVariants[Random.Range(0, animationVariationModel.animationVariants.Count)]; return(animationVariant); }