ByBonesRootBoneMapper.cs 1.0 KB

123456789101112131415161718192021222324252627
  1. using TriLibCore.Extensions;
  2. using UnityEngine;
  3. namespace TriLibCore.Mappers
  4. {
  5. /// <summary>Represents a Mapper that looks for the Game Object which has only a Transform component and has the biggest number of children as the root bone.</summary>
  6. [CreateAssetMenu(menuName = "TriLib/Mappers/Root Bone/By Bones Root Bone Mapper", fileName = "ByBonesRootBoneMapper")]
  7. public class ByBonesRootBoneMapper : RootBoneMapper
  8. {
  9. /// <inheritdoc />
  10. public override Transform Map(AssetLoaderContext assetLoaderContext)
  11. {
  12. Transform bestBone = null;
  13. var bestChildrenCount = 0;
  14. foreach (var bone in assetLoaderContext.BoneTransforms)
  15. {
  16. var childrenCount = bone.CountChild();
  17. if (childrenCount >= bestChildrenCount)
  18. {
  19. bestChildrenCount = childrenCount;
  20. bestBone = bone;
  21. }
  22. }
  23. return bestBone;
  24. }
  25. }
  26. }