Reputation: 315
I have a script attached to an object in Unity. I want to load a folder of .vtk files into my project assets folder, attach that folder to the script on the object as I would attach any public variable to a script in the editor (by dragging and dropping it), and have my script read each .vtk file in the folder as separate TextAsset objects. I would actually like each file to be an element of a TextAsset array, but that should be easy once I can get Unity to accept the folder of .vtk files as individual TextAsset objects.
I've tried declaring a public Directory and Path object to specify the folder, but I get the error that I "cannot declare a variable of static type 'Directory'".
Upvotes: 0
Views: 3545
Reputation: 737
It sounds like you're looking for Resources.LoadAll().
The folder you're loading from needs to be in a folder named Resources
inside your Assets
folder for this function to work.
The function returns an array of objects, so you'll also need to cast them to TextAssets if you need that.
Example usage:
TextAsset[] results = Array.ConvertAll(Resources.LoadAll("FolderName", typeof(TextAsset)), asset => (TextAsset)asset);
Upvotes: 2