private void CompareFile() { string fileFolder = AssetBundleUtility.GetFileFolder(); if (!Directory.Exists(fileFolder)) { return; } DirectoryInfo directoryInfo = new DirectoryInfo(fileFolder); FileInfo[] fileInfos = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories); foreach (FileInfo paramInfo in fileInfos) { string filePath = paramInfo.FullName.Replace("\\", "/"); if (filePath == AssetBundleUtility.GetFileFolder() + "/" + AssetBundleUtility.fileName) { continue; } string md5 = AssetBundleUtility.GetMd5(filePath); if (newDic.ContainsKey(md5)) { newDic.Remove(md5);//don't need update } else { File.Delete(filePath);//clean old file } } }
private static void GenerateFileInfo(string param) { string fileFolder = param; DirectoryInfo directoryInfo = new DirectoryInfo(fileFolder); string fileInfoPath = fileFolder + "/" + AssetBundleUtility.fileName; FileInfo[] fileInfos = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories); FileStream stream = new FileStream(fileInfoPath, FileMode.CreateNew); StreamWriter writer = new StreamWriter(stream); float total, processed = 0; total = fileInfos.Length; foreach (FileInfo paramFileInfo in fileInfos) { processed++; EditorUtility.DisplayProgressBar(AssetBundleUtility.fileName, "Progress", processed / total); string fileInfo = paramFileInfo.FullName; if (fileInfo.EndsWith(".meta")) { continue; } long length = paramFileInfo.Length; string md5 = AssetBundleUtility.GetMd5(fileInfo); fileInfo = fileInfo.Replace("\\", "/"); fileInfo = fileInfo.Replace(fileFolder + "/", string.Empty); writer.WriteLine(md5 + "|" + fileInfo + "|" + length); } EditorUtility.ClearProgressBar(); writer.Close(); stream.Close(); }
void GetFile() { progress = (float)index / lines.Length; if (lines.Length > index) { if (string.IsNullOrEmpty(lines[index])) { index++; GetFile(); } else { string[] keyValue = lines[index].Split('|'); string fileName = keyValue[1].Trim(); string filePath = AssetBundleUtility.fileFolderName + "/" + fileName; fileOutPutPath = AssetBundleUtility.GetFileFolder() + "/" + fileName; IOManager.Instance.ReadFileFromStreamingAssetsPath(filePath, GetFileFinish); } } else { string path = AssetBundleUtility.fileFolderName + "/" + AssetBundleUtility.fileName; IOManager.Instance.WriteFileToPersistentDataPath(path, fileInfoBytes); handler(); } }
public static AssetBundle GetAssetBundle(string paramName) { if (assetBundleDependencies.ContainsKey(paramName)) { string[] dependenceNames = assetBundleDependencies[paramName]; foreach (string paramdependenceName in dependenceNames) { if (loadedAssetBundles.ContainsKey(paramdependenceName)) { loadedAssetBundles[paramdependenceName].dependenceCount++; } else { string path = AssetBundleUtility.GetAssetBundleFolder() + "/" + paramdependenceName; if (File.Exists(path)) { #if UNITY_5_3 || UNITY_5_3_OR_NEWER AssetBundle ab = AssetBundle.LoadFromFile(path); #else AssetBundle ab = AssetBundle.CreateFromFile(path); #endif LoadedAssetBundle loadedAssetBundle = new LoadedAssetBundle(ab); loadedAssetBundles.Add(paramdependenceName, loadedAssetBundle); } else { Debug.LogError("can't find ab file"); } //AssetBundle ab = AssetBundle.LoadFromFile(path); //LoadedAssetBundle loadedAssetBundle = new LoadedAssetBundle(ab); //loadedAssetBundles.Add(paramdependenceName, loadedAssetBundle); } } } if (loadedAssetBundles.ContainsKey(paramName)) { loadedAssetBundles[paramName].dependenceCount++; return(loadedAssetBundles[paramName].assetBundle); } { string assetBundlePath = AssetBundleUtility.GetAssetBundleFolder() + "/" + paramName; if (!File.Exists(assetBundlePath)) { Debug.LogError("file not exist"); return(null); } #if UNITY_5_3 || UNITY_5_3_OR_NEWER AssetBundle assetBundle = AssetBundle.LoadFromFile(assetBundlePath); #else AssetBundle assetBundle = AssetBundle.CreateFromFile(assetBundlePath); #endif LoadedAssetBundle loadedAssetBundle = new LoadedAssetBundle(assetBundle); loadedAssetBundles.Add(paramName, loadedAssetBundle); return(loadedAssetBundles[paramName].assetBundle); } }
public static void Clean() { string path = AssetBundleUtility.GetFileFolder(); if (Directory.Exists(path)) { Directory.Delete(path, true); } Debug.Log("clean finish"); }
private void Finish()//when finish downloading whole files { string filePath = AssetBundleUtility.GetFileFolder() + "/" + AssetBundleUtility.fileName; string directory = Path.GetDirectoryName(filePath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllBytes(filePath, fileInfoBytes); AssetBundleMgr.Init(); finishHandler(); Dispose(); }
public void Init(Action param) { handler = param; string filePath = AssetBundleUtility.GetFileFolder() + "/" + AssetBundleUtility.fileName; if (File.Exists(filePath)) { handler(); } else { DeleteFileFolder(); GetFileInfo(); } }
void DeleteFileFolder() { string tempD = AssetBundleUtility.GetFileFolder(); //if (!Directory.Exists(tempD)) // return; //DirectoryInfo tempDInfo = new DirectoryInfo(tempD); //FileInfo[] tempFInfos = tempDInfo.GetFiles("*.*", SearchOption.AllDirectories); //for (int i = 0; i < tempFInfos.Length; i++) // if (File.Exists(tempFInfos[i].Name)) // File.Delete(tempFInfos[i].Name); if (Directory.Exists(tempD)) { Directory.Delete(tempD, true); } }
private void FinishDownloadFile(WWW paramWWW) { string filePath = AssetBundleUtility.GetFileFolder() + "/" + updateList[0]; string directory = Path.GetDirectoryName(filePath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.WriteAllBytes(filePath, paramWWW.bytes); updateList.RemoveAt(0); DownloadFile(); if (updateList != null) { progress = (totalCount - updateList.Count) / totalCount; } }
private static void Build(BuildTarget param) { string fileFolder = Application.streamingAssetsPath + "/" + AssetBundleUtility.fileFolderName; if (Directory.Exists(fileFolder)) { Directory.Delete(fileFolder, true); } string assetBundleFolder = fileFolder + "/" + AssetBundleUtility.GetPlatformName(param); if (!Directory.Exists(assetBundleFolder)) { Directory.CreateDirectory(assetBundleFolder); } BuildPipeline.BuildAssetBundles(assetBundleFolder, options, param); GenerateFileInfo(fileFolder); Debug.Log("Finish build assetbundle"); }
private static void SetDependenceInfo() { string path = AssetBundleUtility.GetManifestPath(); if (!File.Exists(path)) { return; } #if UNITY_5_3 || UNITY_5_3_OR_NEWER AssetBundle assetBundle = AssetBundle.LoadFromFile(path); #else AssetBundle assetBundle = AssetBundle.CreateFromFile(path); #endif AssetBundleManifest assetBundleManifest = assetBundle.LoadAsset("assetbundlemanifest") as AssetBundleManifest; string[] assetBundleNames = assetBundleManifest.GetAllAssetBundles(); foreach (string paramName in assetBundleNames) { string[] dependence = assetBundleManifest.GetAllDependencies(paramName); assetBundleDependencies.Add(paramName, dependence); } assetBundle.Unload(true); }