public static string GetFileHash(string path, bool force = false) { string _hexStr = null; if (_fileHashCache.ContainsKey(path) && !force) { _hexStr = _fileHashCache[path]; } else if (File.Exists(path) == false) { _hexStr = "FileNotExists"; } else { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); _hexStr = HashUtil.Get(fs); _fileHashCache[path] = _hexStr; fs.Close(); } return(_hexStr); }
public static string GetPackTag(DirectoryInfo bundleDir, FileInfo file, PackMode fPackMode, string parttern, out string abName) { abName = null; switch (fPackMode) { case PackMode.Indepent: return(null); case PackMode.AllInOne: var str1 = "__" + bundleDir.ToString() + parttern + fPackMode; abName = HashUtil.Get(str1) + ".ab"; return(bundleDir.ToString() + "/" + parttern + "(" + fPackMode + ")"); case PackMode.PerAnyDir: var d = file.Directory; var str2 = bundleDir.ToString() + d.FullName.Replace(bundleDir.FullName, ""); abName = HashUtil.Get("_" + str2) + ".ab"; return(str2 + "/" + parttern + "(" + fPackMode + ")"); case PackMode.PerSubDir: var dir = file.Directory; var subDir = ""; while (dir.FullName != bundleDir.FullName) { subDir = dir.Name + "/"; dir = dir.Parent; } var str = "____" + bundleDir.ToString() + subDir + parttern + fPackMode; abName = HashUtil.Get(str) + ".ab"; return(bundleDir.ToString() + "/" + subDir + parttern + "(" + fPackMode + ")"); default: return(null); } }
/// <summary> /// 同步加载 /// </summary> /// <param name="path"></param> /// <returns></returns> public AssetBundle Load(string path) { #if _AB_MODE_ AssetBundleData data = _depInfoReader.GetAssetBundleInfo(HashUtil.Get(path.ToLower()) + ".ab"); string sourceFile = pathResolver.GetBundleSourceFile(data.fullName, false); var ab = AssetBundle.LoadFromFile(sourceFile); return(ab); #else return(null); #endif }
public AssetTarget(Object o, FileInfo file, string assetPath) { this.asset = o; this.file = file; this.assetPath = assetPath; this.bundleShortName = file.Name.ToLower(); this.bundleName = HashUtil.Get(AssetBundleUtils.ConvertToABName(assetPath)) + ".ab"; this.bundleSavePath = Path.Combine(AssetBundleUtils.pathResolver.BundleSavePath, bundleName); _isFileChanged = true; _metaHash = "0"; }
public AssetBundleInfo GetBundleInfo(string key) { key = key.ToLower(); #if _AB_MODE_ key = HashUtil.Get(key) + ".ab"; #endif var e = _loadedAssetBundle.GetEnumerator(); while (e.MoveNext()) { AssetBundleInfo abi = e.Current.Value; if (abi.bundleName == key) return abi; } return null; }
/// <summary> /// 通过一个路径加载ab /// </summary> /// <param name="path">路径</param> /// <param name="prority">优先级</param> /// <param name="handler">回调</param> /// <returns></returns> public AssetBundleLoader Load(string path, int prority, LoadAssetCompleteHandler handler = null) { #if _AB_MODE_ AssetBundleLoader loader = this.CreateLoader(HashUtil.Get(path.ToLower()) + ".ab", path); #else AssetBundleLoader loader = this.CreateLoader(path); #endif loader.prority = prority; loader.onComplete += handler; _isCurrentLoading = true; _nonCompleteLoaderSet.Add(loader); _thisTimeLoaderSet.Add(loader); return(loader); }
public AssetBundleLoader Load(string path, LoadAssetCompleteHandler handler = null) { #if _AB_MODE_ AssetBundleLoader loader = this.CreateLoader(HashUtil.Get(path.ToLower()) + ".ab", path); #else AssetBundleLoader loader = this.CreateLoader(path); #endif if (loader == null) { handler(null); } else { _thisTimeLoaderSet.Add(loader); if (loader.isComplete) { if (handler != null) { handler(loader.bundleInfo); } } else { if (handler != null) { loader.onComplete += handler; } _isCurrentLoading = true; if (loader.state < LoadState.State_Loading) { _nonCompleteLoaderSet.Add(loader); } this.StartLoad(); } } return(loader); }
public AssetTarget(Object o, FileInfo file, string assetPath) { string abName = AssetBundleUtils.ConvertToABName(assetPath); string dirName = file.Directory.Name; if (dirName.StartsWith("&")) { int index = file.DirectoryName.IndexOf("Assets"); if (index != -1) { dirName = file.DirectoryName.Substring(index); abName = AssetBundleUtils.ConvertToABName(dirName); } } this.asset = o; this.file = file; this.assetPath = assetPath; this.bundleShortName = file.Name.ToLower(); this.bundleName = HashUtil.Get(abName) + ".ab"; this.bundleSavePath = Path.Combine(AssetBundleUtils.pathResolver.BundleSavePath, bundleName); _isFileChanged = true; _metaHash = "0"; }