Skip to content

Commit

Permalink
Move animator enable state one scope out
Browse files Browse the repository at this point in the history
  • Loading branch information
marwie committed Jan 20, 2023
1 parent 01d9bf4 commit 3236f38
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ private GLTFAnimation GetOrCreateAnimation(AnimationClip clip, string searchForD
// Creates GLTFAnimation for each clip and adds it to the _root
public void ExportAnimationClips(Transform nodeTransform, IList<AnimationClip> clips, Animator animator = null, AnimatorController animatorController = null)
{
// When sampling animation using AnimationMode the animator might be disabled afterwards when the animation is exported from a prefab (e.g. Prefab -> object with humanoid animation -> export from referenced prefab -> animator is disabled)
// Here we ensure that the animator is enabled again after export
// See ExportAnimationHumanoid with StartAnimationMode
var animatorEnabled = animator?.enabled ?? true;

// Debug.Log("exporting clips from " + nodeTransform + " with " + animatorController);
if (animatorController)
{
if (!animator) throw new ArgumentNullException("Missing " + nameof(animator));
// When sampling animation using AnimationMode the animator might be disabled afterwards when the animation is exported from a prefab (e.g. Prefab -> object with humanoid animation -> export from referenced prefab -> animator is disabled)
// Here we ensure that the animator is enabled again after export
// See ExportAnimationHumanoid with StartAnimationMode
var animatorEnabled = animator.enabled;
for (int i = 0; i < clips.Count; i++)
{
if (!clips[i]) continue;
Expand All @@ -145,7 +146,6 @@ public void ExportAnimationClips(Transform nodeTransform, IList<AnimationClip> c
ExportAnimationClip(clips[i], name, nodeTransform, speed);
}
}
animator.enabled = animatorEnabled;
}
else
{
Expand All @@ -156,6 +156,9 @@ public void ExportAnimationClips(Transform nodeTransform, IList<AnimationClip> c
ExportAnimationClip(clips[i], clips[i].name, nodeTransform, speed);
}
}

if(animator)
animator.enabled = animatorEnabled;
}

public GLTFAnimation ExportAnimationClip(AnimationClip clip, string name, Transform node, float speed)
Expand Down

0 comments on commit 3236f38

Please sign in to comment.