55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEditor;
|
|||
|
using System;
|
|||
|
|
|||
|
public class UpdateSkinnedMeshWindow : EditorWindow
|
|||
|
{
|
|||
|
[MenuItem("Window/Update Skinned Mesh Bones")]
|
|||
|
public static void OpenWindow()
|
|||
|
{
|
|||
|
var window = GetWindow<UpdateSkinnedMeshWindow>();
|
|||
|
window.titleContent = new GUIContent("Skin Updater");
|
|||
|
}
|
|||
|
|
|||
|
private SkinnedMeshRenderer targetSkin;
|
|||
|
private SkinnedMeshRenderer sourceSkin;
|
|||
|
|
|||
|
private void OnGUI()
|
|||
|
{
|
|||
|
sourceSkin = EditorGUILayout.ObjectField("Main Body", sourceSkin, typeof(SkinnedMeshRenderer), true) as SkinnedMeshRenderer;
|
|||
|
targetSkin = EditorGUILayout.ObjectField("Accessory", targetSkin, typeof(SkinnedMeshRenderer), true) as SkinnedMeshRenderer;
|
|||
|
|
|||
|
|
|||
|
GUI.enabled = (targetSkin != null && sourceSkin != null);
|
|||
|
|
|||
|
if (targetSkin != null && sourceSkin != null)
|
|||
|
{
|
|||
|
|
|||
|
if (GUILayout.Button("Update Skinned Mesh Renderer"))
|
|||
|
{
|
|||
|
Transform rootBone = sourceSkin.rootBone;
|
|||
|
Transform[] newBones = new Transform[targetSkin.bones.Length];
|
|||
|
|
|||
|
for (int i = 0; i < targetSkin.bones.Length; i++)
|
|||
|
{
|
|||
|
foreach (var newBone in rootBone.GetComponentsInChildren<Transform>())
|
|||
|
{
|
|||
|
if (newBone.name == targetSkin.bones[i].name)
|
|||
|
{
|
|||
|
newBones[i] = newBone;
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
targetSkin.bones = newBones;
|
|||
|
targetSkin.rootBone = rootBone;
|
|||
|
targetSkin.probeAnchor = rootBone;
|
|||
|
targetSkin.transform.SetParent(rootBone.root);
|
|||
|
targetSkin.localBounds = sourceSkin.localBounds;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|