- Home /
Load zipfile from resources
Hi,
I want to load a zip file with some basic content for the user. But when I use this:
TextAsset zipAsText = Resources.Load(path, typeof(TextAsset)) as TextAsset;
object zipObject = Resources.Load(path);
Both returns 'null'. As path and path.zip.
Is it possible to load a zip from resources?
EDIT: Just to be clear, it is a .zip file. It contains .xml and .jpg within the .zip.
V1ncam
You file is in the Resources folder? The file has a .txt extension?
Answer by donDre · May 21, 2014 at 07:42 AM
I assume you want to have a zip file with some content which is unpacked at runtime.
Two possible solutions:
streaming assets
put the zip file in the streaming assets folder. (normally used for playing videos). Then do your unzip magic at runtime
http://docs.unity3d.com/Documentation/Manual/StreamingAssets.html
rename
another solution is to rename your zip file (zip is not a supported extensension for the resources.load folder) to, for example .bytes then:
TextAsset textAsset = Resources.Load(assetName, typeof(TextAsset)) as TextAsset;
System.IO.File.WriteAllBytes(fullZipPathName, textAsset.bytes);
where assetName = location of your .bytes file (without the extension)
where fullZipPathname = persistantdatapath/nameofthefile.zip
then, do your unzip magic.
Answer by Graham-Dunnett · May 20, 2014 at 04:31 PM
Unity will include your file in Resources as a text asset if it's got a file extension documented as supported. Maybe look at the size of the resources.asset file in the build. Add in some text assets that are around 1M in size and see if the resources.asset grows in size accordingly.
.html .htm .xml .bytes .json .csv .yaml .fntText Assets are a format for imported text files. When you drop a text file into your Project Folder, it will be converted to a Text Asset. The supported text formats are:
.txt