- Home /
How to load objects from a file outside of unity3d
Hi,
Is their a way to load files (videos, images) from outside of unity3d assets directory?
What i mean is if you program in a text field function and a button to search your directory on your hard drive for videos and images, would they show up dynamically in the standalone application when i try to search for a file? If so, can i get an idea of how this might be done? I know that this can be done on the server side of things, but the client i am working for wants to search for all his files on his hard drive. I know if i try to use resource.load(), it won't work since it has to be within the the unity assets directory.
Ok thank! So can all this be done on the Iphone using xcode?
Answer by AliAzin · Apr 16, 2011 at 05:27 PM
you can use System.IO for searching in directories and you can load video(ogg format) and images(png) using WWW class in unity. The only thing you should do is pass your file path like this :
var url = "file://c:/fridays.jpg"; function Start () { // Start a download of the given URL var www : WWW = new WWW (url);
// Wait for download to complete
yield www;
// assign texture
renderer.material.mainTexture = www.texture;
}
see WWW class reference in docs
Ok thanks! So can all this be done on the Iphone using xcode?
I don't have the iphone version, but it should work with iphone too.
Answer by Uzquiano · Apr 16, 2011 at 06:04 PM
Hi,
For text files I do like this:
private var file : String = ""file://c:/files/file.txt";
var reader : StreamReader = File.OpenText(file);
Ok thank! So can all this be done on the Iphone using xcode?
Well... I have never develop Unity for iPhone but I think it should work. And about Xcode, it is only a tool, what matter is what you write in there ;)
Answer by ravi_gohil999 · Jan 24, 2013 at 06:51 AM
You need to use file:///c:/.... to let this file protocol work....3 slashes