/// <summary> /// Starts a load operation for an asset from the given asset bundle. /// </summary> public static AssetLoadOperation LoadAssetAsync(string name) { if (string.IsNullOrEmpty(name)) { return(null); } if (enableLog && (!Level.loading || enableLoadingLog)) { Logger.LogDetail("AssetManager: Loading asset bundle {0}", name); } AssetLoadOperation operation = null; #if UNITY_EDITOR if (simulateMode) { var assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(name); if (assetPaths.Length == 0) { Logger.LogError("There is no asset bundle with name \"{0}\".", name); return(null); } var target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); operation = new AssetLoadOperation(name, target); operation.Complete(); instance.ProcessSimulateOperation(operation); } else #endif { operation = m_operations.Find(op => op.name == name); if (operation != null) { operation.refCount++; } else { operation = new AssetLoadOperation(name, m_serverUrl, LoadType.Load); _AddOperation(operation); } } return(operation); }
/// <summary> /// Starts a load operation for an asset from the given asset bundle and asset name. /// </summary> public static AssetLoadOperation LoadAssetAsync(string name, string assetName, Type type) { if (string.IsNullOrEmpty(name)) { return(null); } if (enableLog && (!Level.loading || enableLoadingLog)) { Logger.LogDetail("AssetManager: Loading {0} [{1}] from bundle {2}", string.IsNullOrEmpty(assetName) ? "all" : assetName, type.Name, name); } AssetLoadOperation operation = null; #if UNITY_EDITOR if (simulateMode) { var assetPaths = string.IsNullOrEmpty(assetName) ? AssetDatabase.GetAssetPathsFromAssetBundle(name) : AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(name, assetName); if (!string.IsNullOrEmpty(assetName)) { var target = assetPaths.Length < 1 ? null : AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); if (!target || target.GetType() != type && !target.GetType().IsSubclassOf(type)) { Logger.LogError("There is no asset with name \"{0}\" in {1} matche type {2}", assetName, name, type); return(null); } operation = new AssetLoadOperation(name, target); operation.Complete(); instance.ProcessSimulateOperation(operation); } else { var targets = new Object[assetPaths.Length]; for (var i = 0; i < assetPaths.Length; ++i) { targets[i] = AssetDatabase.LoadMainAssetAtPath(assetPaths[i]); } if (targets.Length < 1) { Logger.LogError("Load asset {0} failed, bundle is empty", name); return(null); } operation = new AssetLoadOperation(name, targets); operation.Complete(); instance.ProcessSimulateOperation(operation); } } else #endif { operation = m_operations.Find(op => op.name == name); if (operation != null) { operation.refCount++; } else { operation = new AssetLoadOperation(name, m_serverUrl, assetName, type); _AddOperation(operation); } } return(operation); }