export class AnimatorManager {
    public static Play(isboss = false,animator: Laya.Animator, anim: string, islooping: boolean | null = null, complete: Laya.Handler = null, speed: number | null = null) {
        if (animator == null || animator.getControllerLayer() == null) {
            complete && complete.run();
            return;
        }
        let animatorState = animator.getControllerLayer().getAnimatorState(anim) as Laya.AnimatorState;
        if (animatorState == null) {
            complete && complete.run();
            return;
        }
        if (islooping != null) animatorState.clip.islooping = islooping;
        if (speed != null) animatorState.speed = speed;
        animator.play(anim);
        if (complete) {
            let cb = () => {
                if (animator.getCurrentAnimatorPlayState().normalizedTime >= 1) {
                    if(isboss){
                        animator.play("idle");
                    }
                    Laya.timer.clear(this, cb);
                    complete.run();
                }
            };
            Laya.timer.frameLoop(1, this, cb);
        }
    }
}