private bool CheckIfCanMigrate(Type type, Object selectedObject) { bool canMigrate = false; string objectPath = AssetDatabase.GetAssetPath(selectedObject); if (IsSceneGameObject(selectedObject)) { var objectHierarchy = ((GameObject)selectedObject).GetComponentsInChildren <Transform>(true); for (int i = 0; i < objectHierarchy.Length; i++) { if (migrationHandlerInstance.CanMigrate(objectHierarchy[i].gameObject)) { return(true); } } } else if (IsPrefabAsset(selectedObject)) { PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(selectedObject); if (prefabType == PrefabAssetType.Regular || prefabType == PrefabAssetType.Variant) { var parent = UnityEditor.PrefabUtility.LoadPrefabContents(objectPath); canMigrate = CheckIfCanMigrate(type, parent); PrefabUtility.UnloadPrefabContents(parent); } } else if (IsSceneAsset(selectedObject)) { Scene scene = EditorSceneManager.OpenScene(objectPath); foreach (var parent in scene.GetRootGameObjects()) { if (CheckIfCanMigrate(type, parent)) { return(true); } } } return(canMigrate); }
private void MigrateGameObjectHierarchy(GameObject parent) { foreach (var child in parent.GetComponentsInChildren <Transform>()) { try { if (migrationHandlerInstance.CanMigrate(child.gameObject)) { migrationHandlerInstance.Migrate(child.gameObject); Debug.Log($"Successfully migrated {parent.name} object"); } } catch (Exception e) { Debug.LogError($"{e.Message}: GameObject {parent.name} could not be migrated"); } } }