//开始校验文件 void StartCheckFile(FileListJson fileListJson) { var fileList = fileListJson.FileList; foreach (FileJson fileJson in fileList) { string filename = fileJson.FileName; string md5 = fileJson.MD5; string path = GameConfig.GetReadPath(filename); string checkMD5 = FileHelper.GetMD5HashFromFile(path); if (md5 != checkMD5) { string fp = GameConfig.GetPersitentPath("chinatown/filelist.txt"); string vp = GameConfig.GetPersitentPath("chinatown/version.txt"); //将之前的更新文件删除 File.Delete(fp); File.Delete(vp); InitFailed("校验文件失败"); return; } } InitLua(fileListJson); }
/// <summary> /// 初始化 /// </summary> /// <param name="fileListJson"></param> /// <param name="callback"></param> public void Init(FileListJson fileListJson, Action callback, Action <string> errorback) { int count = 0; foreach (FileJson json in fileListJson.FileList) { string filename = json.FileName; if (filename.EndsWith(".lua" + GameConfig.AssetTail)) { filename = filename.Replace(GameConfig.AssetTail, ""); string prefix = GameConfig.GameName + "/Lua/"; int index = prefix.Length; string luaName = filename.Substring(index); count++; ABLoader.Instance.LoadAssetBundle(filename, typeof(TextAsset), (obj) => { TextAsset text = obj as TextAsset; m_LuaDict[luaName] = text.text; count--; if (count == 0) { callback(); } }, errorback); } } }
//初始化lua void InitLua(FileListJson fileListJson) { m_InitView.SetDetail(""); m_InitView.SetTitle("加载脚本"); LuaManager.instance.Init(fileListJson, () => { StartGame(); }, (msg) => { InitFailed("脚本加载失败"); } ); }
//校验文件 void CheckFile() { m_InitView.SetTitle("校验文件"); string path = GameConfig.GetWWWReadPath("chinatown/filelist.txt"); ABLoader.Instance.LoadRes(path, (www) => { if (www.error != null) { InitFailed("获取校验列表失败"); return; } string text = www.text; FileListJson json = JsonUtility.FromJson <FileListJson>(text); StartCheckFile(json); }); }
//获得服务器版本列表 public void GetServerFileList() { m_InitView.SetTitle("获得服务器文件列表"); string url = GameConfig.GetResUrl("chinatown/filelist.txt"); ABLoader.Instance.LoadRes(url, (www) => { if (www.error != null) { InitFailed("获得服务器文件列表失败"); return; } string text = www.text; m_ServerFileList = JsonUtility.FromJson <FileListJson>(text); CompareFileList(); }); }
//获得本地文件 public void GetLocalFileList() { m_InitView.SetTitle("获得本地文件列表"); string path = GameConfig.GetWWWReadPath("chinatown/filelist.txt"); ABLoader.Instance.LoadRes(path, (www) => { if (www.error != null) { InitFailed("获得本地文件列表失败"); return; } string text = www.text; m_LocalFileList = JsonUtility.FromJson <FileListJson>(text); GetServerFileList(); }); }