private void UpdateAvatarState()
    {
        if (Event.current.type != EventType.Repaint)
        {
            return;
        }

        if (avatarPreview.PreviewObject == null || controllerIsDitry)
        {
            avatarPreview.ResetPreviewInstance();

            if (avatarPreview.PreviewObject != null)
            {
                ResetStateMachine();
            }
        }

        Animator animator = avatarPreview.Animator;

        if (animator != null)
        {
            if (PrevIKOnFeet != avatarPreview.IKOnFeet)
            {
                PrevIKOnFeet = avatarPreview.IKOnFeet;
                Vector3    rootPosition = avatarPreview.Animator.rootPosition;
                Quaternion rootRotation = avatarPreview.Animator.rootRotation;
                ResetStateMachine();
                avatarPreview.Animator.UpdateWrapper(avatarPreview.timeControl.currentTime);
                avatarPreview.Animator.UpdateWrapper(0f);
                avatarPreview.Animator.rootPosition = rootPosition;
                avatarPreview.Animator.rootRotation = rootRotation;
            }

            if (avatarPreview.Animator != null)
            {
                BlendTree blendTree = previewedMotion as BlendTree;

                if (blendTree != null)
                {
                    for (int i = 0; i < blendTree.GetRecursiveBlendParamCount(); i++)
                    {
                        string recurvieBlendParameter = blendTree.GetRecursiveBlendParam(i);
                        float  inputBlendValue        = blendTree.GetInputBlendVal(recurvieBlendParameter);
                        avatarPreview.Animator.SetFloat(recurvieBlendParameter, inputBlendValue);
                    }
                }
            }

            avatarPreview.timeControl.loop = true;

            float length      = 1f;
            float currentTime = 0f;
            if (animator.layerCount > 0)
            {
                AnimatorStateInfo currentAnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0);
                length      = currentAnimatorStateInfo.length;
                currentTime = currentAnimatorStateInfo.normalizedTime;
            }

            avatarPreview.timeControl.startTime = 0f;
            avatarPreview.timeControl.stopTime  = length;
            avatarPreview.timeControl.Update();

            float num3 = this.avatarPreview.timeControl.deltaTime;
            if (float.IsInfinity(num3))
            {
                num3 = 0;
            }

            if (!previewedMotion.isLooping)
            {
                if (currentTime >= 1f)
                {
                    num3 -= length;
                }
                else
                {
                    if (currentTime < 0f)
                    {
                        num3 += length;
                    }
                }
            }

            animator.UpdateWrapper(num3);
        }
    }