Search Unity

how to use Obb file ?

Discussion in 'General Discussion' started by Victor Ree, Apr 24, 2014.

  1. Victor Ree

    Victor Ree

    Joined:
    Jun 7, 2013
    Posts:
    6
    I'm use "split application binary" to create .apk and .obb files. I upload .obb file to my server and download it to sd card successfully.

    I have already download .obb file to sd card,
    obb file path: /mnt/sdcard/Android/obb/com.harry.ttbcd/main.20140423.com.harry.ttbcd.obb

    After download and write the data to sd card complete, I restart the app and use fellow code to read .obb file, but all code couldn't work well.

    /// <summary>
    /// Loads the start level.
    /// </summary>
    /// <returns>
    /// The start level.
    /// </returns>
    IEnumerator loadLevel(string levelName){
    print ("loadStartLevel1 start");
    string uri = "jar:file:///mnt/sdcard/Android/obb/com.harry.ttbcd/main.20140423.com.harry.ttbcd.obb" +
    "!/" + levelName;

    WWW www = WWW.LoadFromCacheOrDownload(uri,0);

    yield return www;

    if(www.error == null){
    Application.LoadLevelAsync(levelName);
    }
    else{
    print ("loadStartLevel err " + www.error.ToString() );
    loadLevelFromObb(levelName);
    }
    }

    /// <summary>
    /// Loads the level.
    /// </summary>
    /// <returns>
    /// The level.
    /// </returns>
    /// <param name='levelIndex'>
    /// Level index.
    /// </param>
    IEnumerator loadLevel(int levelIndex){
    print ("loadStartLevel2 start");
    string uri = "jar:file:///mnt/sdcard/Android/obb/com.harry.ttbcd/main.20140423.com.harry.ttbcd.obb" +
    "!/level" + levelIndex ;

    WWW www = WWW.LoadFromCacheOrDownload(uri,0);

    yield return www;

    if(www.error == null){
    print ("start load level2 " );
    Application.LoadLevelAsync(levelIndex);
    }
    else{
    StartCoroutine( loadLevel("splash_scene_01") );
    }
    }

    /// <summary>
    /// Loads the level from obb.
    /// </summary>
    /// <returns>
    /// The level from obb.
    /// </returns>
    /// <param name='levelName'>
    /// Level name.
    /// </param>
    IEnumerator loadLevelFromObb(string levelName){
    print ("loadLevelFromObb");
    string filePath = "file:///mnt/sdcard/Android/obb/com.harry.ttbcd/main.20140423.com.harry.ttbcd.obb";
    WWW www = WWW.LoadFromCacheOrDownload(filePath , 0);
    // Wait for download to complete
    yield return www;
    if(www.error == null){
    Application.LoadLevel(levelName);
    }
    else{
    print ("loadLevelFromObb err " + www.error.ToString() );
    }
    }

    I have add all scenes to Build Settings, but when I read obb file and load scene:
    errors:
    04-24 11:48:14.600: E/Unity(29889): Level 'splash_scene_01' (1) couldn't be loaded because it has not been added to the build settings.
    04-24 11:48:14.600: E/Unity(29889): To add a level to the build settings use the menu File->Build Settings...


    how to use .OBB file ? I don't want to use GooglePlayDownloader, I want custom download and use OBB file.
     
  2. Victor Ree

    Victor Ree

    Joined:
    Jun 7, 2013
    Posts:
    6
    I want my package size more small