Let me be a little bit more accurate:
I have my Unity project, with my Resources folder all set up. I know how to use Resources.Load() on a file, works perfectly. My XML files are correctly compiled at build time and converted to Text Assets, which I can load once deployed on iOS.
Now what I am doing is using Directory.GetFiles(folder, “*.xml”) with folder being my Assets/Resources/XMLs folder to get all the files contained in it before loading/reading them. Obviously this works on my computer as the actual Assets/Resources/XMLs folder exists, but not on the iOS app. I do get why it doesn’t work, that is pretty obvious.
My question is: how can I achieve this trick, “access all the files located [there] once my XMLs are compiled” with [there] being somewhere in my Resources folder?
Mmmmmh indeed that could do the trick. So in your opinion there’s no way to do this directly from the Resources, like I intended to do it? (Yes, I admit my laziness! If I could work around what I already have it would be awesome :p)
Though if you say no, I guess I’ll have to start having a peek at Editor customization (never done it yet) and implement your solution. Definitely not stupid, I already thought of creating an external tool but your approach in-editor would be way better.
There is no listing of the resource contents, no. The issue is that your resource files aren’t stored as files and folders on your device, but rather in a resources file - indexed by their paths.
Yes, the Resource class could be extended to accept all manners of file system relevant input, but it doesn’t really make a lot of sense.
Generally I would discourage using Resources.Load. For some text files you’ll not feel any difference, but basically anything you put in there has to be fully loaded before your application starts. This is unlike the rest of the assets which are only loaded when you load a scene in which they are needed.
Assuming your folder is found at Assets/Resources/XML - if it was something like Assets/Resources/Data/Xml just replace the “XML” with “Data/Xml” and it should work fine I’d imagine.
EDIT:
I’m thinking I misunderstood the question here. Disregard post >.>
The way Resources are handled makes perfect sense to me. Though I didn’t know about the “all needs to be loaded at app start” thing I’ll be more careful from now on with that…
Meanwhile, I had a quick peek at the AssetPostProcessor class: basically I just need to extend it and detect whenever an XML file is imported, and at that time add it to a textAssets array in a prefab that will act as a library (If I did get correctly what you told me earlier?). What method shall I extend in particular from AssetPostProcessor, as I see none dealing with text files imports (only textures, models and audio) in the doc?
Errrm actually I believe your post wasn’t that out of question, as I do think it could be a fix to my problem. I’ll probably give it a try, while still considering AngryAnt’s solution after what he stated about Resources being all loaded at app start.
I think KyleStaves has suggested you right answer as far as i understood your problem. I have used Resources.LoadAll() in my game and that is for iOS and it works absolutely fine. You can put all the resources which you want them to get loaded as per your requirement and LoadAll() method gives you all the files of the folders for the specified path under Resources.
To assign all of them in the inspector view is not a good approach as it loads all of them each and every time your scene is loaded no matter how many of them you use at one time, thereby wasting a lot of memory.
If you want i can provide you the code for the same or you could download the package which implements it.
You can find the link for the same in my signature.
If you want to read in raw files (say XML, PNG’s, or AssetBundles) you can put them in the StreamingAssets folder (no spaces).
These are accessible by Application.dataPath + “/Raw/” (You’ll see it in your XCode build) and you can do all the GetFile you like in there Anything you put in StreamingAssets/ will be deployed to device both on iOS and Android (getting to StreamingAssets on Android is a bit more fun)
Thanks, good to know
Though I think it’s better (in my case) to leave them with the assets as they’re probably compressed during compilation. I don’t need to edit them later, so no need to keep them raw. And even more as my build target does include Android
In order to conclude this thread, I just want to state that I used this solution and it was exactly what I wanted to achieve. How come I didn’t see that in the documentation >_<
Thanks to everybody for the fast answers.
I did read your post and did take it into account. Though if you do read correctly my post just before yours (your first one advising me to follow KyleStaves’ idea) you would see that I already agreed that this was probably (“probably” because I never state anything as certain before I try it myself, even if it appears so) the correct thing to do in order to fix my problem and that I would give it a try, which I did this morning as my workday was over at the time I posted yesterday. So I did implement that solution as stated beforehand and it did work, as expected; and since I am a nice guy, I came back to this thread in order to post a nice and clear conclusion, in case anyone will read it hoping to find a solution to a similar problem. That’s all, so as one can notice, I did go through the post thoroughly.