本文整理汇总了C#中UnityEngine.AssetBundle.LoadAsync方法的典型用法代码示例。如果您正苦于以下问题:C# AssetBundle.LoadAsync方法的具体用法?C# AssetBundle.LoadAsync怎么用?C# AssetBundle.LoadAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.AssetBundle
的用法示例。
在下文中一共展示了AssetBundle.LoadAsync方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnAssetBundleLoaded
void OnAssetBundleLoaded(string url, AssetBundle assetBundle, params object[] args)
{
Object asset = null;
System.DateTime beginTime = System.DateTime.Now;
if (AssetInBundleName == null)
{
// 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化
try
{
asset = assetBundle.mainAsset;
}
catch
{
CBase.LogError("[OnAssetBundleLoaded:mainAsset]{0}", url);
}
}
else
{
AssetBundleRequest request = assetBundle.LoadAsync(AssetInBundleName, typeof(Object));
asset = request.asset;
}
CResourceManager.LogLoadTime("AssetFileBridge", url, beginTime);
if (asset == null)
{
CBase.LogError("Asset is NULL: {0}", url);
}
AssetFileLoadedCallback(asset, CallbackArgs);
}
示例2: BundleLoadedHandler
private void BundleLoadedHandler(WWW request)
{
Debug.Log("Bundle loaded: " + request.url);
_bundle = request.assetBundle;
AssetBundleRequest assetBundleRequest = _bundle.LoadAsync(AssetName, typeof(GameObject));
_assetBundleQueue.Send(assetBundleRequest, AssetLoadedHandler);
}
示例3: GoLoader
/// <summary>
/// Begin load
/// </summary>
/// <param name="asset"></param>
/// <param name="resName"></param>
/// <returns></returns>
public IEnumerator GoLoader(AssetBundle asset, string resName)
{
this.m_cRequest = asset.LoadAsync(resName, typeof(UnityEngine.Object));
for (; !this.m_cRequest.isDone; )
yield return this.m_cRequest;
GameObject.Destroy(this.gameObject);
}
示例4: OnGUI
// ReSharper restore InconsistentNaming
// ReSharper restore UnusedMember.Local
// ReSharper disable UnusedMember.Local
// ReSharper disable InconsistentNaming
void OnGUI()
{
// classic OnGUI
GUI.depth = 0;
if (GUI.Button(new Rect(10, 10, 100, 50), _progress == 0 ? "Load" : "Loading: " + _progress + "%"))
{
// reset queues
_bundleQueue.Reset();
_assetBundleQueue.Reset();
// destroy old object
if (null != _object)
Destroy(_object);
// unload old bundle
if (null != _bundle)
_bundle.Unload(true);
// load bundle
_bundleQueue.Send(new WWW(BundleUrl),
delegate(WWW request)
{
Debug.Log("Bundle loaded: " + request.url);
_bundle = request.assetBundle;
AssetBundleRequest assetBundleRequest = _bundle.LoadAsync(AssetName, typeof(GameObject));
_assetBundleQueue.Send(assetBundleRequest,
delegate(AssetBundleRequest request2)
{
Debug.Log("Asset loaded: " + request2.asset.name);
_object = (GameObject)Instantiate(request2.asset);
// add mouse orbit
GameObject cameraGo = GameObject.Find("Main Camera");
if (null != cameraGo)
{
MouseOrbitCs mouseOrbit = cameraGo.AddComponent<MouseOrbitCs>();
mouseOrbit.Target = _object.transform;
}
}
);
}
);
}
}
示例5: GoLoader
//Begin to load
private IEnumerator GoLoader(AssetBundle asset, string resName , FINISH_CALLBACK finish_callback)
{
this.m_delFinishCallback = finish_callback;
this.m_fProgress = 0;
this.m_cRequest = asset.LoadAsync(resName, typeof(UnityEngine.Object));
for (; !this.m_cRequest.isDone; )
{
this.m_fProgress = this.m_cRequest.progress;
yield return new WaitForEndOfFrame();
}
this.m_fProgress = 1;
if(this.m_delFinishCallback != null)
{
this.m_delFinishCallback(resName , this.m_cRequest.asset);
}
GameObject.Destroy(this.gameObject);
}
示例6: AsyncLoadAsset
static IEnumerator AsyncLoadAsset(AssetBundle bundle, Action<UnityObject> onFinish, String path)
{
if (EnablePauseFlag)
{
if (path.EndsWith(".png.u3dext") || path.EndsWith(".tga.u3dext") || path.EndsWith(".bytes.u3dext") || path.EndsWith(".mp3.u3dext"))
{
while (GetPauseFlag())
yield return null;
Debug.LogWarning(path);
EntryPoint.DebugString = path;
}
}
////checkres(path, typeof(Texture), 0);
CheckDependBundlesInCache(path);
AssetBundleRequest request = bundle.LoadAsync("1", typeof(UnityObject));
if (request == null)
{
Debug.LogWarning("Failed to LoadAsync with name '1' from: " + path);
if (onFinish != null)
onFinish(null);
yield break;
}
while (!request.isDone)
yield return null;
UnityObject asset = request.asset;
if (asset == null)
Debug.LogWarning("LoadAsync with name '1' return null:" + path);
if (m_bEnableLog)
Log("AsyncLoadAsset finish: " + path + "@ " + Time.realtimeSinceStartup);
if (onFinish != null)
onFinish(asset);
}
示例7: NewLoadBGElement
private IEnumerator NewLoadBGElement ()
{
string path = Application.dataPath + "/Bundle/BGElement";
AssetBundle ab = new AssetBundle ();
AssetBundleRequest abr = ab.LoadAsync (path, typeof(GameObject));
yield return abr;
GameObject newCube = Instantiate (abr.asset) as GameObject;
}
示例8: LoadAssetsFromBundleAsync
public IEnumerator LoadAssetsFromBundleAsync(AssetBundle bundle, string[] names)
{
objects = new List<Object>();
foreach (var name in names)
{
AssetBundleRequest request = bundle.LoadAsync(name, typeof(UnityEngine.Object));
yield return request;
UnityEngine.Object obj = request.asset;
TryAddAsset(name, obj, objects);
}
}
示例9: LoadAssetsFromBundleSimultaneouslyAsync
public IEnumerator LoadAssetsFromBundleSimultaneouslyAsync(AssetBundle bundle, string[] names, int nAssets)
{
objects = new List<Object>();
List<AssetBundleRequest> requests = new List<AssetBundleRequest>();
for (int i = 0; i < names.Length; i++)
{
string name = names[i];
requests.Add(bundle.LoadAsync(name, typeof(Object)));
if (requests.Count == nAssets || i == names.Length - 1)
{
while (!AreAssetsLoaded(requests))
{
yield return null;
}
foreach (var request in requests)
{
Object obj = request.asset;
TryAddAsset(obj.name, obj, objects);
}
Debug.Log("Loaded " + requests.Count + " assets from the bundle");
requests = new List<AssetBundleRequest>();
}
}
}
示例10: AyncLoadAsset
static IEnumerator AyncLoadAsset(AssetBundle bundle, Action<UnityObject> onFinish, String path)
{
CheckDependBundlesInCache(path);
AssetBundleRequest request = bundle.LoadAsync("1", typeof(UnityObject));
if (request == null)
{
if (onFinish != null)
onFinish(null);
yield break;
}
while (!request.isDone)
yield return null;
if (onFinish != null)
onFinish(request.asset);
}
示例11: ProcessAssetBundle
/// <summary>
/// In this function we can do whatever we want with the freshly downloaded bundle.
/// In this example we will cache it for later use, and we will load a texture from it.
/// </summary>
IEnumerator ProcessAssetBundle(AssetBundle bundle)
{
if (bundle == null)
yield break;
// Save the bundle for future use
cachedBundle = bundle;
// Start loading the asset from the bundle
var asyncAsset =
#if UNITY_5
cachedBundle.LoadAssetAsync("9443182_orig", typeof(Texture2D));
#else
cachedBundle.LoadAsync("9443182_orig", typeof(Texture2D));
#endif
// wait til load
yield return asyncAsset;
// get the texture
texture = asyncAsset.asset as Texture2D;
}