Search Unity

Question about Assetbundle real world usage flow

Discussion in 'Scripting' started by fugogugo, Sep 14, 2017.

  1. fugogugo

    fugogugo

    Joined:
    Jun 18, 2013
    Posts:
    12
    Hi

    I have read so many AssetBundle articles and tutorial but I still haven't found the answer for my problem. I also really wonder how and when AssetBundle.Unload() method should be called

    So this is my scenario (my game is mobile):
    1. Before the game started I wanna have a loader scene which would load all the assetbundle from my server
    2. After all downloaded then I would use that bundle for gameplay , no more downloading AssetBundle

    So all the sample on internet and even the AssetBundleManager demo always show that you should download the bundle when you want to use and load the asset. I think my scenario should be possible because I've seen some mobile unity game that do exactly what I planned to do. But what would be the drawback by using this scenario? What should I be consider when doing this?

    And what I am really wondering was : when should I call the Unload() method? is it after scenario (1) finished, or after finished doing the gameplay (2)?


    Also is it possible to achieve this by using the AssetBundleManager? when I looked at the plugin I found that you only able to download the assetbundle when you load the asset. this is not what I want. How to modify this behaviour?

    Thank youuu and I hope my question is clear enough!
     
  2. BlueRain01

    BlueRain01

    Joined:
    Aug 22, 2010
    Posts:
    86
    You can always download AssetBundles without unload them in the scene
    1- check the Asset Loader example ( it use instantiate to spawn the game objet , so you can modify that and build on it)
    2- in Unity 2017.1 there's some new changes to WWW with the introduction of UnityWebRequest you can use UnityWebRequest.GetAssetBundle("http://MyUrl.com/Assetbundle");
    https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.GetAssetBundle.html
    As i far i m concern , ABM don't use this , so if you use it you are bypassing ABM and may be you have to do extras steps to load everything correctly .
    So , maybe on the first scene you download all your bundles on a folder , then instead of using a Server path you use Folder path , just like AssetbundleManager when in Editor and silmulation mode create new folder in your game project called AssetBundle , i'm not sure but maybe you hack the definition of AssetBundleManager.SetDevelopmentBundleServer()
    it's like this :
    public static void SetDevelopmentAssetBundleServer()
    {
    #if UNITY_EDITOR
    // If we're in Editor simulation mode, we don't have to setup a download URL
    if (SimulateAssetBundleInEditor)
    return;
    #endif

    TextAsset urlFile = Resources.Load("AssetBundleServerURL") as TextAsset;
    string url = (urlFile != null) ? urlFile.text.Trim() : null;
    if (url == null || url.Length == 0)
    {
    Debug.LogError("Development Server URL could not be found.");
    //AssetBundleManager.SetSourceAssetBundleURL("http://localhost:7888/" + UnityHelper.GetPlatformName() + "/");
    }
    else
    {
    AssetBundleManager.SetSourceAssetBundleURL(url);
    }
    }
    Maybe create a new method based on this but without the Editor conditions and of course specify your platform .
    Hope this help you to get started .
     
    Last edited: Oct 23, 2017