The simplest way, IMO, would be to replace the files in-place, preserving the .meta files so the guids wouldn't change. This way you wouldn't even need to update the material references, which is always a pain to do in Unity.
The procedure:
- bulk-convert the TGAs to PNGs (with Unity closed or at least unfocused)
- delete all the TGAs, but not the associated .tga.meta files
- rename all the .tga.meta files to .png.meta
- then reopen/refocus Unity, let it reimport: you should be all set. Unity think the textures are the same and just need reimporting. It will even preserve the import settings.
You could automate the renaming (step 3) using a simple batch or shell script. If your project is under source-control, use you CVS's command-line rename interface to keep the textures' history. And if it's not, then obviously you make a backup copy of your project.
As a side-note:
I know that for some rendering cases, .tga is better than .png
This is not true. When Unity imports the textures, it converts them to a GPU/platform-specific format (this goes in the library), and the original format of the texture makes no difference.
for my use case, portability is more important than texture quality.
PNG has a lossless-compression option, so you can have both smaller size and pixel-perfect quality, no downside compared to TGA (except maybe the import time would be slightly longer due to decompression).
Edit from @escapecharacter:
This worked perfectly. Here's documentation of what I did. FYI, I'm on Windows using bash. My project is tracked in version control so I wasn't cautious about breaking changes. From my Textures directory:
To convert .meta files:
for i in *.tga.meta; do git mv $i ${i/.tga.meta/.png.meta}; done
To convert the .tga to .png, I used ImageMagick installed via choco:
for f in *.tga; do magick ./"$f" ./"${f%.tga}.png"; done;
To clean up the .tga:
rm *.tga