redbluegames / unity-mulligan-renamer

Mulligan Renamer tool for the Unity Editor allows for quick and safe renaming of many assets and gameobjects at once
MIT License
551 stars 57 forks source link

Do not depend on "Assets/" while detecting asset relative path (#281) #285

Closed KonH closed 3 years ago

KonH commented 3 years ago

It is possible to select assets outside Assets directory (like Packages), it leads to exception spam (see #281) so we need to detect top parent directory dynamically

edwardrowe commented 3 years ago

I've been doing a little debugging and I'm THINKING the whole conversion to "assetRelativePath" is unnecessary because these should already be Assets-relative (if they're in the Assets folder). I'm guessing I originally did System.IO to find files in a directory, discovered that misses sub-assets (like sprites), and then made it use AssetDatabase and didn't realize I could then remove this line.

Basically I think a better fix would be to just delete the original line var assetRelativePath = filePath.Substring(filePath.IndexOf("Assets/"));

and convert the loop to use the filePath directly. I think this should be identical in behavior.

Would you mind doing that instead here? I'll test it in various scenarios on my end.

KonH commented 3 years ago

Looks like it's better solution, you're right. I made proposed changes and it works (at least on trivial use cases).

edwardrowe commented 3 years ago

Ok thanks! Rebased to Staging and merged!