In my Resources folder I have a subfolder for images, I would like to get all the file names of those images from within that folder.
tried several Resources.loadAll
methods to afterwards get the .name but without success
was is the right practice to achieve what I'm trying to do here ?
Hmm... why not try this.
There is no built-in API to do this because the information is not after you build. You cant' even do this with what's in the accepted answer. That would only work in the Editor. When you build the project, your code will fail.
Here's what to do:
1. Detect when the build button is clicked or when a build is about to happen in the
OnPreprocessBuild
function.2. Get all the file names with
Directory.GetFiles
, serialize it to json and save it to the Resources folder. We use json to make it easier to read individual file name. You don't have to use json. You must exclude the ".meta" extension.Step 1 and 2 are done in the Editor.
3. After a build or during run-time, you can access the saved file that contains the file names as a
TextAsset
withResources.Load<TextAsset>("FileNames")
then de-serialize the json fromTextAsset.text
.Below is very simplified example. No error handling and that's up to you to implement. The Editor script below saves the file names when you click on the Build button:
During run-time, you can retrieve the saved file names with the example below: