- Home /
File extensions other than XML in Resources?
When doing Resources.Load, if the extension of a file is known to Unity (like *.xml) it'll load it into a TextAsset just fine. But if it's an unknown file extension, it gets ignored.
I'm using OGMO Editor for a 2D tile-based game I'm making in Unity. It saves its levels in XML format, but they are of the extension .oel. Every single time I save a level, I've been having to manually copy and rename it from .oel to *.xml in explorer, which is extremely annoying and time consuming.
Is there any way to get Unity's resource manager to accept file types other than the arbitrary ones it already knows about?
Thanks!
Answer by Bunny83 · Jun 05, 2013 at 10:17 PM
No, i don't think there's a way to make Uniyt accept other types. However you can write an editor script which does the renaming for you. Depending on what kind of game it is and what platform you target you could use external files. Either load them from a subfolder (standalone, mobile) or load them from a webeerver (webplayer, mobile)
Thanks for your response.
That's really frustrating... I've already had to roll my own audio manager, input manager, game object base class (allowing update ordering), and purchase a library for 2D sprite rendering. Now I have to program my own file handling?
I thought Unity was supposed to be a full-featured game engine? Perhaps I'll look into alternatives for my next project.
I have to say though I was pleasantly surprised how easy it was to write the editor script. Here's my quick-and-dirty script for anyone else who needs to do this:
using UnityEditor;
using UnityEngine;
using System.IO;
public class BatchRenamer
{
[$$anonymous$$enuItem("BeatBros/Rename *.oel to *.xml %r")]
public static void RenameOELToX$$anonymous$$L()
{
DirectoryInfo info = new DirectoryInfo("Assets/Resources/Levels");
FileInfo[] fileInfo = info.GetFiles();
foreach(FileInfo file in fileInfo)
{
if(file.Extension.ToLower() == ".oel")
{
string newname = "Assets/Resources/Levels/" + file.Name.Substring(0, file.Name.Length-3) + "xml";
FileUtil.DeleteFileOrDirectory(newname);
FileUtil.CopyFileOrDirectory( file.ToString(), newname);
}
}
}
}