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

Obb Downloading Script

Discussion in 'Android' started by Spoink, Mar 4, 2015.

  1. Spoink

    Spoink

    Joined:
    May 9, 2011
    Posts:
    33
    Hey hey,

    The last couple of days I have been working on an OBB downloading script to download an OBB file which is hosted on a server of your choice.

    Since I didn't find anyone posting a script like this, and also since you guys helped me creating this one, I'm posting my solution here.

    http://pastebin.com/XRmMjKrY

    I've used this class as following:
    • Create a loading scene and place it as the first scene in the build settings.
    • Create a gui script and attach it to a game object in that scene
    • In start the gui script runs ObbDownloader.Instance.HasExpansionpack()
      • If this is true, go to the next scene (like a main menu)
      • If this is false, show a download button
    • When the user hits the download button the gui calls ObbDownloader.Instance.DownloadExpansion(gameObject);
      • The gameObject is there as a reference to receive callbacks when the download is complete.
    • While downloading I'm showing the percentage downloaded with ObbDownloader.Instance.PercentageDone; in a label
    • Once downloaded OnExpansionDownloaded() event will be triggered. Then you can switch scene to your next scene (like the main menu)
    • Then build this project with split application binary and upload the .obb on your server. Do note that you need to name the .obb in the proper obb manner (main.versionnumber.com.companyname.productname.obb)

    I have started to test this one out with good results. Any constructive feedback is welcome :)
    Enjoy.
     
    Den D. and RoyalCoder like this.
  2. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    970
  3. Spoink

    Spoink

    Joined:
    May 9, 2011
    Posts:
    33
    I had an issue with the official OBB downloader interfering with my apps AndroidManifest. Also I wanted to be able to fully customize the downloading part, which is very enclosed in the addon provided by unity.

    However if I didn't have additonal addons which needed to modify the manifest and also if I were to host the OBB on google play, I would use the official addon.
     
  4. cqc29a

    cqc29a

    Joined:
    Mar 9, 2015
    Posts:
    1
    Thanks a lot for posting your script. We had a problem with some 3rd party software and weren't unable to use the unity obb plugin, we managed to download our OBB but couldn't load a scene past the first scene. However after we rebooted the app the rest of the scenes loaded ok. From our testing it appears that Unity's scene list is initialized on boot up , it looks in the APK and also searches for any OBB's, if a OBB is loaded afterwards the scene list isn't updated, and we couldn't find anything in the documentation to force Unity to update it's scene list again. But restarting the Unity activity via the code snippet in QuickRestartAndroidApp() did the trick. Thanks
     
  5. break_heart

    break_heart

    Joined:
    Oct 16, 2014
    Posts:
    12
    Thank you very much for the code. After downloading the obb call the QuickRestartAndroidApp () function but it's like if you did nothing. Should we play something on the manifest?