Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by hollym16 · Oct 02, 2014 at 10:36 AM · scenestreamingassetspersistentdatapathqcar

Editing a script

I've got the following script which extracts files in a string from the streaming assets folder, and saves them to a persistent data path:

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class ObbExtractor : MonoBehaviour {
     
     void Start () {
         StartCoroutine(ExtractObbDatasets());
     }
     private IEnumerator ExtractObbDatasets () {
         string[] filesInOBB = {"Tracker_Name.dat", "Tracker_Name.xml"};
         foreach (var filename in filesInOBB) {
             string uri = "file://" + Application.streamingAssetsPath + "/QCAR/" + filename;
             
             string outputFilePath = Application.persistentDataPath + "/QCAR/" + filename;
             if(!Directory.Exists(Path.GetDirectoryName(outputFilePath)))
                 Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath));
             
             var www = new WWW(uri);
             yield return www;
             
             Save(www, outputFilePath);
             yield return new WaitForEndOfFrame();
         }
         // When done extracting the datasets, Start Vuforia AR scene
     }
     private void Save(WWW www, string outputPath) {
         File.WriteAllBytes(outputPath, www.bytes);
         
         // Verify that the File has been actually stored
         if(File.Exists(outputPath))
             Debug.LogError("File successfully saved at: " + outputPath);
         else
             Debug.LogError("Failure!! - File does not exist at: " + outputPath);
         
         Application.LoadLevel("SceneMenu1");
     }
 }

However, it only saves the .dat file to the path; the first file in the string. So my plan was to identify, extract and save the files individually, as opposed to a string, to see if that worked. I tried this script:

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class ObbExtractor2 : MonoBehaviour {
     
     void Start () {
         StartCoroutine(ExtractObbDatasets());
     }
     private IEnumerator ExtractObbDatasets () {
             string XMLuri = "file://" + Application.streamingAssetsPath + "/QCAR/" + "Tracker_Name.xml";
             string XMLoutputFilePath = Application.persistentDataPath + "/QCAR/" + "Tracker_Name.xml";
             if(!Directory.Exists(Path.GetDirectoryName(XMLoutputFilePath)))
                 Directory.CreateDirectory(Path.GetDirectoryName(XMLoutputFilePath));
             
         string DATuri = "file://" + Application.streamingAssetsPath + "/QCAR/" + "Tracker_Name.dat";
         string DAToutputFilePath = Application.persistentDataPath + "/QCAR/" + "Tracker_Name.dat";
         if(!Directory.Exists(Path.GetDirectoryName(DAToutputFilePath)))
             Directory.CreateDirectory(Path.GetDirectoryName(DAToutputFilePath));
 
         var XMLwww = new WWW(XMLuri);
         yield return XMLwww;
         Save(XMLwww, XMLoutputFilePath);
         yield return new WaitForEndOfFrame();
         
         var DATwww = new WWW(DATuri);
         yield return DATwww;
         Save(DATwww, DAToutputFilePath);
         yield return new WaitForEndOfFrame();    
         }
         // When done extracting the datasets, Start Vuforia AR scene
 
     private void Save(WWW www, string outputPath) {
         File.WriteAllBytes(outputPath, www.bytes);
         
         // Verify that the File has been actually stored
         if(File.Exists(outputPath))
             Debug.LogError("File successfully saved at: " + outputPath);
         else
             Debug.LogError("Failure!! - File does not exist at: " + outputPath);
         
         Application.LoadLevel("SceneMenu1");
     }
 }

When I test it in the Editor, in the Console it only says the .xml file has been saved (the first one to be identified) Why is it only saved the one file?

Could anyone please help?

Comment
Add comment · Show 12
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 Xitech_ · Oct 02, 2014 at 12:14 PM 0
Share

Im sorry, forgot to post my code. Let me post my code here. Hold on please :) Edit: Dont have the files here. after work ill try

avatar image hollym16 · Oct 02, 2014 at 12:29 PM 0
Share

Thank you, it'll be a lifesaver!

avatar image hollym16 · Oct 03, 2014 at 07:21 AM 0
Share

LevoTNTO could you please send me the code yo have?

avatar image Xitech_ · Oct 03, 2014 at 08:05 AM 0
Share

And yet again I forgot about it, im re-program$$anonymous$$g an app so I keep forgetting it, my appologies! I've just putted it in my agenda so I wont forget about it. Ill be at home at around 6 P$$anonymous$$ CET

Note: If the scripts only works for the first file. Its not a good solution but you can make an empty gameObject for each .X$$anonymous$$L and .DAT file, put in the script on each of them with the correct information(make it a public variable so you can change it in the hierachery).

avatar image luis_punk · Dec 24, 2014 at 07:19 AM 1
Share

Sorry, you've been able to solve this problem? because now I also encountered the same eh! In my case I created the files on the computer, but in the dispositovo (tablet) I created the files but empty bone 0 $$anonymous$$B

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by smoggach · Oct 24, 2014 at 01:12 PM

Hi. In the second code segment, your Save coroutine never breaks. Also it's not a good idea to load levels from a coroutine. The reason you only save the first file is because the Application.LoadLevel destroys the script that's running (or stops it or something). Put your Application.LoadLevel at the end of ExtractObbDatasets instead of Save.

Comment
Add comment · Show 1 · 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 Bunny83 · Oct 24, 2014 at 01:24 PM 0
Share

Exactly, Application.LoadLevel will wipe out all gameobjects in the scene including the scripts attached and the coroutines running on them. The first script would work just find without that LoadLevel.

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

32 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Click handling at world scene level 1 Answer

How to make loading screens? 1 Answer

How to find a prefab in another scene? 1 Answer

Pickable item to unlock doors (Being able to proceed next scene) 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