private void anlyzeOp() { deeply = GUILayout.Toggle(deeply, "是否深度分析(加载包内资源对象)?"); if (GUILayout.Button("analyze", GUILayout.Width(100))) { listFiles.Clear(); statistics.Clear(); foreach (KeyValuePair <string, string> item in srcFolder2destFolderPC) { string srcFilePath = (string)item.Key; DirectoryInfo di = new DirectoryInfo(srcFilePath); foreach (FileInfo fi in di.GetFiles()) { if (!IsOKSuffix(Path.GetExtension(fi.FullName))) { continue; } listFiles.Enqueue(fi.FullName); } } progress = 0; secs = listFiles.Count; int count = 0; while (listFiles.Count > 0) { string filename = listFiles.Dequeue(); progress++; if (EditorUtility.DisplayCancelableProgressBar("AssetBundle加载进度窗口 " + progress.ToString() + "/" + secs.ToString(), "当前加载: " + Path.GetFileName(filename), (float)progress / (float)secs)) { EditorUtility.ClearProgressBar(); break; } StatErrorData data = analyzeAssetBundle(filename); statistics.Add(data); if (data.errortext != "no error") { count++; } } EditorUtility.ClearProgressBar(); EditorUtility.DisplayDialog("Assetbundle统计结果", "Error Count = " + count.ToString(), "关闭"); } }
private StatErrorData analyzeAssetBundle(string assetPath) { if (!IsOKSuffix(Path.GetExtension(assetPath))) { return(null); } StatErrorData data = new StatErrorData(); data.filename = assetPath; WWW www = null; try { string escName = WWW.EscapeURL("file:///" + assetPath); Debug.Log(escName); LogData = data; Application.RegisterLogCallback(HandleLog); www = new WWW("file:///" + assetPath); //WWW www = WWW.LoadFromCacheOrDownload("file:///" + assetPath, 0); if (!string.IsNullOrEmpty(www.error)) { data.errortext = www.error; } else { data.errortext = "no error"; if (deeply && www.assetBundle != null) { Object[] loadedObjects = www.assetBundle.LoadAllAssets(); if (loadedObjects == null) { data.errortext = "all = null"; } if (!string.IsNullOrEmpty(www.error)) { data.errortext = www.error; } } } } catch (System.Exception e) { data.errortext = e.Message; } if (www.assetBundle != null) { www.assetBundle.Unload(true); } www.Dispose(); Application.RegisterLogCallback(null); LogData = null; return(data); }
private StatErrorData analyzeAssetBundle(string assetPath) { if (!IsOKSuffix(Path.GetExtension(assetPath))) return null; StatErrorData data = new StatErrorData(); data.filename = assetPath; WWW www = null; try { string escName = WWW.EscapeURL("file:///" + assetPath); Debug.Log(escName); LogData = data; Application.RegisterLogCallback(HandleLog); www = new WWW("file:///" + assetPath); //WWW www = WWW.LoadFromCacheOrDownload("file:///" + assetPath, 0); if (!string.IsNullOrEmpty(www.error)) { data.errortext = www.error; } else { data.errortext = "no error"; if (deeply && www.assetBundle != null) { Object[] loadedObjects = www.assetBundle.LoadAll(); if (loadedObjects == null) data.errortext = "all = null"; if (!string.IsNullOrEmpty(www.error)) { data.errortext = www.error; } } } } catch (System.Exception e) { data.errortext = e.Message; } if (www.assetBundle != null) www.assetBundle.Unload(true); www.Dispose(); Application.RegisterLogCallback(null); LogData = null; return data; }