CAssetBundleMgr

class CAssetBundleMgr

You need to add this script by AddComponent in “Awake” method of CMainSystem.

This is the manager to cache or load the assetbundles.

When you prepare your own manager , it is unnecessary.

First ,for get the version of each asset , this script downloads the version.unity3d.

if the versions are different ,this script discards old cached data.

To have the following characteristics .

  1. Asset bundles are version control.This script does not download assetbundles if same assetbundle downloaded in the past(WWW.LoadFromCacheOrDownload).

  2. The loaded asset bundles are cached in memory.

  3. It releases the cache at the scene switching .

  4. It is possible to put a resident flag in assetbundles. These are not released at the scene switching.

  5. Possible to switch the load path in the configuration file on the MS-Windows and the Mac ( local files without using the HTTP server can also be loaded)

  6. The name’s format of the assetbundle is MulID .unity3d.

const Int32 MaxConcurrentLoadNum { get; set; }

This value means the maximum number that this script can download at the same time.

In other words,the number of a LoadFromCacheOrDownload calling can not exceed this maximum value.

The default value is to 1.

const Int64 MaximumAvailableDiskSpace { get; }

It sets the maximum cache size of a local disk.

The default value is set to 512 * 1024 * 1024 (512Mbyte).

static String httpServerPath { get; set; }

It sets the HTTP address.

static String debugPath { get; set; }

It sets the debug path . It is effective only in MS-Windows / Mac environment .This manager preferentially loads assetbundles via this path.

Note

A file that was loaded via the debug path does not perform the cache to the local disk.

Int32 lastError { get; }

It has the error number

Int32 errorMessage { get; }

It has the error message

CAssetBundle[] lodings

This returns a list of asset bundles currently being downloaded .

This list includes what the manager deferred assetbundle downloads.

Int32 loadNum { get; }

It has a number of asset bundle currently being downloaded .

This number includes what the manager deferred assetbundle downloads.

static CAssetBundleMgr Instance { get; }

It has an instance of a manager

CAssetBundle reference (UInt32 id)

It references a assetbundle. If you have not cache it , the manager downloads it .

If it was already downloaded, it returns the existing CAssetBundle.

Whether CAssetBundle was downloaded, it is possible to determine by CAssetBundle.isLoaded.

if it returns true,the asset is already loaded.

When null is returned , it is not exist.

Boolean isExist (UInt32 id)

It examines whether the asset bundle exist .

void startPreload ()

You need to call this function if you want to download all asset bundles that exist in order to cache on the local disk.

void loadAssetVersion ()

Asset version (version.unity3d) to download and again , and updates the cache of asset bundle.

void releaseAll ()

It releases all asset bundle regardless of the resident / non-resident .

After the release , you must call the loadAssetVersion.

class CAssetBundle

It can be cast in AssetBundle.

AssetBundle get ()

Get the AssetBundle.

UInt32 id { get; }

It has the ID.

Boolean isLoaded { get; }

if it is already loaded,this value sets to true.

You can see whether it is resident .

How to change a path to load local files.

It is only valid on Windows / Mac.

You make the following files in the same location as the Assets folder.

  • config.cf

  • config.local.cf

_images/configpath.png

The loading order is config.cf → config.local.cf.

“config.cf” is overwritten by “config.local.cf”.

It is described as follows in config.cf

#
# config.cf
#
DEBUG_PATH = ../../../unified/AssetBuilder/assetbundles/Windows

In the Awake of CMainSystem, set as follows .

//==========================================================================
/*!Awake
* @brief    Unity Callback
*/
new void Awake() {
     base.Awake();
     if (m_instance != null) {
         Debug.LogError("already exist CMainSystem");
         return;
     }
     m_instance = this;
     #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_WEBPLAYER)
         CAssetBundleMgr.debugPath = CConfig.Instance.get ("DEBUG_PATH","../Debug/");
     #endif
     if (KsSoftConfig.UseAssetBundle) {
             gameObject.AddComponent<CAssetBundleMgr>();
         }