- Home /
Get resource path
Hi,
I use Resources.LoadAll(path) to load all items in the folder and subfolders. After I do this I would like to get the subfolder's name of the objects, or the complete path like I see in the editor. Is this possible?
And don't suggest AssetDatabase, because it is an editor class, and I need it in my build.
Thanks in advance.
The Application API has useful calls for getting paths for data, persistantData, strea$$anonymous$$g assets etc:
http://docs.unity3d.com/Documentation/ScriptReference/Application.html
Beyond that you could use the System.IO.Directory:
http://msdn.microsoft.com/en-us/library/system.io.directory.aspx
The resource loaded is inside the build, it is not yet a file. I want to get the directory like I see in the editor. So the Directory class I cannot use, because you need a real file to get the path. And I cannot find the function I need in the Application class.
You are right, I forgot it was only one file when built to a standalone. Application.dataPath will give you the path to your Data folder then adding resources.assets will give you the file but beyond that there is no way access the internals of the file. The only way to know the paths etc would be to add a build step that saved them in text/xml and you could reference back to that.
So no other way? I cannot create a build step, because this will not get deployed on an iOS device. Or will it?
This is going to sound odd but if you create a custom menu entry to build your project and in that function parse the resources directory of your project. Then put this in a text file and add it to your resources directory. This way you can load file from resources and parse it for the paths of all the individual assets. I am still not sure why you need the paths to each asset.
Answer by $$anonymous$$ · Oct 24, 2012 at 07:50 PM
To come to the conclussion that it is not possible to get the path data inside the Resources.
I have com up with this idea: I named my files in the resources map 'folder-name'
ex: RootFolder/Test/Test-Object
So in this case I can split my name name.Split('-') and get an array of [0] = subfolder [1] = name and this to the resources
Or like RoflHarris said, you can also let a file be generated with the folder structures.
Answer by inewland · May 10, 2013 at 05:24 PM
Also if others are looking for something temporary, I was able to put my files into the StreamingAssets folder and get their path...
var filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "MyFile");
Note that this doesn't work for all platforms, but I was able to use it on iOS for temporary storage of test files. You may be able to rework this for production.
http://docs.unity3d.com/Documentation/ScriptReference/Application-streamingAssetsPath.html
Answer by Sisso · Jun 19, 2013 at 05:58 PM
Alternatively, for GameObjects you can create a component that identify when a object is in resources and its path. Next you create a Editor script to update all paths.
Your answer
Follow this Question
Related Questions
Resources.Load folders path? 2 Answers
Alternatives to Resources.Load or Refining that command 1 Answer
Store the path with Resources.Load in a string 3 Answers
Access path of stored asset 0 Answers