Files
AutoMorpherDecompiled/Assets/@Eden_Tools/Eden_AutoMorpher/Script/BoneAlignmentUtil.cs

180 lines
7.3 KiB
C#

// Warning: Some assembly references could not be resolved automatically. This might lead to incorrect decompilation of some parts,
// for ex. property getter/setter access. To get optimal decompilation results, please manually add the missing references to the list of loaded assemblies.
// EdenAutoMorpherScript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Eden.AutoMorpher.BoneAlignmentUtil
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class BoneAlignmentUtil
{
public void AlignClothBonesToAvatar(ClothInstance cloth, Animator targetAvatarAnimator)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
if (cloth == null || (Object)(object)targetAvatarAnimator == (Object)null)
{
Debug.LogWarning((object)"[BoneAlignmentUtil] cloth 또는 targetAvatarAnimator 가 null.");
return;
}
foreach (KeyValuePair<HumanBodyBones, HashSet<Transform>> humanoidMatchedBone in cloth.humanoidMatchedBones)
{
HumanBodyBones key = humanoidMatchedBone.Key;
foreach (Transform item in humanoidMatchedBone.Value)
{
if (!((Object)(object)item == (Object)null))
{
Transform boneTransform = targetAvatarAnimator.GetBoneTransform(key);
if (!((Object)(object)boneTransform == (Object)null))
{
item.position = boneTransform.position;
item.localScale = Vector3.one;
((Object)item).name = ((Object)boneTransform).name;
}
}
}
}
}
public void ReparentAccessoryBonesToAvatar(EdenAutoMorpherConfig config)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Expected O, but got Unknown
if (config.clothBoneTypeMap == null || (Object)(object)config.targetAvatarObject == (Object)null)
{
return;
}
Animator component = config.targetAvatarObject.GetComponent<Animator>();
if ((Object)(object)component == (Object)null || !component.isHuman)
{
return;
}
Dictionary<Transform, Transform> dictionary = new Dictionary<Transform, Transform>();
if (config.clothesHumanoidMatchedBones != null)
{
foreach (KeyValuePair<HumanBodyBones, HashSet<Transform>> clothesHumanoidMatchedBone in config.clothesHumanoidMatchedBones)
{
HumanBodyBones key = clothesHumanoidMatchedBone.Key;
foreach (Transform item2 in clothesHumanoidMatchedBone.Value)
{
Transform boneTransform = component.GetBoneTransform(key);
if ((Object)(object)item2 != (Object)null && (Object)(object)boneTransform != (Object)null)
{
dictionary[item2] = boneTransform;
}
}
}
}
foreach (KeyValuePair<Transform, ClothBoneType> item3 in config.clothBoneTypeMap)
{
if (item3.Value != ClothBoneType.Accessory)
{
continue;
}
Transform key2 = item3.Key;
if ((Object)(object)key2 == (Object)null || !key2.IsChildOf(config.targetClothesObject.transform))
{
continue;
}
Transform parent = key2.parent;
Transform val = null;
while ((Object)(object)parent != (Object)null)
{
if (config.clothBoneTypeMap.TryGetValue(parent, out var value) && value == ClothBoneType.Body)
{
val = parent;
break;
}
parent = parent.parent;
}
if (!((Object)(object)val == (Object)null) && dictionary.TryGetValue(val, out var value2))
{
key2.SetParent(value2, true);
}
}
foreach (KeyValuePair<Transform, Transform> item4 in dictionary)
{
Transform key3 = item4.Key;
Transform value3 = item4.Value;
if ((Object)(object)key3 == (Object)null || (Object)(object)value3 == (Object)null)
{
continue;
}
List<Transform> list = new List<Transform>();
foreach (Transform item5 in key3)
{
Transform item = item5;
list.Add(item);
}
foreach (Transform item6 in list)
{
if (!((Object)(object)item6 == (Object)null) && !config.clothBoneTypeMap.ContainsKey(item6))
{
item6.SetParent(value3, true);
}
}
}
}
public void CleanupTempBones(Transform root)
{
if ((Object)(object)root == (Object)null)
{
return;
}
TempBoneMarker[] componentsInChildren = ((Component)root).GetComponentsInChildren<TempBoneMarker>(true);
if (componentsInChildren == null || componentsInChildren.Length == 0)
{
return;
}
TempBoneMarker[] array = (from m in componentsInChildren
where (Object)(object)m != (Object)null
orderby GetDepth(((Component)m).transform) descending
select m).ToArray();
foreach (TempBoneMarker tempBoneMarker in array)
{
if ((Object)(object)tempBoneMarker == (Object)null)
{
continue;
}
Transform transform = ((Component)tempBoneMarker).transform;
Transform val = tempBoneMarker.originalParent;
if ((Object)(object)val == (Object)null)
{
val = transform.parent;
}
if ((Object)(object)val != (Object)null)
{
while (transform.childCount > 0)
{
transform.GetChild(0).SetParent(val, true);
}
}
if (!Application.isPlaying)
{
Object.DestroyImmediate((Object)(object)((Component)transform).gameObject);
}
else
{
Object.Destroy((Object)(object)((Component)transform).gameObject);
}
}
int GetDepth(Transform t)
{
int num2 = 0;
while ((Object)(object)t != (Object)null)
{
num2++;
t = t.parent;
}
return num2;
}
}
}