Table of Contents

TAssetBundle

TAssetBundle is a powerful asset bundle integrated management system.

TAssetBundle uses the same folder structure as your project and organizes and builds asset bundles the way you want.


Index


Using an TAssetBundle Asset

TAssetBundle provides two ways to load assets.

Using Asset Path

The asset path is the full path to the asset and needs to be modified if the asset is moved.

How to get asset path?

get_asset_path

using UnityEngine;
using TAssetBundle;

public class TestLoadAsset : MonoBehaviour
{
    public string prefabPath; //Asset Path        

    void Awake()
    {
        //Load as Asset Path
        var loadAsset = AssetManager.LoadAssetAsync<GameObject>(prefabPath);
        loadAsset.OnComplete += (IAssetHandle<GameObject> assetHandle) =>
        {
            var asset = assetHandle.Get();

            //use asset
            Instantiate(asset);
        };
    }

    void OnDestroy()
    {
        //Unload as Asset Path
        AssetManager.UnloadAsset(prefabPath);
    }
}

Using Asset Reference

Asset references allow you to drag and drop or select assets in the editor.

Asset references do not require modification if the asset is moved.

drag_and_drop_asset

using UnityEngine;
using TAssetBundle;

public class TestLoadAssetReference : MonoBehaviour
{
    [AssetType(typeof(GameObject))]
    public AssetRef prefab;

    void Awake()
    {
        //Load as Asset Reference
        var loadAsset = AssetManager.LoadAssetAsync<GameObject>(prefab);
        loadAsset.OnComplete += (IAssetHandle<GameObject> assetHandle) =>
        {
            var asset = assetHandle.Get();

            //use asset
            Instantiate(asset);
        };
    }

    void OnDestroy()
    {
        //Unload as Asset Reference
        AssetManager.UnloadAsset(prefab);
    }
}

Unload With AssetHandle

It's fast because it skips one key lookup when unloading into an asset handle.

using UnityEngine;
using TAssetBundle;

public class TestLoadAssetReference : MonoBehaviour
{
    [AssetType(typeof(GameObject))]
    public AssetRef prefab;

    private IAssetHandle prefabHandle;

    void Awake()
    {
        //Load as Asset Reference
        var loadAsset = AssetManager.LoadAssetAsync<GameObject>(prefab);
        loadAsset.OnComplete += (IAssetHandle<GameObject> assetHandle) =>
        {
            prefabHandle = assetHandle;
            var asset = assetHandle.Get();

            //use asset
            Instantiate(asset);
        };
    }

    void OnDestroy()
    {
        //Unload as Asset Handle
        AssetManager.UnloadAsset(prefabHandle);
    }
}

2. Play with Assets Directly (Only Editor)

Using assets directly allows you to run right away without having to configure or build asset bundles.

Select TAssetBundle/Settings Menu

settings_hilght

Select Editor Play Mode as Editor Asset

editor_asset_mode

Play!!

3. Play with Asset Bundle

Play using AssetBundles. To use an AssetBundle, you must first configure the AssetBundle using TAssetBundleManifest.

What is TAssetBundleManifest

  • Configures the AssetBundle Composition Strategy for the assets in the folder.
  • You can setup built-in, encryption, tags, etc to AssetBundle.
  • Indicates configured AssetBundle information

Create TAssetBundleManifest

Create TAssetBundleManifest in the folder where you want to bundle assets.

create_manifest

Select TAssetBundleManifest file

select_manifest

Configure AssetBundle

There are two ways to organize your AssetBundles.

Manual Configuration

add_assetbundle_build_info

Add asset bundle build information

drag_and_drop_assets

Finish!

Auto Configuration

Automatically configure AssetBundles using a Composition Strategy

What is Composition Strategy

  • individual composition strategy to configure AssetBundle in TAssetBundleManifest
  • Run Composition Strategy from the context menu will run the strategies in the order listed.

add_composition_strategy

Add Composition Strategy

select_composition_strategy select_composition_strategy2

Select all_together Composition Strategy

