void CopyCompoment(GameObject src, GameObject dst, Dictionary <string, Transform> dstDic) { foreach (var component in src.GetComponents <UnityEngine.Component>()) { Component oldComponent = dst.GetComponent(component.GetType()); if (oldComponent) { } else { UnityEditorInternal.ComponentUtility.CopyComponent(component); if (UnityEditorInternal.ComponentUtility.PasteComponentAsNew(dst)) { Debug.Log($"Paste New Values {component.GetType()} to {dst.name} Success"); } else { Debug.LogWarning($"Paste New Values {component.GetType()} to {dst.name} Failed"); } if (component.GetType() == typeof(DynamicBone)) { var db = dst.GetComponent <DynamicBone>(); string name = (component as DynamicBone).m_Root.name; db.m_Root = dstDic[normalizeName ? AnimationNameNormalization.NormalizeStr(name) : name]; } } } }
void GetChildrenDeep(Dictionary <string, Transform> dic, Transform father) { dic.Add(normalizeName ? AnimationNameNormalization.NormalizeStr(father.name) : father.name, father); for (int i = 0; i < father.childCount; i++) { GetChildrenDeep(dic, father.GetChild(i)); } }