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); }
public static bool RevealAndSelectSubAsset(string assetPath, string name, long objectId) { var targetAssets = AssetDatabase.LoadAllAssetsAtPath(assetPath); if (targetAssets == null || targetAssets.Length == 0) { return(false); } foreach (var targetAsset in targetAssets) { if (!AssetDatabase.IsSubAsset(targetAsset)) { continue; } if (targetAsset is GameObject || targetAsset is Component) { continue; } if (!string.Equals(targetAsset.name, name, StringComparison.OrdinalIgnoreCase)) { continue; } var assetId = CSObjectTools.GetUniqueObjectId(targetAsset); if (assetId != objectId) { continue; } Selection.activeInstanceID = targetAsset.GetInstanceID(); return(true); } return(false); }