dustxx
1
Seems like a simple enough question. If I have a folder for prefabs like “Assets/Resources/Prefabs/Area/Tiles” and a folder for textures like “Assets/Textures/Area/Tiles” I’d like to make an editor script that can jump back and forth between them. I know how to do all that stuff except for actually changing the project view’s folder. I looked at the ProjectWindowUtil class and there doesn’t seem to be anything helpful there, so if there’s not a way to do this is there any way I can request it? Thanks.
dustxx
2
I solved my own problem. You can’t directly change the project view, but if you change the “Selection.activeObject” to an asset in a folder, the project view will jump to the folder in which that asset is stored. In my case, I simply used the path of the current “Selection.activeObject” to replace the needed parts to find the asset I wanted and set that to the selection. Simple enough!
//Draw the 'Switch Selection Between Tile and Texture' tool
private void DrawSwitchSelectionBetweenTileAndTextureTool()
{
if ( GUILayout.Button("Switch Selection Between Tile and Texture") )
{
Object mirroredAsset = GetMirroringTileOrTexture(Selection.activeObject);
if ( mirroredAsset != null ) { Selection.activeObject = mirroredAsset; }
else { CancelOperation("Could not find mirroring asset"); }
}
}
//Get the Tile mirroring a texture or the texture mirroring a tile
private Object GetMirroringTileOrTexture(Object asset)
{
string activeSelectionPath = AssetDatabase.GetAssetPath(asset);
string mirroredActiveSelectionPath = null;
//Convert the path
if ( activeSelectionPath.Contains("Resources/Prefabs/Overworld") )
{
mirroredActiveSelectionPath = new StringBuilder(activeSelectionPath).Replace("Resources/Prefabs/Overworld", "Textures").Replace(Constants.PREFAB_EXTENSION, Constants.PNG_EXTENSION).ToString();
}
else if ( activeSelectionPath.Contains("Textures") )
{
mirroredActiveSelectionPath = new StringBuilder(activeSelectionPath).Replace("Textures", "Resources/Prefabs/Overworld").Replace(Constants.PNG_EXTENSION, Constants.PREFAB_EXTENSION).ToString();
}
return AssetDatabase.LoadAssetAtPath(mirroredActiveSelectionPath, typeof(Object));
}
For people looking for exactly what is needed to do this,
EditorUtility.FocusProjectWindow();
Selection.activeObject = myObject;