On my 2d game I have meshes with textures, I attach to this mesh a script called retinaTextureLoader, then load the correct texture from the resources folder depending on the mobile device…
However, with this approach, an object in the scene will have the standard @1x asset loaded at runtime, then the correct @2x texture loaded, meaning it has to load two textures (the first one loads automatically). The only way to stop this is to null/delete the texture from the material in the editor, to stop the texture being loaded into the scene. This makes everything unusable in the editor though, as you’ll have no textures just white rects.
I’ve not done Editor scripting yet, how hard would it be to make a script that runs at build time to cycle through every object in the scene, see if it hast the retinaTextureLoader component attached, then delete (null) the texture from the attached material?
NOTE: While documenting this writing, I came across [PostProcessSceneAttribute] - which is confusingly documented as “Add this attribute to a method to get a notification just before building the scene”. This may or may not do exactly what you need allowing you to just tap in to the process before building a scene to filter out objects without having to replace the build pipeline.
My initial response:
It’s not incredibly difficult, but it comes with one drawback (that you can probably live with).
You need to call your code to deal with retinaTextureLoader, then call BuildPipeline.BuildPlayer(…). The drawback is that you need to do this in your own menu function and you can’t do builds from the normal Build window (well, you could, but it wouldn’t do your retinaTextureLoaderPreprocess).
This is all because though there is such a thing as [PostProcessBuildAttribute] there is no corresponding alternative for preprocessing.
Check out the documentation about BuildPipeline, that should clue you on some point to start from.
Between those two options (replacing the pipeline or tapping in to the scene post process) you should be able to solve your problem.