LoadAssetAsync() public static method

public static LoadAssetAsync ( string assetBundleName, string assetName, System type ) : AssetBundleLoadAssetOperation
assetBundleName string
assetName string
type System
return AssetBundleLoadAssetOperation
示例#1
0
	protected virtual IEnumerator LoadAssetAsync_Callback (string assetBundleName
			, string assetName 
			, System.Action<UnityEngine.Object> _CallbackFunc )
	{
#if ENABLE_NDINFRA_EXAMPLE_LOG
		// This is simply to get the elapsed time for this phase of AssetLoading.
		float start = Time.realtimeSinceStartup;
#endif

		// Load asset from assetBundle.
		var request = 
			AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(UnityEngine.Object) );
		if (request == null)
		{
			onError("assetBundleName is missing." , assetBundleName ) ;
			yield break;
		}
		
		yield return StartCoroutine(request);
		
		// Get the asset.
		var assetObject = request.GetAsset<UnityEngine.Object> ();
		
		_CallbackFunc( assetObject ) ;

#if ENABLE_NDINFRA_EXAMPLE_LOG
		LogFinishTime( "Assets " + assetBundleName + (null == assetObject ? " was not" : " was") + " loaded successfully " , string.Empty , start ) ;
#endif // ENABLE_NDINFRA_EXAMPLE_LOG	
		
	}
        public static IObservable <T> LoadAssetBundle <T>(AssetBundleStruct assetBundleStruct,
                                                          IProgress <float> progress = null)
            where T : UnityEngine.Object
        {
            var request = AssetBundleManager.LoadAssetAsync <T>(
                assetBundleStruct.AssetBundlePath, assetBundleStruct.AssetName);

            return(Observable.FromCoroutine <T>((observer, cancellation) => FetchAssetBundle(request, observer, progress, cancellation)));
        }
示例#3
0
 public static bool LoadAssetAsyncCallback <T>(string assetBundleName, string assetName, Func <T, bool> onAssetLoaded) where T : UnityEngine.Object
 {
     AssetBundleManager.Initialize();
     if (AssetBundleManager.m_Instance)
     {
         if (string.IsNullOrEmpty(assetBundleName) || string.IsNullOrEmpty(assetName))
         {
             Debug.LogError("## Empty bundle or asset name: assetBundleName=" + assetBundleName + ", assetName=" + assetName);
             return(false);
         }
         AssetBundleLoadAssetOperation assetBundleLoadAssetOperation = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(T));
         if (assetBundleLoadAssetOperation != null)
         {
             if (!AssetBundleManager.m_PendingRoutines.ContainsKey(onAssetLoaded))
             {
                 Coroutine value = AssetBundleManager.m_Instance.StartCoroutine(AssetBundleManager.LoadAssetAsyncCallbackRoutine <T>(assetBundleName, assetBundleLoadAssetOperation, onAssetLoaded));
                 AssetBundleManager.m_PendingRoutines.Add(onAssetLoaded, value);
             }
             return(true);
         }
     }
     return(false);
 }