I’d like to store textfiles with other file endings than “.txt” as TextAssets.
Is it possible to override the TextAssets class to allow for other file extensions to be recognized as text files?
There are some .po files in the project edited and updated with external translation software. Now they have to be renamed each time from “.po” to “.txt”.
You can still load any file with System.IO instead if you have to. Its nearly as simple as using Text Asset, and more flexible.
There are plenty of examples out there. Just use File.ReadAllText() or look into StreamReader for example.
For your translation files you could just do this:
string filepath = path+"lang_"+MyLanguage+".po";
if(File.Exists(filepath))
var languageFile = File.ReadAllText(filepath);
This is actually really easy to handle with the relatively new ScriptedImporter API:
[ScriptedImporter(0, "po")]
public class PoConverter : ScriptedImporter {
public override void OnImportAsset(AssetImportContext ctx)
{
var contents = File.ReadAllText(ctx.assetPath);
var text = new TextAsset(contents);
ctx.AddObjectToAsset("Text", text);
}
}
Your .po objects are now treated as TextAssets. You might have to reimport them after adding that script, to make them run. Or maybe not, don’t have that much experience with the API.