public Object LoadRes(string fullPath, System.Type type, GameResLoadMode resLoadMode) { if (!fullPath.Contains(INSTANCE.defaultResFolder) && !fullPath.Contains("Assets/")) { fullPath = string.Format("{0}/{1}", INSTANCE.defaultResFolder, fullPath); } resLoadMode = resLoadMode == GameResLoadMode.None ? actualLoadMode : resLoadMode; #if UNITY_EDITOR if (resLoadMode == GameResLoadMode.Direct || resLoadMode == GameResLoadMode.None) { return(UnityEditor.AssetDatabase.LoadAssetAtPath(fullPath, type)); } #endif var bundle = GetResAssetBundle(fullPath); if (bundle == null) { return(null); } return(bundle.LoadAsset(fullPath, type)); }
public void LoadBundles(string manifestName, List <string> bundleList, Dictionary <string, List <string> > resUrls, Dictionary <string, string> resHashes, System.Action <bool> onLoadDone = null, GameResLoadMode resLoadMode = GameResLoadMode.None) { resLoadMode = resLoadMode == GameResLoadMode.None ? actualLoadMode : resLoadMode; if (resLoadMode == GameResLoadMode.Direct) { if (onLoadDone != null) { onLoadDone(true); } return; } if (bundleList.Count == 0) { if (onLoadDone != null) { onLoadDone(true); } return; } var bundleName = bundleList[0]; bundleList.RemoveAt(0); var hash = (resHashes != null && resHashes.ContainsKey(bundleName)) ? resHashes[bundleName] : GameBundleSetting.INSTANCE.GetBundleHash(bundleName, manifestName); var urls = (resUrls != null && resUrls.ContainsKey(bundleName)) ? resUrls[bundleName].ToArray() : new string[] { bundleName }; GameResLoader.INSTANCE.LoadAssetBundle(bundleName, manifestName, hash, urls, GameBundleSetting.INSTANCE.IsBundleSameHash(hash, bundleName, manifestName), (result) => { if (!result) { if (onLoadDone != null) { onLoadDone(false); } return; } LoadBundles(manifestName, bundleList, resUrls, resHashes, onLoadDone, resLoadMode); }, resLoadMode); }
public void LoadManifestBundles(string manifestName, string manifestHash, string[] manifestUrls, Dictionary <string, string> resHashes, Dictionary <string, List <string> > resUrls, System.Action <bool> onLoadDone = null, GameResLoadMode resLoadMode = GameResLoadMode.None) { resLoadMode = resLoadMode == GameResLoadMode.None ? actualLoadMode : resLoadMode; if (resLoadMode == GameResLoadMode.Direct) { if (onLoadDone != null) { onLoadDone(true); } return; } manifestHash = string.IsNullOrEmpty(manifestHash) ? GameBundleSetting.INSTANCE.GetBundleHash(manifestName, manifestName) : manifestHash; manifestUrls = (manifestUrls == null || manifestUrls.Length == 0) ? new string[] { manifestName } : manifestUrls; GameResLoader.INSTANCE.LoadManifest(manifestName, manifestHash, manifestUrls, GameBundleSetting.INSTANCE.IsBundleSameHash(manifestHash, manifestName, manifestName), (result, bundleNames) => { if (!result || bundleNames == null) { if (onLoadDone != null) { onLoadDone(result); } return; } var bundleList = bundleNames.ToList <string>(); LoadBundles(manifestName, bundleList, resUrls, resHashes, (_result) => { if (!_result) { if (onLoadDone != null) { onLoadDone(false); } return; } if (onLoadDone != null) { onLoadDone(true); } }); }, resLoadMode); }
private IEnumerator _LoadManifestBundles(string manifestName, string manifestHash, string[] manifestUrls, Dictionary <string, string> resHashes, Dictionary <string, List <string> > resUrls, System.Action onLoadDone = null, GameResLoadMode resLoadMode = GameResLoadMode.None) { bool isLoadDone = false; LoadManifestBundles(manifestName, manifestHash, manifestUrls, resHashes, resUrls, (result) => { if (onLoadDone != null) { onLoadDone(); } isLoadDone = true; }); while (!isLoadDone) { yield return(null); } }
public Coroutine CoroutineLoadManifestBundles(string manifestName, string manifestHash, string[] manifestUrls, Dictionary <string, string> resHashes, Dictionary <string, List <string> > resUrls, System.Action onLoadDone = null, GameResLoadMode resLoadMode = GameResLoadMode.None) { return(StartCoroutine(_LoadManifestBundles(manifestName, manifestHash, manifestUrls, resHashes, resUrls, onLoadDone, resLoadMode))); }
public void LoadResAsync(string fullPath, System.Type type, System.Action <Object> onLoadDone, GameResLoadMode resLoadMode) { if (!fullPath.Contains(INSTANCE.defaultResFolder) && !fullPath.Contains("Assets/")) { fullPath = string.Format("{0}/{1}", INSTANCE.defaultResFolder, fullPath); } resLoadMode = resLoadMode == GameResLoadMode.None ? actualLoadMode : resLoadMode; #if UNITY_EDITOR if (resLoadMode == GameResLoadMode.Direct || resLoadMode == GameResLoadMode.None) { onLoadDone(LoadRes(fullPath, type)); return; } #endif var bundle = GetResAssetBundle(fullPath); if (bundle == null) { onLoadDone(null); return; } StartCoroutine(_LoadResAsync(bundle, fullPath, type, onLoadDone)); }
public T LoadRes <T>(string fullPath, GameResLoadMode resLoadMode) where T : Object { return(LoadRes(fullPath, typeof(T), resLoadMode) as T); }
public void LoadAssetBundle(string bundleName, string manifestName, string hash, string[] urls, bool isLoadFromPackage, System.Action <bool> onLoadDone, GameResLoadMode resLoadMode) { if (string.IsNullOrEmpty(hash)) { onLoadDone(false); return; } if (hash == GetAssetBundleHash(bundleName, manifestName)) { // 已加载相同Hash的,无需再加载 onLoadDone(true); return; } // 已加载不同Hash的,先卸载 UnLoadAssetBundle(bundleName, manifestName); if (!_allAssetBundleMap.ContainsKey(manifestName)) { _allAssetBundleMap.Add(manifestName, new Dictionary <string, GameResAssetBundle>()); } var bundleGroupMap = _allAssetBundleMap[manifestName]; resLoadMode = resLoadMode == GameResLoadMode.None ? actualLoadMode : resLoadMode; switch (resLoadMode) { #if UNITY_EDITOR case GameResLoadMode.None: case GameResLoadMode.Direct: { // 无需加载AssetBundle,直接通过AssetDatabase加载 onLoadDone(true); return; } break; case GameResLoadMode.LocalSimulation: { // 从Output中加载 var buildTarget = UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString(); var project = Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length); var fullPath = string.Format(project + defaultOutputFolder + "/{0}/{1}/{2}", manifestName, buildTarget, bundleName); if (File.Exists(fullPath)) { StartCoroutine(LoadAssetBundleFromFile(bundleGroupMap, bundleName, manifestName, hash, fullPath, onLoadDone)); return; } } break; #endif case GameResLoadMode.Release: { if (isLoadFromPackage) { // 从包体加载 var fullPath = Application.streamingAssetsPath + "/" + bundleName; StartCoroutine(LoadAssetBundleFromFile(bundleGroupMap, bundleName, manifestName, hash, fullPath, onLoadDone)); return; } else { // 从Cache中加载 StartCoroutine(LoadAssetBundleFromCache(bundleGroupMap, bundleName, manifestName, hash, urls, onLoadDone)); return; } } break; } onLoadDone(IsAssetBundleLoaded(bundleName, manifestName)); }
public void LoadManifest(string manifestName, string hash, string[] urls, bool isLoadFromPackage, System.Action <bool, string[]> onLoadDone, GameResLoadMode resLoadMode) { resLoadMode = resLoadMode == GameResLoadMode.None ? actualLoadMode : resLoadMode; #if UNITY_EDITOR if (resLoadMode == GameResLoadMode.Direct || resLoadMode == GameResLoadMode.None) { onLoadDone(true, null); return; } #endif LoadAssetBundle(manifestName, manifestName, hash, urls, isLoadFromPackage, (result) => { if (!result) { UnLoadAssetBundle(manifestName, manifestName); onLoadDone(false, null); return; } var manifestBundle = GetAssetBundle(manifestName, manifestName); if (manifestBundle == null) { UnLoadAssetBundle(manifestName, manifestName); onLoadDone(false, null); return; } var manifest = manifestBundle.LoadAsset("assetbundlemanifest", typeof(AssetBundleManifest)) as AssetBundleManifest; if (manifest == null) { UnLoadAssetBundle(manifestName, manifestName); onLoadDone(false, null); return; } var allAssetBundles = manifest.GetAllAssetBundles(); UnLoadAssetBundle(manifestName, manifestName); onLoadDone(true, allAssetBundles); }, resLoadMode); }