internal void OnUnloadAssetBundles() { if (!Enter.bUsingAb) { return; } var dep = OnGetAssetBundleDependeces("ui/uiloading.ab").ToList(); dep.Add(UStaticFuncs.GetPlatformFolder(Application.platform)); var remove = new List <string>(); foreach (var d in dAssetBundles) { if (dep.Contains(d.Key)) { continue; } d.Value.Unload(true); remove.Add(d.Key); } foreach (var r in remove) { dAssetBundles.Remove(r); } }
private void InitRemoteConfig() { SetJindu("正在检查本地资源版本,请稍候"); AOutput.Log("InitRemoteConfig"); ConfigDownloader.Instance.StartToDownload(ConfigURL, () => { ParseConfigs(); if (UConfigManager.bUsingAb) { SetJindu("正在加载脚本资源......"); StartCoroutine(OnDownloadDll(ConfigDownloader.Instance.OnGetValue("dll"))); } else { SetJindu("正在加载脚本资源..."); LoadDll(File.ReadAllBytes("Assets/RemoteResources/Dll/ahotgames.bytes") , File.ReadAllBytes("Assets/RemoteResources/Dll/ahotgames.pdb")); } }, () => { SetJindu("正在加载本地资源,请稍候"); Debug.Log("下载远端配置文件失败,加载本地文件"); UConfigManager.bUsingAb = false; StartCoroutine(OnDownloadDll(UStaticFuncs.GetStreamAssetPath() + UStaticFuncs.GetPlatformFolder(Application.platform) + "/dll/ahotgames.ab")); }); }
public string[] OnGetAssetBundleDependeces(string name, List <string> dependens = null) { if (!dAssetBundles.ContainsKey(UStaticFuncs.GetPlatformFolder(Application.platform))) { return(new string[] { }); } if (manifestBundle == null) { manifestBundle = dAssetBundles[UStaticFuncs.GetPlatformFolder(Application.platform)]; } if (manifest == null) { manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest"); } var total = dependens; if (dependens != null) { foreach (var d in dependens) { if (!total.Contains(d)) { total.Add(d); } } } else { total = new List <string>(); } var result = manifest.GetAllDependencies(name); foreach (var d in result) { if (!total.Contains(d)) { total.Add(d); } } foreach (var r in result) { if (dependens != null && dependens.Contains(r)) { continue; } var deps = OnGetAssetBundleDependeces(r, total); foreach (var d in deps) { if (!total.Contains(d)) { total.Add(d); } } } return(total.ToArray()); }
private void Start() { ConfigDownloader.Instance.StartToDownload(ConfigURL, () => { ParseConfigs(); Debug.Log("UConfigManager.bUsingAb " + UConfigManager.bUsingAb); UAssetBundleDownloader.Instance.DownloadResources((l1) => { UAssetBundleDownloader.Instance.DownloadResources((l2) => { var dll = "Dll/AHotGames"; byte[] pdbBytes = null; #if UNITY_EDITOR if (!UConfigManager.bUsingAb) { dll += ".bytes"; } pdbBytes = System.IO.File.ReadAllBytes("Assets/RemoteResources/Dll/AHotGames.pdb"); #endif ILRuntimeHandler.Instance.DoLoadDll("ahotmages" , UAssetBundleDownloader.Instance.OnLoadAsset <TextAsset>(dll).bytes, pdbBytes); ILRuntimeHandler.Instance.SetUnityMessageReceiver(MonoInstancePool.getInstance <UEmitMessage>(true).gameObject); ILRuntimeHandler.Instance.OnLoadClass("AEntrance", new GameObject("AEntrance")); } , null, (arg) => { var preloads = ConfigDownloader.Instance.OnGetValue("preloads"); var lPreloads = preloads.Split(',').ToList(); foreach (var p in lPreloads) { if (arg.ToLower().StartsWith(p.ToLower())) { return(true); } } return(false); }); } , null, null, true, UStaticFuncs.GetPlatformFolder(Application.platform) , UStaticFuncs.GetPlatformFolder(Application.platform) + ".manifest"); }, () => { Debug.LogError("下载配置文件失败。"); }); }
public string OnGetValue(string skey) { if (dKeyValue.ContainsKey($"{skey}{UStaticFuncs.GetPlatformFolder(Application.platform)}{Utils_Plugins.Util_GetBundleVersion()}")) { return(dKeyValue[$"{skey}{UStaticFuncs.GetPlatformFolder(Application.platform)}{Utils_Plugins.Util_GetBundleVersion()}"]); } if (dKeyValue.ContainsKey($"{skey}{UStaticFuncs.GetPlatformFolder(Application.platform)}")) { return(dKeyValue[$"{skey}{UStaticFuncs.GetPlatformFolder(Application.platform)}"]); } if (dKeyValue.ContainsKey($"{skey}{Utils_Plugins.Util_GetBundleVersion()}")) { return(dKeyValue[$"{skey}{Utils_Plugins.Util_GetBundleVersion()}"]); } if (dKeyValue.ContainsKey(skey)) { return(dKeyValue[skey]); } return(""); }
private IEnumerator DoLoadFileList(string fileListName) { lfiles.Clear(); var www = new WWW(UStaticFuncs.GetStreamAssetPath() + UStaticFuncs.GetPlatformFolder(Application.platform) + "/" + fileListName); yield return(www); if (string.IsNullOrEmpty(www.error)) { var atext = www.text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var t in atext) { var fname = ""; var av = t.Split('|'); if (av.Length <= 2) { continue; } fname = av[0]; if (fname.StartsWith("/") || fname.StartsWith("\\")) { fname = fname.Substring(1); } fname = fname.Replace("\\", "/"); if (fname.EndsWith(".meta")) { continue; } lfiles.Add(fname); } totalCount = lfiles.Count; OnCopyFile(); } else { AOutput.Log("DoCopyFile failed:" + www.error + " for file " + www.url); actionOnComp?.Invoke(); } }
private IEnumerator DoCopyFile(string fname) { var www = new WWW(UStaticFuncs.GetStreamAssetPath() + UStaticFuncs.GetPlatformFolder(Application.platform) + "/" + fname); yield return(www); if (string.IsNullOrEmpty(www.error)) { var finfo = new FileInfo(UStaticFuncs.ConfigSaveDir + fname); if (!finfo.Directory.Exists) { finfo.Directory.Create(); } System.IO.File.WriteAllBytes(finfo.FullName, www.bytes); } else { AOutput.Log("DoCopyFile failed:" + www.error + " for file " + www.url); } AOutput.Log("正在释放资源,不消耗流量。"); OnCopyFile(); }
private void Start() { ConfigDownloader.Instance.StartToDownload(ConfigURL, () => { UAssetBundleDownloader.Instance.DownloadResources((l1) => { UAssetBundleDownloader.Instance.DownloadResources((l2) => { var dll = "Dll/AHotGames"; #if UNITY_EDITOR dll += ".bytes"; #endif ILRuntimeHandler.Instance.DoLoadDll("ahotmages", UAssetBundleDownloader.Instance.OnLoadAsset <TextAsset>(dll).bytes); ILRuntimeHandler.Instance.SetUnityMessageReceiver(MonoInstancePool.getInstance <UEmitMessage>(true).gameObject); ILRuntimeHandler.Instance.OnLoadClass("AEntrance", new GameObject("AEntrance")); } , null, (arg) => { return(arg.Contains("dll/")); }, true); } , null, null, true, UStaticFuncs.GetPlatformFolder(Application.platform) , UStaticFuncs.GetPlatformFolder(Application.platform) + ".manifest"); }, () => { Debug.LogError("下载配置文件失败。"); }); }
public AssetBundle OnGetAssetBundle(string assetBundlePath, bool NoDependences = false) { if (!assetBundlePath.EndsWith(AssetBundleSuffix)) { assetBundlePath += AssetBundleSuffix; } assetBundlePath = assetBundlePath.ToLower(); if (!NoDependences && dAssetBundles.ContainsKey(UStaticFuncs.GetPlatformFolder(Application.platform))) { if (manifestBundle == null) { manifestBundle = dAssetBundles[UStaticFuncs.GetPlatformFolder(Application.platform)]; } if (manifest == null) { manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest"); } } if (dAssetBundles.ContainsKey(assetBundlePath)) { return(dAssetBundles[assetBundlePath]); } return(DoGetAssetBundle(assetBundlePath)); }
public AssetBundle OnGetAssetBundle(string name, bool NoDependences = false) { name = name.ToLower(); if (!name.EndsWith(AssetBundleSuffix)) { name += AssetBundleSuffix; } if (!NoDependences && dAssetBundles.ContainsKey(UStaticFuncs.GetPlatformFolder(Application.platform))) { if (manifestBundle == null) { manifestBundle = dAssetBundles[UStaticFuncs.GetPlatformFolder(Application.platform)]; } if (manifest == null) { manifest = (AssetBundleManifest)manifestBundle.LoadAsset("AssetBundleManifest"); } } if (dAssetBundles.ContainsKey(name)) { return(dAssetBundles[name]); } return(null); }
private IEnumerator DoCheckRemoteVersion(Action <List <string> > downloadComplete, Action <int, int, float> downloadProgress, Func <string, bool> filter, bool NoDependeces, params string[] resources) { yield return(new WaitForEndOfFrame()); this.downloadComplete = downloadComplete; downloading = true; ResetDownloadStatus(); if (string.IsNullOrEmpty(UStaticFuncs.DownLoadConfigURL)) { Debug.Log("资源下载地址为空"); } else { Debug.Log("正在检查资源版本"); downloadingResources = resources.ToList(); if (!NoDependeces) { foreach (var r in resources) { var files = UAssetBundleDownloader.Instance.OnGetAssetBundleDependeces(r); foreach (var f in files) { if (downloadingResources.Contains(f)) { continue; } downloadingResources.Add(f); } } } var downloadedResources = new List <string>(); if (dFileRemoteVersions.Count == 0) { var url = UStaticFuncs.DownLoadConfigURL + "versions.txt?-" + ApiDateTime.Now.Ticks; if (UStaticFuncs.GetPlatformFolder(Application.platform) == UStaticFuncs.GetPlatformFolder(RuntimePlatform.WindowsPlayer)) { if (!url.Contains("://")) { url = "file://" + url; } } WWW www = new WWW(url); yield return(www); if (string.IsNullOrEmpty(www.error)) { var text = www.text; var atext = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var t in atext) { var name = ""; var av = t.Split('|'); if (av.Length < 3) { continue; } name = av[0]; if (name.StartsWith("/") || name.StartsWith("\\")) { name = name.Substring(1); } name = name.Replace("\\", "/"); var filecell = new RemoteFileCell(); filecell.version = av[1]; filecell.bytes = typeParser.Int64Parse(av[2]); if (dFileRemoteVersions.ContainsKey(name)) { dFileRemoteVersions[name] = filecell; } else { dFileRemoteVersions.Add(name, filecell); } } } else { Debug.Log("检查资源版本失败," + www.error); } } foreach (var rver in dFileRemoteVersions) { if (filter != null && filter(rver.Key)) { if (!downloadingResources.Contains(rver.Key)) { downloadingResources.Add(rver.Key); } if (!NoDependeces) { var files = OnGetAssetBundleDependeces(rver.Key); foreach (var f in files) { if (downloadingResources.Contains(f)) { continue; } downloadingResources.Add(f); } } } var remove = new List <string>(); foreach (var n in downloadingResources) { if (!dFileRemoteVersions.ContainsKey(n)) { remove.Add(n); } } foreach (var r in remove) { downloadingResources.Remove(r); } } foreach (var r in downloadingResources) { totalBytes += dFileRemoteVersions[r].bytes; } if (dFileRemoteVersions.Count != 0) { waitingForDownload = new List <string>(); waitingForDownload.AddRange(downloadingResources); if (downloadingResources.Count == 0) { OnDownloadComplete(waitingForDownload); } else { for (var i = 0; i < DownloadHandlerCount && i < downloadingResources.Count; i++) { StartToDownloadResources(downloadComplete, downloadProgress); } } } } }
private IEnumerator DoCheckRemoteVersion(Action <List <string> > downloadComplete, Action <int, int, float> downloadProgress, Func <string, bool> filter, bool NoDependeces, params string[] resources) { if (string.IsNullOrEmpty(UStaticFuncs.DownLoadConfigURL)) { Debug.Log("资源下载地址为空。"); } else { Debug.Log("正在检查资源版本"); var resourcesList = resources.ToList(); if (!NoDependeces) { foreach (var r in resources) { var files = UAssetBundleDownloader.Instance.OnGetAssetBundleDependeces(r); foreach (var f in files) { if (resourcesList.Contains(f)) { continue; } resourcesList.Add(f); } } } var downloadedResources = new List <string>(); if (dFileRemoteVersions.Count == 0) { var url = UStaticFuncs.DownLoadConfigURL + "versions.txt?" + ApiDateTime.Now.Ticks; if (UStaticFuncs.GetPlatformFolder(Application.platform) == UStaticFuncs.GetPlatformFolder(RuntimePlatform.WindowsPlayer)) { if (!url.Contains("://")) { url = "file://" + url; } } www = new WWW(url); yield return(www); if (string.IsNullOrEmpty(www.error)) { var text = www.text; var atext = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var t in atext) { var name = ""; var av = t.Split('|'); if (av.Length < 3) { Debug.LogError("remote version file check failed"); } name = av[0]; if (name.StartsWith("/") || name.StartsWith("\\")) { name = name.Substring(1); } name = name.Replace("\\", "/"); var filecell = new RemoteFileCell(); filecell.version = av[1]; filecell.bytes = typeParser.Int64Parse(av[2]); if (dFileRemoteVersions.ContainsKey(name)) { dFileRemoteVersions[name] = filecell; } else { dFileRemoteVersions.Add(name, filecell); } } } else { Debug.Log("检查资源版本失败," + www.error); } } foreach (var rver in dFileRemoteVersions) { if (filter != null && filter(rver.Key)) { if (!resourcesList.Contains(rver.Key)) { resourcesList.Add(rver.Key); } if (!NoDependeces) { var files = OnGetAssetBundleDependeces(rver.Key); foreach (var f in files) { if (resourcesList.Contains(f)) { continue; } resourcesList.Add(f); } } } var remove = new List <string>(); foreach (var n in resourcesList) { if (dAssetBundles.ContainsKey(n) || !dFileRemoteVersions.ContainsKey(n)) { remove.Add(n); } } foreach (var r in remove) { resourcesList.Remove(r); } } totalBytes = 0; foreach (var r in resourcesList) { totalBytes += dFileRemoteVersions[r].bytes; } if (dFileRemoteVersions.Count != 0) { if (resourcesList.Count == 0) { downloadComplete?.Invoke(resourcesList); } else { StartToDownloadResources(downloadComplete, downloadProgress, downloadedResources, resourcesList); #if UNITY_IOS || UNITY_EDITOR StartCoroutine(DelayUpdateProgress(downloadProgress, downloadedResources, resourcesList)); #endif } } } }