all_together is a strategy to organize assets in a folder into one AssetBundle.

run_composition_strategy

Run Composition Strategy in the context menu of TAssetBundleManifest

Finish!

Build Asset Bundle

build_asset_bundle

Build asset bundle

Editor Play Mode to AssetBundle

Select TAssetBundle/Settings Menu

setting_playmode_assetbundle

Select Editor Play Mode as Asset Bundle

Play!!


Remote Assets Download

Flow of Remote Assets Download

  1. Check Catalog Update
  2. Update Catalog
  3. Get Download Size
  4. Download Assets
  • Assets that have been downloaded are cached and will not be downloaded again
using UnityEngine;
using TAssetBundle;

public class RemoteDownloadAssets : MonoBehaviour
{
    public string remoteDownloadUrl;
    public GameObjectAssetRef needDownloadAsset;

    private void Awake()
    {
        AssetManager.SetRemoteUrls(new string[] { remoteDownloadUrl });
    }

    private void OnGUI()
    {
        GUILayout.BeginVertical();

        if (GUILayout.Button("Check Catalog Update"))
        {
            var checkCatalogUpdateAsync = AssetManager.CheckCatalogUpdateAsync();

            checkCatalogUpdateAsync.OnComplete += (result) =>
            {
                Debug.Log("need catalog update - " + result);
            };
        }

        if (GUILayout.Button("Update Catalog"))
        {
            var updateCatalogAsync = AssetManager.UpdateCatalogAsync();

            updateCatalogAsync.OnComplete += (result) =>
            {
                Debug.Log("update catalog - " + result);
            };
        }

        if (GUILayout.Button("Get Download Size All"))
        {
            var downloadSizeAsync = AssetManager.GetDownloadSizeAsync();

            downloadSizeAsync.OnComplete += size =>
            {
                Debug.Log("download size - " + size);
            };
        }

        if (GUILayout.Button("Download All"))
        {
            var downloadAsync = AssetManager.DownloadAsync();
            downloadAsync.OnProgress += OnDownloadProgress;
            downloadAsync.OnComplete += OnDownloadComplete;
        }

        if (GUILayout.Button("Get Download Size By Tags"))
        {
            var downloadSizeAsync = AssetManager.GetDownloadSizeByTagsAsync(new string[] 
            { 
                "character" 
            });

            downloadSizeAsync.OnComplete += size =>
            {
                Debug.Log("download size - " + size);
            };
        }

        if (GUILayout.Button("Download By Tags"))
        {
            var downloadAsync = AssetManager.DownloadByTagsAsync(new string[] 
            { 
                "character"
            });

            downloadAsync.OnProgress += OnDownloadProgress;
            downloadAsync.OnComplete += OnDownloadComplete;
        }

        if (GUILayout.Button("Get Download Size By Assets"))
        {
            var downloadSizeAsync = AssetManager.GetDownloadSizeByAssetsAsync(new AssetRef[] 
            { 
                needDownloadAsset 
            });

            downloadSizeAsync.OnComplete += size =>
            {
                Debug.Log("download size - " + size);
            };
        }

        if (GUILayout.Button("Download By Assets"))
        {
            var downloadAsync = AssetManager.DownloadByAssetsAsync(new AssetRef[] 
            { 
                needDownloadAsset 
            });

            downloadAsync.OnProgress += OnDownloadProgress;
            downloadAsync.OnComplete += OnDownloadComplete;
        }

        GUILayout.EndVertical();
    }    

    private void OnDownloadProgress(AssetBundleDownloadInfo downloadInfo)
    {
        double value = downloadInfo.DownloadedSize / (double)downloadInfo.TotalDownloadSize;

        Debug.Log(string.Format("downloading - {0:0.00}%, {1}/{2}", 
            value * 100, downloadInfo.DownloadedSize, downloadInfo.TotalDownloadSize));
    }

