private static void UpdateBonesToNewRoot(MenuCommand command) { SkinnedMeshRenderer renderer = command.context as SkinnedMeshRenderer; GameObject meshAssetObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(renderer.sharedMesh)) as GameObject; if (meshAssetObject != null) { if (renderer.rootBone == null) { int depth = SceneUtils.GetChildDepth(meshAssetObject.transform, meshAssetObject.transform.FindInChildren(renderer.name)); Transform parent = renderer.transform; for (int i = 0; i < depth; i++) { parent = parent.parent; } SkinnedMeshRenderer assetRenderer = meshAssetObject.transform.FindInChildren(renderer.name).GetComponent <SkinnedMeshRenderer>(); renderer.rootBone = parent.FindInChildren(assetRenderer.rootBone.name); } SkinnedMeshRenderer[] childRenderers = meshAssetObject.GetComponentsInChildren <SkinnedMeshRenderer>(); for (int i = 0; i < childRenderers.Length; i++) { if (childRenderers[i].sharedMesh == renderer.sharedMesh) { Transform[] bones = new Transform[childRenderers[i].bones.Length]; for (int j = 0; j < bones.Length; j++) { bones[j] = renderer.rootBone.FindInChildren(childRenderers[i].bones[j].name); } renderer.bones = bones; EditorUtility.SetDirty(renderer); break; } } } }
void ShowFavouritesDropdown(Rect rect) { GenericMenu menu = new GenericMenu(); LoadFavourites(); List <Object> assets = _favouritesContainer.assets; List <DefaultAsset> folders = _favouritesContainer.folders; List <MonoScript> scripts = _favouritesContainer.sceneObjects; if (_favouritesContainer.assets.Count == 0 && _favouritesContainer.folders.Count == 0 && _favouritesContainer.sceneObjects.Count == 0) { menu.AddDisabledItem(new GUIContent("No Favourites")); } else { int totalAdded = 0; int addedInSection = 0; for (int i = 0; i < assets.Count; i++) { if (assets[i] != null) { menu.AddItem(new GUIContent(assets[i].name), false, (asset) => AssetDatabase.OpenAsset((Object)asset), assets[i]); totalAdded++; addedInSection++; } } addedInSection = 0; for (int i = 0; i < folders.Count; i++) { if (folders[i] != null) { if (addedInSection == 0 && totalAdded != 0) { menu.AddSeparator(""); } menu.AddItem(new GUIContent(folders[i].name), false, (folder) => Selection.activeObject = (Object)folder, folders[i]); totalAdded++; addedInSection++; } } addedInSection = 0; for (int i = 0; i < scripts.Count; i++) { if (scripts[i] != null) { Component[] components = SceneUtils.FindObjectsOfType(scripts[i].GetClass(), true); if (components.Length > 0) { if (addedInSection == 0 && totalAdded != 0) { menu.AddSeparator(""); } if (components.Length == 1) { menu.AddItem(new GUIContent(scripts[i].name + " (Scene)"), false, () => Selection.activeObject = components[0]); } else if (components.Length > 1) { menu.AddItem(new GUIContent(scripts[i].name + " (Scene)"), false, () => Selection.objects = components.Select(component => component.gameObject).ToArray()); } totalAdded++; addedInSection++; } } } } menu.DropDown(rect); }