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
- Play with Assets Directly (Only Editor)
- Play with Asset Bundle
- Remote Assets Download
- TAssetBundleManifest
- Default Composition Strategies
- TAssetBundle Menu
- TAssetBundle Browser
- TAssetBundle Settings
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?
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.
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
Select Editor Play Mode as Editor Asset
Play!!
3. Play with Asset Bundle
Play using AssetBundles. To use an AssetBundle, you must first configure the AssetBundle using TAssetBundleManifest.
- What is TAssetBundleManifest
- Create TAssetBundleManifest
- Configure AssetBundle
- Build Asset Bundle
- Editor Play Mode to AssetBundle
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.
Select TAssetBundleManifest file
Configure AssetBundle
There are two ways to organize your AssetBundles.
Manual Configuration
Add asset bundle build information
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
Select all_together Composition Strategy
all_together is a strategy to organize assets in a folder into one AssetBundle.
Run Composition Strategy in the context menu of TAssetBundleManifest
Finish!
Build Asset Bundle
Build asset bundle
Editor Play Mode to AssetBundle
Select TAssetBundle/Settings Menu
Select Editor Play Mode as Asset Bundle
Play!!
Remote Assets Download
Flow of Remote Assets Download
- Check Catalog Update
- Update Catalog
- Get Download Size
- 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
- If enabled, it is included in the AssetBundle build target.
- If built-in is enabled, the configured AssetBundles are included in the app.
- If encrypt is enabled, it encrypts the configured AssetBundle.
- Set tags for configured AssetBundles.
- A list of composition strategies, strategies are always run in order.
- AssetBundle build list, AssetBundle build information that has been configured.
Default Composition Strategies
- 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
- Open TAssetBundle Settings File
- Remove build cache information for current platform
- Build Asset Bundle
- Run the composition strategy on all TAssetBundleManifest
- Clear AssetBundle build information for all TAssetBundleManifest using Composition Strategy
- Open Build Output Folder
- Open Download Cached Assets Folder
- Remove Download Cached Assets
- Open TAssetBundle Browser
- Open Tag Editor
- Open Web Server Test Window
- Open AssetBundle Dependency Checker
- 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
- Clear AssetBundle build information for all TAssetBundleManifest using Composition Strategy
- Run the composition strategy on all TAssetBundleManifest
- Build Asset Bundle
- Check dependencies between AssetBundles
- Total Asset Bundle Count
- A single AssetBundle build name and the assets it contains
- TAssetBundleManifest and file path
- Count of AssetBundles configured in TAssetBundleManifest
- Assets not yet configured as AssetBundle in TAssetBundleManifest
TAssetBundle Settings
All settings used by TAssetBundle
- The name of the catalog file generated when building the AssetBundle
- AssetBundle Build Output Folder Name
- Catalog file extension
- Asset Bundle file extension
- Enable catalog compression
- Enable catalog encryption
- encryption key
- Add the hash of the asset bundle file name
- Editor Play Mode (Editor Only)
- Forced in editor to use only remote AssetBundles. (Editor only)
- Maximum count of concurrent web requests
- Maximum count of web request retries
- Retry request wait duration
- Using the build cache only builds the AssetBundles that need to be built.
- Enable Debugging Log
- Include catalog in app
- How to embed AssetBundles into app
- Recompress the AssetBundles built-in in your app to lz4 (very efficient, but slightly increases file size).
- If enabled, the UnityRemoteAssetBundleProvider is used. When disabled, always uses a SpecificManagedAssetBundleProvider. SpecificManagedAssetBundleProvider are default used for crypto asset bundles.
- Set the custom catalog serializer
- Set the custom crypto serializer
- Set default remote url