I’m trying to write an editor script which creates an XML file to go with certain textures. I want the resulting file as an asset in the asset database. Is this possible?
My script so far is this:
public class ImageImporter : AssetPostprocessor
{
void OnPreprocessTexture()
{
if (assetPath.Contains("_ImageImport")==true)
{
TextureImporter TI = assetImporter as TextureImporter;
TI.isReadable = true;
char[] suffix = new char[4] {'.','t','g','a'};
TextAsset TA = new TextAsset();
AssetDatabase.CreateAsset(TA, assetPath.TrimEnd(suffix) + ".xml");
}
}
}
Unfortunately, no asset is created and I get a bunch of null object violations in System.Reflection.Binder instead. Perhaps I’m going about things the wrong way, but I simply want to analyze incoming textures, and write the data to an XML file which is part of the asset database (maybe I’ll add more stuff and make it a prefab).
I tried AssetDatabase.SaveAssets() too but it made no difference, and also crashed.