private static bool RevealAndSelectGameObjectInPrefab(string enclosingAssetPath, string transformPath, long objectId, long componentId) { var targetAsset = AssetDatabase.LoadMainAssetAtPath(enclosingAssetPath) as GameObject; if (targetAsset == null) { return(false); } Object target = CSObjectTools.FindChildGameObjectRecursive(targetAsset.transform, objectId, targetAsset.transform.name, transformPath); // in some cases, prefabs can have nested non-GameObject items if (target == null) { var allObjectsInPrefab = AssetDatabase.LoadAllAssetsAtPath(enclosingAssetPath); foreach (var objectOnPrefab in allObjectsInPrefab) { if (objectOnPrefab is BillboardAsset || objectOnPrefab is TreeData) { var objectOnPrefabId = CSObjectTools.GetUniqueObjectId(objectOnPrefab); if (objectOnPrefabId == objectId) { target = objectOnPrefab; } } } } if (target == null) { Debug.LogError(Maintainer.ConstructError("Couldn't find target Game Object " + transformPath + " at " + enclosingAssetPath + " with ObjectID " + objectId + "!")); return(false); } if (target is GameObject) { CSObjectTools.SelectGameObject((GameObject)target, false); } else { Selection.activeObject = target; } if (transformPath.Split('/').Length > 2) { EditorApplication.delayCall += () => { EditorGUIUtility.PingObject(targetAsset); }; } if (componentId != -1) { return(TryFoldAllComponentsExceptId(componentId)); } return(true); }
private static bool RevealAndSelectGameObjectInPrefab(string enclosingAssetPath, string transformPath, long objectId, long componentId) { /*Debug.Log("LOOKING FOR objectId " + objectId); * Debug.Log("enclosingAssetPath " + enclosingAssetPath);*/ var targetAsset = AssetDatabase.LoadMainAssetAtPath(enclosingAssetPath) as GameObject; var prefabType = PrefabUtility.GetPrefabAssetType(targetAsset); GameObject target; if (prefabType == PrefabAssetType.Model) { target = targetAsset; } else { if (!AssetDatabase.OpenAsset(targetAsset)) { Debug.LogError(Maintainer.ConstructError("Couldn't open prefab at " + enclosingAssetPath + "!")); return(false); } var stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage == null) { Debug.LogError(Maintainer.ConstructError("Couldn't get prefab stage for prefab at " + enclosingAssetPath + "!")); return(false); } target = stage.prefabContentsRoot; } if (target == null) { Debug.LogError(Maintainer.ConstructError("Couldn't find target Game Object " + transformPath + " at " + enclosingAssetPath + " with ObjectID " + objectId + "!")); return(false); } target = CSObjectTools.FindChildGameObjectRecursive(target.transform, objectId, target.transform.name, transformPath); EditorApplication.delayCall += () => { CSObjectTools.SelectGameObject(target, false); EditorGUIUtility.PingObject(targetAsset); if (componentId != -1) { EditorApplication.delayCall += () => { TryFoldAllComponentsExceptId(componentId); }; } }; return(true); }