/// <summary> /// 下载云端MD5文件与本地MD5对比 /// </summary> /// <param name="ResClass"></param> /// <param name="processEvent">如果不是AR的AB,那么久需要直接下载,这里是AB包下载进度回调</param> /// <param name="aBMD5CallBack">MD5下载完成后的回调,会将结果传回去</param> /// <param name="isHasRecog"></param> public void ABMD5Request(string ResClass, ABProcessEvent processEvent, ABMD5CallBack aBMD5CallBack = null, bool isHasRecog = false) { OneABClassInfo oldClassInfo = SerializeHelper.FromJson <OneABClassInfo>(FileHelper.ReadTxtToStr(GetSavePathByClass(ResClass, false))); AddDownload(ResClass, true, ABDataHolder.Instance.GetMD5DownURL() + ResClass + "Info.txt"); DownManager.Instance.StartDownABMD5(ABClassDownInfo.Allocate(ResClass, ABDataHolder.Instance.GetMD5DownURL() + ResClass + "Info.txt", GetSavePathByClass(ResClass, true), true, aBMD5CallBack, ABMD5ResultCallback, processEvent, oldClassInfo, isHasRecog)); }
/// <summary> /// 获取xml文件中的识别对象,比如全部的识别图名称,或者模型名称 /// </summary> /// <param name="xmlPath"></param> /// <returns></returns> public static List <string> GetDataSetTarget(string xmlPath) { if (xmlPath == "") { AFLogger.d("未找到DataSet对应的xml文件,请检查设置!"); return(null); } if (!FileHelper.JudgeFilePathExit(xmlPath)) { AFLogger.d("DataSet对应的xml路径不存在:" + xmlPath); return(null); } string xmlContent = FileHelper.ReadTxtToStr(xmlPath); if (xmlContent.Contains("ImageTarget")) { FileInfo fileInfo = new FileInfo(xmlPath); using (FileStream fs = fileInfo.OpenRead()) { var knownTypes = new Type[] { typeof(VuforiaImage.ImageTargetList) }; XmlSerializer xmlserializer = new XmlSerializer(typeof(VuforiaImage.QCARConfig), knownTypes); VuforiaImage.QCARConfig data = xmlserializer.Deserialize(fs) as VuforiaImage.QCARConfig; List <string> imageTargets = new List <string>(); foreach (var OneImageTarget in data.Tracking.ImageTarget) { imageTargets.Add(OneImageTarget.name); } return(imageTargets); } } else if (xmlContent.Contains("ModelTarget") && xmlContent.Contains("Assembly")) { FileInfo fileInfo = new FileInfo(xmlPath); using (FileStream fs = fileInfo.OpenRead()) { var knownTypes = new Type[] { typeof(VuforiaModel.ModelTargetInfo), typeof(VuforiaModel.ModelTargetNameInfo), typeof(VuforiaModel.Assembly), typeof(VuforiaModel.Part) }; XmlSerializer xmlserializer = new XmlSerializer(typeof(VuforiaModel.QCARConfig), knownTypes); VuforiaModel.QCARConfig data = xmlserializer.Deserialize(fs) as VuforiaModel.QCARConfig; List <string> imageTargets = new List <string>(); imageTargets.Add(data.Assembly.Part.name); return(imageTargets); } } return(null); }
private static bool IsAFoudationAvailable() { bool isLoad = FileHelper.ReadTxtToStr(System.Environment.CurrentDirectory + "/Packages/manifest.json") .Contains("com.unity.xr.arfoundation"); if (isLoad && Loadstate == SDKLoadState.Loaded) { Loadstate = SDKLoadState.LoadAndInit; } else { if (isLoad) { Loadstate = SDKLoadState.Loaded; SDKLoadInit(); } else { Loadstate = SDKLoadState.UnLoad; } } return(isLoad); }
public override void DownloadFinish() { base.DownloadFinish(); HttpTxtInfo httpTxtInfo = (HttpTxtInfo)httpInfo; if (httpTxtInfo.webRequestTextEvent != null) { if (httpTxtInfo.returnPathOrCon) { httpTxtInfo.webRequestTextEvent.Invoke(m_saveFilePath, downResult, downError); } else { if (downResult == DownStatus.Fail) { httpTxtInfo.webRequestTextEvent.Invoke("", downResult, downError); } else { httpTxtInfo.webRequestTextEvent.Invoke(FileHelper.ReadTxtToStr(m_saveFilePath), downResult, downError); } } } }
public override void DownloadFinish() { base.DownloadFinish(); ABClassDownInfo aBDownInfo = (ABClassDownInfo)httpInfo; OneABClassInfo NewABInfo = SerializeHelper.FromJson <OneABClassInfo>(FileHelper.ReadTxtToStr(m_saveFilePath)); List <string> downStr = new List <string>(); bool isLocalABComplete = true; bool isNeedHot = false; if (aBDownInfo.oldClassInfo != null) { List <string> keys = new List <string>(NewABInfo.FileMD5.Keys); for (int i = 0; i < keys.Count; i++) { if (aBDownInfo.oldClassInfo.FileMD5.ContainsKey(keys[i])) { if (NewABInfo.FileMD5[keys[i]].Equals(aBDownInfo.oldClassInfo.FileMD5[keys[i]])) // MD5相等 { if (!FileHelper.JudgeFilePathExit(PathTool.PersistentDataPath + keys[i])) //本地没有AB存在 { AFLogger.d("检测MD5:本地没有AB存在111"); isLocalABComplete = false; //本地AB包不完整 isNeedHot = true; downStr.Add(keys[i]); } } else { isNeedHot = true; downStr.Add(keys[i]); if (!FileHelper.JudgeFilePathExit(PathTool.PersistentDataPath + "/" + keys[i])) //本地没有AB存在 { AFLogger.d("检测MD5:本地没有AB存在222"); isLocalABComplete = false; //本地AB包不完整 } } } else { isLocalABComplete = false; //本地AB包不完整 isNeedHot = true; downStr.Add(keys[i]); } } } else { isLocalABComplete = false; isNeedHot = true; List <string> keys = new List <string>(NewABInfo.FileMD5.Keys); for (int i = 0; i < keys.Count; i++) { FileHelper.DeleteFile(PathTool.PersistentDataPath + "/" + keys[i]); downStr.Add(keys[i]); } } if (aBDownInfo.ABMD5Callback != null) { ABState aBState = ABState.Newest; if (isNeedHot) { if (isLocalABComplete) { aBState = ABState.UpdateAndLocalComplete; } else { aBState = ABState.UpdateAndLocalNotComplete; } } aBDownInfo.CheckMD5Call(NewABInfo, aBState, downStr); aBDownInfo.ABMD5CallbackLocal(aBDownInfo, downResult, downError); } }
public string LoadStr(string path) { return(FileHelper.ReadTxtToStr(path)); }
/// <summary> /// 加载Androidmanifest /// </summary> /// <returns></returns> public bool LoadAssetManifest() { AssetBundleConfig config = null; switch (ABConfig.configWritingMode) { case ConfigWritingMode.Binary: if (FileHelper.JudgeFilePathExit(GetABConfigLocalPath())) { if (configAB != null) { configAB.Unload(false); } configAB = AssetBundle.LoadFromFile(GetABConfigLocalPath()); TextAsset textAsset = configAB.LoadAsset <TextAsset>(ABConfigName); if (textAsset == null) { Debug.LogError("AssetBundleConfig is no exist!"); return(false); } //反序列化,得到打包的信息 MemoryStream stream = new MemoryStream(textAsset.bytes); BinaryFormatter bf = new BinaryFormatter(); config = (AssetBundleConfig)bf.Deserialize(stream); stream.Close(); } else { AFLogger.e("AssetbundleConfig文件不存在"); return(false); } break; case ConfigWritingMode.TXT: string abJson = ""; if (ABConfig.ABResLoadfrom == ABResLoadFrom.PersistentDataPathAB) { abJson = FileHelper.ReadTxtToStr(GetABConfigLocalPath()); if (abJson.Equals("")) { AFLogger.e("AssetbundleConfig文件不存在或者内容为空"); return(false); } } else if (ABConfig.ABResLoadfrom == ABResLoadFrom.StreamingAssetAB) { string abConfigPath = "AF-ABForLocal/AF-InfoFile" + GetVersionStr() + "/" + GetStrByPlatform() + ABConfigName; TextAsset textAsset = ResManager.Instance.LoadSync(ResLoadInfo.Allocate(ResFromType.ResourcesRes, abConfigPath, false)) as TextAsset; abJson = textAsset.text; } config = SerializeHelper.FromJson <AssetBundleConfig>(abJson); break; case ConfigWritingMode.XML: XmlDocument xml = new XmlDocument(); MemoryStream ms = null; if (ABConfig.ABResLoadfrom == ABResLoadFrom.PersistentDataPathAB) { xml.Load(GetABConfigLocalPath()); } else { string abConfigPath = "AF-ABForLocal/AF-InfoFile" + GetVersionStr() + "/" + GetStrByPlatform() + ABConfigName; TextAsset textAsset = ResManager.Instance.LoadSync(ResLoadInfo.Allocate(ResFromType.ResourcesRes, abConfigPath, false)) as TextAsset; //由于编码问题,要设置编码方式 byte[] encodeString = System.Text.Encoding.UTF8.GetBytes(textAsset.text); //以流的形式来读取 ms = new MemoryStream(encodeString); xml.Load(ms); } if (xml == null) { AFLogger.e("AssetbundleConfig文件不存在或者内容为空"); return(false); } XmlSerializer xmldes = new XmlSerializer(typeof(AssetBundleConfig)); StringReader sr = new StringReader(xml.InnerXml); config = (AssetBundleConfig)xmldes.Deserialize(sr); if (ms != null) { ms.Close(); ms.Dispose(); } if (sr != null) { sr.Close(); sr.Dispose(); } break; } ResManager.Instance.CacheABConfig(config); return(true); }