Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by MindJuice · Feb 21, 2012 at 10:20 PM · serverloadresourcesurlc# dll

Loading resources from a ZIP file from a server

Is it possible to load resources such as the following from a ZIP file (or other compression format) that has been retrieved from the web using WWW or perhaps the UniWeb extension?

  • PNG images

  • Sounds

  • Javascript code

This needs to be cross-platform compatible (Mac, PC, iPad, Android -- I don't care about Webplayer or Flash).

Also, Asset Bundles don't seem to be an option since you need Unity to create them, and I want to create them from a server program that won't have access to Unity (unless the file format is now open & documented).

I have found some older posts asking similar questions, but they are out of date and implied that a better way might be available soon.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by MindJuice · Mar 01, 2012 at 05:42 AM

I found various bits and pieces regarding this on blogs and Unity Answers posts. The code below is what I pieced together.

With this, I was able to download a ZIP file, save it to the Documents folder on the iPhone and then unzip the two files that were in the test.zip file. Obviously this is not an example of a good way to setup your code, but it shows you how the pieces work to download and unzip the files.

 using UnityEngine;
 using System;
 using System.Text;
 using System.Collections;
 using System.IO;
 using ICSharpCode.SharpZipLib.Zip;
 
 public class ZipTest : MonoBehaviour {
 
     private WWW www;
     private bool isUnzipped = false;
 
     // Use this for initialization
     void Start () {
         string url = "http://www.yoursite.com/files/test.zip";
         www = new WWW(url);
     }
 
     // Update is called once per frame
     void Update () {
         if (www.isDone && !isUnzipped)
         {
             Debug.Log("Load of test.zip complete");
             byte[] data = www.bytes;
 
             string docPath = Application.dataPath;
             docPath = docPath.Substring(0, docPath.Length - 5);
             docPath = docPath.Substring(0, docPath.LastIndexOf("/"));
             docPath += "/Documents/test.zip";
             Debug.Log("docPath=" + docPath);
             System.IO.File.WriteAllBytes(docPath, data);
     
             using (ZipInputStream s = new ZipInputStream(File.OpenRead(docPath)))
             {
                 ZipEntry theEntry;
                 while ((theEntry = s.GetNextEntry()) != null)
                 {
                     Console.WriteLine(theEntry.Name);
                     
                     string directoryName = Path.GetDirectoryName(theEntry.Name);
                     string fileName      = Path.GetFileName(theEntry.Name);
                     
                     // create directory
                     if ( directoryName.Length > 0 )
                     {
                         Directory.CreateDirectory(directoryName);
                     }
 
                     if (fileName != String.Empty)
                     {
                         string filename = docPath.Substring(0, docPath.Length - 8);
                         filename += theEntry.Name;
                         Debug.Log("Unzipping: " + filename);
                         using (FileStream streamWriter = File.Create(filename))
                         {
                             int size = 2048;
                             byte[] fdata = new byte[2048];
                             while (true)
                             {
                                 size = s.Read(fdata, 0, fdata.Length);
                                 if (size > 0)
                                 {
                                     streamWriter.Write(fdata, 0, size);
                                 }
                                 else
                                 {
                                     break;
                                 }
                             }
                         }
                     }
                 }
                 isUnzipped = true;
             }
         }
     }
 }

I just created an empty Unity project and added a Cube to the scene and attached ZipTest.cs (the file that contains the above code) to the Cube object.

Also, note that the path manipulation done here is for iOS only. You will need to create different file paths for other platforms.

Here is the website: SharpZipLib Site

And here is the download link for the source code to include in your project: SharpZipLib Source Code Download

I removed the source folders for BZip2, GZip, Lzw and Tar since I didn't need those. This will make the code a bit smaller. It may be possible to remove other files too such as Encryption, depending on your needs.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Contract-killer · Mar 08, 2013 at 02:16 PM 0
Share

HI there I download the required file but issue is I am getting lots of error in it

avatar image Contract-killer · Mar 08, 2013 at 02:17 PM 0
Share

please let me know if you have solution. my contact id is a.verma.2906@gmail.com actually it is not able to find the ICSharpCode file

avatar image hottotty · Nov 24, 2014 at 01:00 PM 0
Share

most excellent comments here. I tried it and it didnt work.

avatar image
0

Answer by OfficeThrashing · Sep 27, 2018 at 06:12 AM

Eroors

I am getting these much errors . how to solve them?? @mindjuice


screenshot-33.png (86.7 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Accessing 4.6 GUI build-in sprites in C# 0 Answers

Resources.Load wont read text file 6 Answers

How do I make sure a resource is loaded or is instantiated? 2 Answers

load resources material 0 Answers

I think I abuse of Ressources.load 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges