AssetBundles.AssetBundleManager.LoadAssetAsync C# (CSharp) Method

LoadAssetAsync() public static method

public static LoadAssetAsync ( string assetBundleName, string assetName, System type ) : AssetBundleLoadAssetOperation
assetBundleName string
assetName string
type System
return AssetBundleLoadAssetOperation
        public static AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type)
        {
            Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle");

            AssetBundleLoadAssetOperation operation = null;
            #if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
                if (assetPaths.Length == 0)
                {
                    Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName);
                    return null;
                }

                // @TODO: Now we only get the main object from the first asset. Should consider type also.
                Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                operation = new AssetBundleLoadAssetOperationSimulation (target);
            }
            else
            #endif
            {
                assetBundleName = RemapVariantName (assetBundleName);
                LoadAssetBundle (assetBundleName);
                operation = new AssetBundleLoadAssetOperationFull (assetBundleName, assetName, type);

                m_InProgressOperations.Add (operation);
            }

            return operation;
        }

Usage Example

Beispiel #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	
		
	}
All Usage Examples Of AssetBundles.AssetBundleManager::LoadAssetAsync