mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-04 19:49:02 +08:00
chore: use InitializeOnLoadMethod instead of reflection to get boneNamePattern from Editor Assembly
This commit is contained in:
parent
14d46b4546
commit
2fa8672823
@ -243,6 +243,12 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
internal static readonly ImmutableDictionary<string, List<HumanBodyBones>> NameToBoneMap;
|
||||
internal static readonly ImmutableDictionary<HumanBodyBones, ImmutableList<string>> BoneToNameMap;
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
private static void InsertboneNamePatternsToRuntime()
|
||||
{
|
||||
ModularAvatarMergeArmature.boneNamePatterns = boneNamePatterns;
|
||||
}
|
||||
|
||||
static HeuristicBoneMapper()
|
||||
{
|
||||
var pat_end_side = new Regex(@"[_\.]([LR])$");
|
||||
|
@ -61,6 +61,9 @@ namespace nadena.dev.modular_avatar.core
|
||||
|
||||
public bool mangleNames = true;
|
||||
|
||||
// Inserted from HeuristicBoneMapper(Editor Assembly) with InitializeOnLoadMethod
|
||||
// We use raw `boneNamePatterns` instead of `BoneToNameMap` because BoneToNameMap requires matching with normalized bone name, but normalizing makes raw prefix/suffix unavailable.
|
||||
internal static string[][] boneNamePatterns;
|
||||
private ArmatureLockController _lockController;
|
||||
|
||||
internal Transform MapBone(Transform bone)
|
||||
@ -200,21 +203,6 @@ namespace nadena.dev.modular_avatar.core
|
||||
}
|
||||
}
|
||||
|
||||
private static class InferWithHeuristic
|
||||
{
|
||||
internal static Type HeuristicBoneMapper;
|
||||
static InferWithHeuristic()
|
||||
{
|
||||
foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
HeuristicBoneMapper = assembly.GetType("nadena.dev.modular_avatar.core.editor.HeuristicBoneMapper");
|
||||
if (HeuristicBoneMapper != null) return;
|
||||
}
|
||||
if (HeuristicBoneMapper == null)
|
||||
throw new InvalidOperationException("HeuristicBoneMapper not found");
|
||||
}
|
||||
}
|
||||
|
||||
public void InferPrefixSuffix()
|
||||
{
|
||||
// We only infer if targeting the armature (below the Hips bone)
|
||||
@ -233,9 +221,6 @@ namespace nadena.dev.modular_avatar.core
|
||||
var mergeName = transform.GetChild(0).name;
|
||||
var isInferred = false;
|
||||
|
||||
// We use raw `boneNamePatterns` instead of `BoneToNameMap` because BoneToNameMap requires matching with normalized bone name, but normalizing makes raw prefix/suffix unavailable.
|
||||
string[][] boneNamePatterns = (string[][])InferWithHeuristic.HeuristicBoneMapper.GetField("boneNamePatterns", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null);
|
||||
|
||||
foreach (var hipNameCandidate in boneNamePatterns[(int)HumanBodyBones.Hips])
|
||||
{
|
||||
var prefixLength = mergeName.IndexOf(hipNameCandidate, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
Loading…
x
Reference in New Issue
Block a user