mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-29 18:55:06 +08:00
35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
|
using UnityEngine;
|
|||
|
using VRC.SDKBase.Editor.BuildPipeline;
|
|||
|
|
|||
|
namespace net.fushizen.modular_avatar.core.editor
|
|||
|
{
|
|||
|
public class BoneProxyHook : IVRCSDKPreprocessAvatarCallback
|
|||
|
{
|
|||
|
public int callbackOrder => HookSequence.SEQ_BONE_PROXY;
|
|||
|
|
|||
|
public bool OnPreprocessAvatar(GameObject avatarGameObject)
|
|||
|
{
|
|||
|
var boneProxies = avatarGameObject.GetComponentsInChildren<ModularAvatarBoneProxy>(true);
|
|||
|
|
|||
|
foreach (var proxy in boneProxies)
|
|||
|
{
|
|||
|
if (proxy.constraint != null) UnityEngine.Object.DestroyImmediate(proxy.constraint);
|
|||
|
if (proxy.target != null)
|
|||
|
{
|
|||
|
var oldPath = RuntimeUtil.AvatarRootPath(proxy.gameObject);
|
|||
|
Transform transform = proxy.transform;
|
|||
|
transform.SetParent(proxy.target, false);
|
|||
|
transform.localPosition = Vector3.zero;
|
|||
|
transform.localRotation = Quaternion.identity;
|
|||
|
PathMappings.Remap(oldPath, new PathMappings.MappingEntry() {
|
|||
|
path = RuntimeUtil.AvatarRootPath(proxy.gameObject),
|
|||
|
transformPath = RuntimeUtil.AvatarRootPath(proxy.gameObject)
|
|||
|
});
|
|||
|
}
|
|||
|
Object.DestroyImmediate(proxy);
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|