144 lines
7.1 KiB
C#
144 lines
7.1 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: Eden.AutoMorpher.BoneAlignmentUtil
|
|
// Assembly: EdenAutoMorpherScript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
|
|
// MVID: D39968B3-E151-4276-BDB4-E82752BBAFF0
|
|
// Assembly location: D:\dev\AutoMorpher\Assets\@Eden_Tools\Eden_AutoMorpher\Script\EdenAutoMorpherScript.dll
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace Eden.AutoMorpher
|
|
{
|
|
public class BoneAlignmentUtil
|
|
{
|
|
public void AlignClothBonesToAvatar(ClothInstance cloth, Animator targetAvatarAnimator)
|
|
{
|
|
if (cloth == null || Object.op_Equality((Object)targetAvatarAnimator, (Object)null))
|
|
{
|
|
Debug.LogWarning((object)"[BoneAlignmentUtil] cloth 또는 targetAvatarAnimator 가 null.");
|
|
}
|
|
else
|
|
{
|
|
foreach (KeyValuePair<HumanBodyBones, HashSet<Transform>> humanoidMatchedBone in cloth.humanoidMatchedBones)
|
|
{
|
|
HumanBodyBones key = humanoidMatchedBone.Key;
|
|
foreach (Transform transform in humanoidMatchedBone.Value)
|
|
{
|
|
if (!Object.op_Equality((Object)transform, (Object)null))
|
|
{
|
|
Transform boneTransform = targetAvatarAnimator.GetBoneTransform(key);
|
|
if (!Object.op_Equality((Object)boneTransform, (Object)null))
|
|
{
|
|
transform.position = boneTransform.position;
|
|
transform.localScale = Vector3.one;
|
|
((Object)transform).name = ((Object)boneTransform).name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ReparentAccessoryBonesToAvatar(EdenAutoMorpherConfig config)
|
|
{
|
|
if (config.clothBoneTypeMap == null || Object.op_Equality((Object)config.targetAvatarObject, (Object)null))
|
|
return;
|
|
Animator component = config.targetAvatarObject.GetComponent<Animator>();
|
|
if (Object.op_Equality((Object)component, (Object)null) || !component.isHuman)
|
|
return;
|
|
Dictionary<Transform, Transform> dictionary = new Dictionary<Transform, Transform>();
|
|
if (config.clothesHumanoidMatchedBones != null)
|
|
{
|
|
foreach (KeyValuePair<HumanBodyBones, HashSet<Transform>> humanoidMatchedBone in config.clothesHumanoidMatchedBones)
|
|
{
|
|
HumanBodyBones key1 = humanoidMatchedBone.Key;
|
|
foreach (Transform key2 in humanoidMatchedBone.Value)
|
|
{
|
|
Transform boneTransform = component.GetBoneTransform(key1);
|
|
if (Object.op_Inequality((Object)key2, (Object)null) && Object.op_Inequality((Object)boneTransform, (Object)null))
|
|
dictionary[key2] = boneTransform;
|
|
}
|
|
}
|
|
}
|
|
foreach (KeyValuePair<Transform, ClothBoneType> clothBoneType1 in config.clothBoneTypeMap)
|
|
{
|
|
if (clothBoneType1.Value == ClothBoneType.Accessory)
|
|
{
|
|
Transform key3 = clothBoneType1.Key;
|
|
if (!Object.op_Equality((Object)key3, (Object)null) && key3.IsChildOf(config.targetClothesObject.transform))
|
|
{
|
|
Transform parent = key3.parent;
|
|
Transform key4 = (Transform)null;
|
|
for (; Object.op_Inequality((Object)parent, (Object)null); parent = parent.parent)
|
|
{
|
|
ClothBoneType clothBoneType2;
|
|
if (config.clothBoneTypeMap.TryGetValue(parent, out clothBoneType2) && clothBoneType2 == ClothBoneType.Body)
|
|
{
|
|
key4 = parent;
|
|
break;
|
|
}
|
|
}
|
|
Transform transform;
|
|
if (!Object.op_Equality((Object)key4, (Object)null) && dictionary.TryGetValue(key4, out transform))
|
|
key3.SetParent(transform, true);
|
|
}
|
|
}
|
|
}
|
|
foreach (KeyValuePair<Transform, Transform> keyValuePair in dictionary)
|
|
{
|
|
Transform key5 = keyValuePair.Key;
|
|
Transform transform1 = keyValuePair.Value;
|
|
if (!Object.op_Equality((Object)key5, (Object)null) && !Object.op_Equality((Object)transform1, (Object)null))
|
|
{
|
|
List<Transform> transformList = new List<Transform>();
|
|
foreach (Transform transform2 in key5)
|
|
transformList.Add(transform2);
|
|
foreach (Transform key6 in transformList)
|
|
{
|
|
if (!Object.op_Equality((Object)key6, (Object)null) && !config.clothBoneTypeMap.ContainsKey(key6))
|
|
key6.SetParent(transform1, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CleanupTempBones(Transform root)
|
|
{
|
|
if (Object.op_Equality((Object)root, (Object)null))
|
|
return;
|
|
TempBoneMarker[] componentsInChildren = ((Component)root).GetComponentsInChildren<TempBoneMarker>(true);
|
|
if (componentsInChildren == null || componentsInChildren.Length == 0)
|
|
return;
|
|
foreach (TempBoneMarker tempBoneMarker in ((IEnumerable<TempBoneMarker>)componentsInChildren).Where<TempBoneMarker>((Func<TempBoneMarker, bool>)(m => Object.op_Inequality((Object)m, (Object)null))).OrderByDescending<TempBoneMarker, int>((Func<TempBoneMarker, int>)(m => GetDepth(((Component)m).transform))).ToArray<TempBoneMarker>())
|
|
{
|
|
if (!Object.op_Equality((Object)tempBoneMarker, (Object)null))
|
|
{
|
|
Transform transform1 = ((Component)tempBoneMarker).transform;
|
|
Transform transform2 = tempBoneMarker.originalParent;
|
|
if (Object.op_Equality((Object)transform2, (Object)null))
|
|
transform2 = transform1.parent;
|
|
if (Object.op_Inequality((Object)transform2, (Object)null))
|
|
{
|
|
while (transform1.childCount > 0)
|
|
transform1.GetChild(0).SetParent(transform2, true);
|
|
}
|
|
if (!Application.isPlaying)
|
|
Object.DestroyImmediate((Object)((Component)transform1).gameObject);
|
|
else
|
|
Object.Destroy((Object)((Component)transform1).gameObject);
|
|
}
|
|
}
|
|
|
|
static int GetDepth(Transform t)
|
|
{
|
|
int depth = 0;
|
|
for (; Object.op_Inequality((Object)t, (Object)null); t = t.parent)
|
|
++depth;
|
|
return depth;
|
|
}
|
|
}
|
|
}
|
|
}
|