Tanoda
ByNameRootBoneMapper.cs
Go to the documentation of this file.
1using TriLibCore.General;
2using TriLibCore.Utils;
3using UnityEngine;
4
5namespace TriLibCore.Mappers
6{
8 [CreateAssetMenu(menuName = "TriLib/Mappers/Root Bone/By Name Root Bone Mapper", fileName = "ByNameRootBoneMapper")]
9 public class ByNameRootBoneMapper : RootBoneMapper
10 {
14 [Header("Left = Loaded GameObjects Names, Right = Names in RootBoneNames")]
16
20 public bool CaseInsensitive = true;
21
25 public string[] RootBoneNames = { "Hips", "Bip01", "Pelvis" };
26
28 public override Transform Map(AssetLoaderContext assetLoaderContext)
29 {
30 if (RootBoneNames != null)
31 {
32 for (var i = 0; i < RootBoneNames.Length; i++)
33 {
34 var rootBoneName = RootBoneNames[i];
35 var found = FindDeepChild(assetLoaderContext.RootGameObject.transform, rootBoneName);
36 if (found != null)
37 {
38 return found;
39 }
40 }
41 }
42 return base.Map(assetLoaderContext);
43 }
44
45 private Transform FindDeepChild(Transform transform, string right)
46 {
47 if (StringComparer.Matches(StringComparisonMode, CaseInsensitive, transform.name, right))
48 {
49 return transform;
50 }
51
52 var childCount = transform.childCount;
53 for (var i = 0; i < childCount; i++)
54 {
55 var child = transform.GetChild(i);
56 var found = FindDeepChild(child, right);
57 if (found != null)
58 {
59 return found;
60 }
61 }
62 return null;
63 }
64 }
65}
Represents a Mapper that searches for a root bone on the Models by the bone names.
StringComparisonMode StringComparisonMode
String comparison mode to use on the mapping.
bool CaseInsensitive
Is the string comparison case insensitive?
string[] RootBoneNames
Root bone names to be searched.
override Transform Map(AssetLoaderContext assetLoaderContext)