    private void OnDownloadComplete(AssetBundleDownloadInfo downloadInfo)
    {
        if (downloadInfo.TotalDownloadSize == 0)
        {
            Debug.Log("don't need to download");
        }
        else if (downloadInfo.IsDownloadComplete())
        {
            Debug.Log("download complete");
        }
        else
        {
            Debug.Log("download fail");
        }
    }
}

TAssetBundleManifest

tassetbundle_manifest

  1. If enabled, it is included in the AssetBundle build target.
  2. If built-in is enabled, the configured AssetBundles are included in the app.
  3. If encrypt is enabled, it encrypts the configured AssetBundle.
  4. Set tags for configured AssetBundles.
  5. A list of composition strategies, strategies are always run in order.
  6. AssetBundle build list, AssetBundle build information that has been configured.

Default Composition Strategies

default_composition_strategy

  • all_separatly: Add assets as individual asset bundles.
  • all_together: Add assets as one asset bundle.
  • clear: Clear asset bundle build information.
  • exclude_objects: Exclude specific assets from asset bundle build information.
  • file_separatly: Add only the files as individual asset bundles.
  • file_together: Add only the files as one asset bundle.
  • fixed_objects: Add only specific assets to one asset bundle.
  • folder_separatly: Add only folders as individual asset bundles.
  • fodler_together: Add only the folder as one asset bundle.
  • regex_match: Only assets whose file names match the regular expression are added to one asset bundle.
  • regex_match_delete: Remove asset bundle build information if asset filename matches regular expression
  • regex_not_match_delete: Remove AssetBundle build information if asset file name does not match regular expression
  • same_name_together: Add assets with the same file name as one asset bundle

TAssetBundle Menu

tassetbundle_menu

  1. Open TAssetBundle Settings File
  2. Remove build cache information for current platform
  3. Build Asset Bundle
  4. Run the composition strategy on all TAssetBundleManifest
  5. Clear AssetBundle build information for all TAssetBundleManifest using Composition Strategy
  6. Open Build Output Folder
  7. Open Download Cached Assets Folder
  8. Remove Download Cached Assets
  9. Open TAssetBundle Browser
  10. Open Tag Editor
  11. Open Web Server Test Window
  12. Open AssetBundle Dependency Checker
  13. Open Asset Reference Tracker

TAssetBundle Browser

The TAssetBundle Browser is a browser that allows you to view all TAssetBundleManifests and current AssetBundle information at once.

Select TAssetBundle/TAssetBundle Browser Menu

tassetbundle_browser

  1. Clear AssetBundle build information for all TAssetBundleManifest using Composition Strategy
  2. Run the composition strategy on all TAssetBundleManifest
  3. Build Asset Bundle
  4. Check dependencies between AssetBundles
  5. Total Asset Bundle Count
  6. A single AssetBundle build name and the assets it contains
  7. TAssetBundleManifest and file path
  8. Count of AssetBundles configured in TAssetBundleManifest
  9. Assets not yet configured as AssetBundle in TAssetBundleManifest

TAssetBundle Settings

All settings used by TAssetBundle

tassetbundle_settings

  1. The name of the catalog file generated when building the AssetBundle
  2. AssetBundle Build Output Folder Name
  3. Catalog file extension
  4. Asset Bundle file extension
  5. Enable catalog compression
  6. Enable catalog encryption
  7. encryption key
  8. Add the hash of the asset bundle file name
  9. Editor Play Mode (Editor Only)
  10. Forced in editor to use only remote AssetBundles. (Editor only)
  11. Maximum count of concurrent web requests
  12. Maximum count of web request retries
  13. Retry request wait duration
  14. Using the build cache only builds the AssetBundles that need to be built.
  15. Enable Debugging Log
  16. Include catalog in app
  17. How to embed AssetBundles into app
  18. Recompress the AssetBundles built-in in your app to lz4 (very efficient, but slightly increases file size).
  19. If enabled, the UnityRemoteAssetBundleProvider is used. When disabled, always uses a SpecificManagedAssetBundleProvider. SpecificManagedAssetBundleProvider are default used for crypto asset bundles.
  20. Set the custom catalog serializer
  21. Set the custom crypto serializer
  22. Set default remote url