/// <summary> /// 获取下载队列句柄 /// </summary> /// <param name="_pathType"></param> /// <returns></returns> private IRequestTaskQueue GetDownloadHandler(AssetPathType _pathType) { var taskQueue = App.Make <IRequestTaskQueue>(); if (null != serverVersion) { var downloadItems = CheckDownloadList(serverVersion.AssetBundleVersionItems, _pathType); if (null == downloadItems) { return(null); } downloadInfo.SetDownloadList(_pathType, downloadItems); if (downloadItems.Count > 0) { for (int index = 0; index < downloadItems.Count; index++) { var downloadItem = downloadItems[index]; var path = GetDownloadPath(downloadItem); if (null == path) { continue; } taskQueue.AddTask(path, DownloadResType.ByteArray, SingleAssetComplete, downloadItem); } } } return(taskQueue); }
//按path类型获取完整路径(没有斜杆) static public string GetPathWithoutDiagonal(string path, AssetPathType pathtype) { path = PlatformPathMng.SubPathByPlatform(path); return(PlatformPathMng.GetFilePath(path, pathtype, "")); // if (Application.platform == RuntimePlatform.Android) // { // if (pathtype == 0) // return Application.streamingAssetsPath + "/assetbundles" + path; // else if (pathtype == 1) // { // return "file:///" + Application.persistentDataPath + "/assetbundles_android" + path; // } // else // return baseURL + "/assetbundles_http" + path; // } // else // { // if (pathtype == 0) // return "file://" + Application.streamingAssetsPath + "/assetbundles" + path; // else if (pathtype == 1) // { // return Application.persistentDataPath + "/assetbundles_android" + path; // } // else // return baseURL + "/assetbundles_http" + path; // } }
private void NativeVersionCompare() { Debugger.Log("Native version compare."); #if UNITY_WEBGL m_AssetPathType = AssetPathType.Persistent; m_Version = GetPersistentVersion(null); Debugger.Log("Persistent version: " + (m_Version ?? "null")); Debugger.Log("Last native version in Persistent."); #else string streamingVersion = ConstValue.VERSION; Debugger.Log("Streaming version: " + streamingVersion); string[] streamingVersions = ConstValue.VERSION.Split('.'); int streamingHotVersion = StringParser.StringToInt(streamingVersions[2]); string persistentVersion = GetPersistentVersion(ConstValue.VERSION); Debugger.Log("Persistent version: " + persistentVersion); string[] persistentVersions = persistentVersion.Split('.'); int persistentHotVersion = StringParser.StringToInt(persistentVersions[2]); if (string.Equals(persistentVersions[0], streamingVersions[0]) && string.Equals(persistentVersions[1], streamingVersions[1]) && persistentHotVersion > streamingHotVersion) { m_AssetPathType = AssetPathType.Persistent; m_Version = persistentVersion; Debugger.Log("Last native version in Persistent."); } else { m_AssetPathType = AssetPathType.Streaming; m_Version = streamingVersion; Debugger.Log("Last native version in Streaming."); } #endif }
/// <summary> /// 停止下载 /// </summary> public void StopDownload(AssetPathType _type) { if (_type == AssetPathType.gameLoad && null != gameingDownloadHandler) { gameingDownloadHandler.StopDownload(); } DownloadProgressCallback = null; }
/// <summary> /// 获取下载队列 /// </summary> /// <param name="_type"></param> public List <AssetBundleVersionItem> GetDownloadList(AssetPathType _type) { if (false == DownloadItemsDic.ContainsKey(_type)) { emptyList.Clear(); return(emptyList); } return(DownloadItemsDic[_type]); }
/// <summary> /// 获取Streaming根路径 /// </summary> /// <returns></returns> public static string GetStreamingBasePath() { AssetPathType t = AssetPathType.Path_Streaming; if (AssetSetting.UseExternalFile) { t = AssetPathType.Path_LocalStreaming; } return(GetAssetBasePath(t)); }
/// <summary> /// 获取XML文件的路径 by /// </summary> static public string GetXmlLoadFilePath(string path, AssetPathType pathtype) { path = PlatformPathMng.SubPathByPlatform(path); return(PlatformPathMng.GetFilePath(path, pathtype, "")); //#if UNITY_ANDROID // if (Application.platform == RuntimePlatform.Android) // { // if(pathtype==0) // return Application.streamingAssetsPath + "/assetbundles/" + path; // else // { // return Application.persistentDataPath + "/assetbundles_android/" + path; // } // } // else // { // if (pathtype == 0) // return "file:///" +Application.streamingAssetsPath + "/assetbundles/" + path; // else // { // return Application.persistentDataPath + "/assetbundles_android/" + path; // } // } //#elif UNITY_IPHONE // if (Application.platform == RuntimePlatform.IPhonePlayer) // { // if(pathtype==0) // return Application.streamingAssetsPath + "/assetbundles/" + path; // else // { // return "file:///" + Application.persistentDataPath + "/assetbundles_ios/" + path; // } // } // else // { // if (pathtype == 0) // return "file:///" +Application.streamingAssetsPath + "/assetbundles/" + path; // else // { // return Application.persistentDataPath + "/assetbundles_ios/" + path; // } // } // //#else // if (pathtype == 0) // return "file://" + Application.streamingAssetsPath + "/assetbundles/" + path; // else // { // return "file:///" + Application.persistentDataPath + "/assetbundles_win32/" + path; // } //#endif }
static public string GetWWWPath(string path, AssetPathType pathtype, string suffix = "") { string temppath = ""; if (pathtype == AssetPathType.Http) { temppath = GetWWWTypePath(wwwProtocolType.http, pathtype, GetFilePath(path, pathtype, suffix)); } else { temppath = GetWWWTypePath(wwwProtocolType.file, pathtype, GetFilePath(path, pathtype, suffix)); } return(temppath); }
/// <summary> /// 设置资源下载 /// </summary> /// <param name="_type"></param> /// <param name="_list"></param> public void SetDownloadList(AssetPathType _type, List <AssetBundleVersionItem> _list) { if (null == _list || _list.Count <= 0) { return; } if (false == DownloadItemsDic.ContainsKey(_type)) { DownloadItemsDic.Add(_type, _list); } else { DownloadItemsDic[_type] = _list; } }
/// <summary> /// 获得资源文件的根路径 /// </summary> /// <param name="pathType"></param> /// <returns></returns> public static string GetAssetBasePath(AssetPathType pathType) { switch (pathType) { case AssetPathType.Path_Local: return(GetAssetLocalPath()); case AssetPathType.Path_Streaming: return(GetAssetStreamingAssetsPath()); case AssetPathType.Path_LocalStreaming: return(GetAssetLocalStreamingAssetsPath()); default: return(string.Empty); } }
static public string GetWWWTypePath(wwwProtocolType type, AssetPathType pathtype, string completeFilePath) { string temppath = ""; switch (type) { case wwwProtocolType.file: if (Application.platform == RuntimePlatform.Android && pathtype == AssetPathType.StreamingAssetsPath) { temppath = completeFilePath; } else { if (completeFilePath.Substring(0, 1) == "/") { temppath = "file://" + completeFilePath; } else { temppath = "file:///" + completeFilePath; } } break; case wwwProtocolType.ftp: temppath = "ftp://" + completeFilePath; break; case wwwProtocolType.http: temppath = "http://" + completeFilePath; break; case wwwProtocolType.https: temppath = "https://" + completeFilePath; break; } return(temppath); }
static public string GetFilePath(string path, AssetPathType _pathtype, string suffix = "") { string temppath = ""; if (path.Length > 0 && path.Substring(0, 1) == "/") { path = path.Remove(0, 1); } path += suffix; //拼接api固定路径 switch (_pathtype) { case AssetPathType.StreamingAssetsPath: temppath = GetStreamingAssetsPath(path); break; case AssetPathType.PersistentDataPath: temppath = GetPersistentAssetsPath(path); break; case AssetPathType.DataPath: temppath = GetDataPath(path); break; case AssetPathType.TemporaryCachePath: temppath = GetTemporaryCachePath(path); break; case AssetPathType.Http: temppath = GetHttpAssetPath(path); break; default: break; } return(temppath); }
//按path类型获取完整路径(没有斜杆) static public string GetPathWithoutDiagonal(string path, AssetPathType pathtype) { path = PathTool.SubPathByPlatform(path); return(PathTool.GetFilePath(path, pathtype, "")); }
//按path类型获取完整路径 by邓成 static public string GetPathWithoutExtension(string path, AssetPathType pathtype) { path = PathTool.SubPathByPlatform(path); return(PathTool.GetWWWPath(path, pathtype, "")); }
/// <summary> /// 检测某个类型的资源下载里列表 /// </summary> /// <returns></returns> private List <AssetBundleVersionItem> CheckDownloadList(List <AssetBundleVersionItem> _abItemList, AssetPathType _pathType) { List <AssetBundleVersionItem> result = new List <AssetBundleVersionItem>(); if (null == _abItemList || _abItemList.Count <= 0) { return(null); } long sizeCount = 0; for (int index = 0; index < _abItemList.Count; index++) { var item = _abItemList[index]; if (null == item) { continue; } string fileFullPath = GetFileLocalPath(item); if (false == App.Make <IFileDiskSystem>().FileExists(fileFullPath)) // 这里直接检测本地文件 { if (item.AssetPathType == _pathType) { sizeCount += item.size; result.Add(item); } } } downloadInfo.DownloadSizeCount = sizeCount; return(result); }
private IEnumerator DoVersionUpdate(Action callback) { // 对比文件 m_UpdateStepType = UpdateStepType.FileCompare; string[] streamingVersions = ConstValue.VERSION.Split('.'); string cdnCurVerUrl = ConstValue.CDN_URL + "/" + ConstValue.GAME_NAME + "/" + ConstValue.BUNDLE_DIR + "/" + streamingVersions[0] + "." + streamingVersions[1]; // 下载并解析CDN上的文件列表和Manifest WWWLoader cdnFileListLoader = WWWManager.Load(cdnCurVerUrl + "/" + m_ModuleName + "/" + ConstValue.FILE_LIST_NAME, this); yield return(cdnFileListLoader.Wait); m_CdnFileList = StringParser.StringToJo(cdnFileListLoader.Text, false); // 统计需要下载的和需要删除的 CountFiles(); // 下载 if (m_UpdateIndex > 1) { LuaTable UIManager = LuaMain.LuaEnv.Global.GetInPath <LuaTable>("LuaClass.UIManager.Instance"); LuaTable moduleTypeClass = LuaMain.LuaEnv.Global.GetInPath <LuaTable>("LuaClass.ModuleType"); m_LoadingUI = LuaMain.Instance.FuncInvoke(UIManager, "Open", UIManager, moduleTypeClass.Get <object>("Common"), "LoadingUI") as LuaTable; } m_UpdateStepType = UpdateStepType.FileDownload; for (m_Index = 0; m_Index < UpdateFileNameList.Count; m_Index++) { string fileName = UpdateFileNameList[m_Index]; m_CurrentLoader = WWWManager.Load(cdnCurVerUrl + "/" + fileName, this); yield return(m_CurrentLoader.Wait); if (m_CurrentLoader.Error != null) { // 下载失败,需要重新更新 Debugger.Log("Update failed by: " + m_CurrentLoader.Error); m_UpdateStepType = UpdateStepType.UpdateFailed; OnUpdateFaild(fileName, m_CurrentLoader.Error); yield break; } byte[] bytes = m_CurrentLoader.Bytes; if (bytes != null) { FileManager.Write(ConstValue.PERSISTENT_DIR_PATH + "/" + fileName, bytes); } } // 删除 m_UpdateStepType = UpdateStepType.FileDelete; for (m_Index = 0; m_Index < DeleteFileNameList.Count; m_Index++) { string fileName = DeleteFileNameList[m_Index]; FileManager.Delete(ConstValue.PERSISTENT_DIR_PATH + "/" + fileName); yield return(null); } // 将CDN上的Version文件和Manifest文件写入本地 m_UpdateStepType = UpdateStepType.VersionWrite; // 将Persistent的文件列表替换成Cdn上的文件列表,并写入文件 m_PersistentFileList = m_CdnFileList; SetPersistentFileList(); // 将Version标记为最新的版本 string[] cdnVersions = m_CdnVersion.Split('.'); string[] nativeVersions = m_Version.Split('.'); m_Version = nativeVersions[0] + "." + nativeVersions[1] + "." + cdnVersions[2]; SetPersistentVersion(m_Version); // 热更完成 Action action = () => { m_UpdateStepType = UpdateStepType.UpdateFinished; //优先读Persistent m_AssetPathType = AssetPathType.Persistent; }; action += callback; CoroutineManager.MainThread(action); }
//按path类型获取完整路径 by吴江 static public string GetPathWithExtension(string path, AssetPathType pathtype) { path = PlatformPathMng.SubPathByPlatform(path); return(PlatformPathMng.GetWWWPath(path, pathtype, ".assetbundle")); }
/// <summary> /// 获取XML文件的路径 by /// </summary> static public string GetXmlLoadFilePath(string path, AssetPathType pathtype) { path = PathTool.SubPathByPlatform(path); return(PathTool.GetFilePath(path, pathtype, "")); }
/// <summary> /// 获得资源文件的根路径 /// </summary> /// <param name="ptype"></param> /// <returns></returns> public static string GetFileAssetBase(AssetPathType ptype) { if (ptype == AssetPathType.Path_Local) { switch (Application.platform) { //编辑器模式 case RuntimePlatform.WindowsEditor: case RuntimePlatform.OSXEditor: return(Application.dataPath + "/../../../Bin/client/StreamingAssets/"); case RuntimePlatform.WindowsPlayer: return(Application.dataPath + "/../StreamingAssets/"); case RuntimePlatform.Android: return(Application.persistentDataPath + "/Data/"); case RuntimePlatform.IPhonePlayer: return(Application.persistentDataPath + "/Raw/"); default: return(""); } } else if (ptype == AssetPathType.Path_Streaming) { switch (Application.platform) { case RuntimePlatform.WindowsEditor: case RuntimePlatform.OSXEditor: if (!string.IsNullOrEmpty(editorAssetPath)) { return("file://" + editorAssetPath); } return("file://" + Application.dataPath + "/../../../Bin/client/StreamingAssets/"); case RuntimePlatform.WindowsPlayer: return("file://" + Application.dataPath + "/../StreamingAssets/"); case RuntimePlatform.Android: return("jar:file://" + Application.dataPath + "!/assets/Data/"); case RuntimePlatform.IPhonePlayer: return("file://" + Application.dataPath + "/Raw/"); default: return(""); } } else if (ptype == AssetPathType.Path_LocalStreaming) { switch (Application.platform) { case RuntimePlatform.WindowsEditor: case RuntimePlatform.OSXEditor: return("file://" + Application.dataPath + "/../../../Bin/client/StreamingAssets/"); case RuntimePlatform.WindowsPlayer: return("file://" + Application.dataPath + "/../StreamingAssets/"); case RuntimePlatform.Android: return("file://" + Application.persistentDataPath + "/Data/"); case RuntimePlatform.IPhonePlayer: return("file://" + Application.persistentDataPath + "/Data/"); default: return(""); } } return(""); }