AnimatorOverrideAnimationClipMapper.cs 1.2 KB

1234567891011121314151617181920212223242526272829
  1. using UnityEngine;
  2. namespace TriLibCore.Mappers
  3. {
  4. /// <summary>Represents a Mapper used to fill Animator Override Animation Clips.</summary>
  5. public class AnimatorOverrideAnimationClipMapper : AnimationClipMapper
  6. {
  7. /// <summary>
  8. /// Animator controller override to use on the animator.
  9. /// </summary>
  10. public AnimatorOverrideController AnimatorOverrideController;
  11. ///<inheritdoc />
  12. public override AnimationClip[] MapArray(AssetLoaderContext assetLoaderContext, AnimationClip[] sourceAnimationClips)
  13. {
  14. var animator = assetLoaderContext.RootGameObject.GetComponent<Animator>();
  15. if (animator == null || AnimatorOverrideController == null)
  16. {
  17. if (assetLoaderContext.Options.ShowLoadingWarnings)
  18. {
  19. Debug.LogWarning("Tried to execute an AnimatorOverrideController Mapper on a GameObject without an Animator or without setting an AnimatorOverrideController.");
  20. }
  21. return sourceAnimationClips;
  22. }
  23. animator.runtimeAnimatorController = AnimatorOverrideController;
  24. return sourceAnimationClips;
  25. }
  26. }
  27. }