Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Split APK Google Play OBB Downloader Question

Discussion in 'Developer Preview Archive' started by Muckel, Sep 5, 2012.

  1. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    Hello,
    i use the new nice feature to split my apk...
    All works well but i have heard on older Devices i should use the Google Play OBB Downloader from Asset Store
    http://u3d.as/content/unity-technologies/google-play-obb-downloader/2Qq

    So now i want to have it check automatic @ the start of my APP.
    I use this Code but i'm totally unsure if it is correct or if i can optimize it.
    Plz have a look and give feedback what to change or do better i hope this tread is useful for all others who use the Google Play OBB Downloader from Store....:)

    The Idea is : Check @ start if OBB File exist... if not download it after download go on use the obb...
    If the obb file is there go on and start...

    many many thxxx

    Code (csharp):
    1.     void Start ()
    2.     {
    3.         if (!GooglePlayDownloader.RunningOnAndroid())
    4.         {
    5.             return;
    6.         }
    7.        
    8.         string expPath = GooglePlayDownloader.GetExpansionFilePath();
    9.         string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
    10.         if (mainPath != null) {    
    11.             return;
    12.         }
    13.         if (mainPath == null) {    
    14.             GooglePlayDownloader.FetchOBB();
    15.         }  
    16.  
    17.     }  
    18.  
    19. }
     
  2. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    My recommendation is to have a start scene that acts as a loader. The code above is going to get you the file... but to start a coroutine and wait until you can load something from the OBB file (some small texture or something from your resources.Load() requests. Then you can progress onto the actual game's first scene. Ideally, everything should work. However, I'm struggling to convert my own project to 4.0. Currently, it appears that videos are crashing... but that's probably another issue.
     
  3. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    Hi,
    well if i use a Start Scene then i want to use this code.
    It seams to work but nor sure if it is well done... :roll:
    Code (csharp):
    1.     void Start ()
    2.     {
    3.         if (!GooglePlayDownloader.RunningOnAndroid())
    4.         {
    5.             Application.LoadLevel (1);
    6.             //return;
    7.         }
    8.        
    9.         string expPath = GooglePlayDownloader.GetExpansionFilePath();
    10.         if (expPath == null)
    11.         {
    12.  
    13.             Debug.Log("External storage is not available!");
    14.         }
    15.         else
    16.         {
    17.         string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
    18.         //string patchPath = GooglePlayDownloader.GetPatchOBBPath(expPath);
    19.         if (mainPath != null) {
    20.         Application.LoadLevel (1);
    21.         }
    22.         if (mainPath == null)   {      
    23.             GooglePlayDownloader.FetchOBB();
    24.             Application.LoadLevel (1);
    25.             //Debug.Log("After GooglePlayDownloader");
    26.         }  
    27.         }
    28.  
    29.     }
     
  4. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    That is the general gist of it. I ran into some problems with loading the level as soon as mainPath was not null. It happens a bit too soon from when the levels are available. So what I did to get around this was to just put a coroutine loop that tries to load a resource using Resources.Load() on a small resource until it didn't return null... it returns a non-null object that is when I load the next level. Hope that helps.
     
  5. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    Hi Ferazel,
    well i ran into the same Problem....
    After downloading the obb file it hangs there and can not load Level 1...
    If i quit the Task in the Taskmanager and restart the APP all is fine but that is not what i expect as a customer...
    So plz help
    can you maybe post your coroutine here ? So that i get the idea how to wait until....

    many many thxxx
     
    Last edited: Sep 7, 2012
  6. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Code (csharp):
    1.  
    2.     void Start ()
    3.  
    4.     {
    5.  
    6.         if (!GooglePlayDownloader.RunningOnAndroid())
    7.  
    8.         {
    9.  
    10.             Application.LoadLevel (1);
    11.  
    12.             //return;
    13.  
    14.         }
    15.  
    16.        
    17.  
    18.         string expPath = GooglePlayDownloader.GetExpansionFilePath();
    19.  
    20.         if (expPath == null)
    21.  
    22.         {
    23.  
    24.  
    25.  
    26.             Debug.Log("External storage is not available!");
    27.  
    28.         }
    29.  
    30.         else
    31.  
    32.         {
    33.  
    34.         string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
    35.  
    36.         //string patchPath = GooglePlayDownloader.GetPatchOBBPath(expPath);
    37.  
    38.         if (mainPath == null)   {      
    39.  
    40.             GooglePlayDownloader.FetchOBB();
    41.         }
    42.         //We get here, we should have the main path for the OBB file
    43.         StartCoroutine(CoroutineLoadLevel());
    44.         }
    45.     }
    46.  
    47. protected IEnumerator CoroutineLoadLevel() {
    48.       bool testResourceLoaded = false;
    49.       while(!testResourceLoaded) {
    50.            yield return new WaitForSeconds(0.5f); //Let's not constantly check, but give a buffer time to the loading
    51.            if(Resources.Load("PathToTestResource") != null) {
    52.               testResourceLoaded = true;
    53.            }
    54.       }
    55.       //Everything should be loaded now
    56.       Application.LoadLevel(1);
    57. }
    58.  
     
  7. Muckel

    Muckel

    Joined:
    Mar 26, 2009
    Posts:
    471
    Wow !
    many many thanks for sharing it !!!

    i see now where i had my error...
    i totally forgot the bool testRecourses = false;

    thank you so much .... you make my Day !

    Have a nice weekend !

    cheers
     
  8. anthonyk2

    anthonyk2

    Joined:
    Sep 18, 2012
    Posts:
    47