IEnumerator TryGetVersion() { var ManifestPath = string.Format("{0}{1}", AssetBundlePath, VersionFileName); using (UnityWebRequest uwr = UnityWebRequest.Get(ManifestPath)) { yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.error != null) { FrameDebug.LogError(String.Format("File -{0}- Download failed{1}", ManifestPath, uwr.error)); yield break; } m_dataMap.Clear(); var data = Encoding.UTF8.GetString(uwr.downloadHandler.data); var infos = data.Split('\n'); foreach (var item in infos) { var texts = item.Split('\t'); var itemdata = new ResItemData(); itemdata.resName = texts[0]; itemdata.resHash = texts[1]; itemdata.resSize = int.Parse(texts[2]); m_dataMap[itemdata.resName] = itemdata; } FrameDebug.Log(string.Format("Finish Download Version")); verReadFinished = true; } }
/// <summary> /// 缓存的unity objects /// 请求过的物体会在这里缓存起来 /// </summary> public T Load <T>(string path) where T : class, new() { T obj = null; Object temp = null; if (CachedObjects.TryGetValue(path, out temp)) {// 尝试在缓存中查找 obj = temp as T; return(obj); } var fileName = path.Replace("/", DIR_SPLIT);//替换目录分隔符 if (DownloadedFiles.ContainsKey(fileName)) { FileInfo file = DownloadedFiles[fileName]; var bytes = File.ReadAllBytes(file.FullName); var ab = AssetBundle.LoadFromMemory(bytes); string objectName = Path.GetFileName(path); temp = ab.LoadAsset(objectName, typeof(T)); obj = temp as T; ab.Unload(false);//一旦加载完毕,立即释放assetbundle,但不释放bundle中的物体。 if (obj == null) { FrameDebug.LogError(string.Format("the resource {0} load from ab is null", path)); return(null); } CachedObjects.Add(path, temp); } else { temp = Resources.Load(path, typeof(T)); obj = temp as T; } return(obj); }
void IClientModule.InitData() { FrameDebug.Log("Start Init ModuleLua"); luaScriptsFullPath = Application.dataPath + luaScriptsFolder; DoHotFix(); luaEnv.AddLoader(CustomLoader); LoadScript(HotFix); LuaFileWatcher.CreateLuaFileWatcher(luaEnv); }
private void LoadAync(int index) { if (index < jobs.Count) { ResManager.Instance.AddDownload(jobs[index]); } else { FrameDebug.Log("Index out range"); } }
public static string GetAssetBuildPath(BuildTarget target) { switch (target) { case BuildTarget.StandaloneWindows64: return(GetFullOutPutDir(target) + "Windows"); default: FrameDebug.LogError("Dont Contain target" + target.ToString()); return(GetFullOutPutDir(target) + "default"); } }
public static string GetFullOutPutDir(BuildTarget target) { switch (target) { case BuildTarget.StandaloneWindows64: return(Application.dataPath.Remove(Application.dataPath.Length - 6) + GetOutPutDir(target)); default: FrameDebug.LogError("Dont Contain target" + target.ToString()); return("AssetBundles"); } }
static void WriteVersion(BuildTarget target) { FrameDebug.Log("Start Write Verison"); var oripath = GetFullOutPutDir(target); var path = GetAssetBuildPath(target); var manifestPath = GetManifestPath(target); var temps = new List <string>(Directory.GetFiles(oripath)); temps.Remove(path); var versionpath = oripath + versionName; if (Directory.Exists(versionpath)) { Directory.Delete(versionpath); } var viersionfile = File.CreateText(versionpath); var allfiles = new List <string>(Directory.GetFiles(oripath)); allfiles.Remove(versionpath); allfiles.Remove(manifestPath); allfiles.Remove(manifestPath + ".manifest"); var allmanifest = AssetBundle.LoadFromFile(manifestPath).LoadAsset <AssetBundleManifest>("AssetBundleManifest").GetAllAssetBundles(); for (int i = 0; i < allmanifest.Length; i++) { if (!allmanifest[i].EndsWith(".manifest")) { var fullitemPath = oripath + allmanifest[i]; var manifest = AssetBundle.LoadFromFile(fullitemPath); if (manifest != null) { var code = manifest.GetHashCode(); allfiles.Remove(fullitemPath); if (i == allmanifest.Length - 1) { viersionfile.Write(string.Format("{0}\t{1}\t{2}", allmanifest[i], AssetBundleUtils.GetMD5(fullitemPath), AssetBundleUtils.GetSize(fullitemPath))); } else { viersionfile.WriteLine(string.Format("{0}\t{1}\t{2}", allmanifest[i], AssetBundleUtils.GetMD5(fullitemPath), AssetBundleUtils.GetSize(fullitemPath))); } } } } viersionfile.Close(); //删除不属于的ab foreach (var item in allfiles) { File.Delete(item); } FrameDebug.Log("Finish"); }
void Awake() { DontDestroyOnLoad(gameObject); if (Ins == null) { Ins = this; Inited = false; FindMdule(); } else { FrameDebug.LogError("Client has been created mutiple times!"); } }
static string GetTargetName(BuildTarget target) { switch (target) { case BuildTarget.StandaloneWindows64: return("Windows"); case BuildTarget.StandaloneWindows: return("Windows"); default: FrameDebug.LogError("Null Target Name"); return(""); } }
private static byte[] CustomLoader(ref string filepath) { string scriptPath = string.Empty; filepath = filepath.Replace(".", "/") + ".lua"; scriptPath = Path.Combine(luaScriptsFullPath, filepath); if (!File.Exists(scriptPath)) { FrameDebug.LogError("Error Lua Script Path" + scriptPath); return(null); } File.SetAttributes(scriptPath, FileAttributes.Normal); return(File.ReadAllBytes(scriptPath)); }
private IEnumerator DownLordAssetBundle(ResItem item) { UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(item.fullpath); www.SendWebRequest(); item.StartDownLoading(); while (!www.isDone) { yield return(1); } if (www.isNetworkError || www.isHttpError) { FrameDebug.Log("DownLoad Err: " + www.error); } else { var ab = DownloadHandlerAssetBundle.GetContent(www); } }
public static string GetMD5(string path) { try { Stream st = new FileStream(path, FileMode.Open, FileAccess.Read); MD5 md5 = new MD5CryptoServiceProvider(); StringBuilder sb = new StringBuilder(); var temp = md5.ComputeHash(st); foreach (var item in temp) { sb.Append(item.ToString("x2")); } st.Dispose(); return(sb.ToString()); } catch (Exception ex) { FrameDebug.LogError(ex.ToString()); return(""); } }