/// <summary> /// 将filePath路径内容(对象转的json字符串)转换成对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="filePath"></param> /// <returns></returns> public static T ReadJsonTxtToObject <T>(string filePath) where T : class { if (JudgeFilePathExit(filePath)) { return(SerializeHelper.FromJson <T>(ReadTxtToStr(filePath))); } return(default(T)); }
/// <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)); }
void OnPlatformChange() { if (buildPlatform == BuildPlatform.IOS && xcodeSetting == null) { AppInfoConfig appInfoConfig = AssetDatabasex.LoadAssetOfType <AppInfoConfig>("AppInfoConfig"); xcodeSetting = new AFXcodeSetting(AssetDatabase.GetAssetPath(appInfoConfig)); TextAsset textAsset = AssetDatabasex.LoadAssetOfType <TextAsset>("XcodeSetting"); if (textAsset != null) { xcodeSetting.InitWithExit(SerializeHelper.FromJson <XcodeSetting>(textAsset.text)); } } }
protected override OdinMenuTree BuildMenuTree() { OdinMenuTree tree = new OdinMenuTree(); this.titleContent = new GUIContent("AFramework设置"); tree.Config.DrawSearchToolbar = true; tree.DefaultMenuStyle.Height = 30; tree.Selection.SupportsMultiSelect = false; AppInfoConfig appInfoConfig = AssetDatabasex.LoadAssetOfType <AppInfoConfig>("AppInfoConfig"); ABAndPathConfig aBAndPathConfig = new ABAndPathConfig(); AFXcodeSetting aFXcodeSetting = new AFXcodeSetting(AssetDatabase.GetAssetPath(appInfoConfig)); TextAsset textAsset = AssetDatabasex.LoadAssetOfType <TextAsset>("XcodeSetting"); if (textAsset != null) { aFXcodeSetting.InitWithExit(SerializeHelper.FromJson <XcodeSetting>(textAsset.text)); } APPBuildWindows buildAppWindows = AssetDatabasex.LoadAssetOfType <APPBuildWindows>("APPBuildWindows"); buildAppWindows.xcodeSetting = aFXcodeSetting; buildAppWindows.SyncSceneWithBuildSetting(); tree.Add("App基本信息配置", appInfoConfig); tree.Add("AB打包配置", aBAndPathConfig); tree.Add("APP打包配置", buildAppWindows); tree.Add("AR SDK配置", new ARSDKConfig()); tree.Add("Unity配置", AssetDatabasex.LoadAssetOfType <AFUnitySettingWindows>("AFUnitySetting")); tree.Add("UI配置", AssetDatabasex.LoadAssetOfType <AFUIConfig>("AFUIConfig")); tree.Add("多语言配置", AssetDatabasex.LoadAssetOfType <LanuageInfo>("LanuageInfo")); tree.Add("查找重复文件", new SearchDuplicateFiles()); tree.Add("批量更改Raycast Target选项", new ChangeRaycastTarget()); tree.Add("批量更换字体", new ChangeFont()); tree.Selection.SupportsMultiSelect = false; List <OdinMenuItem> menuItems = tree.MenuItems; OdinMenuTreeSelection odinMenuItems = tree.Selection; odinMenuItems.Add(menuItems[selectIndex]); return(tree); }
/// <summary> /// 版本文件下载回调 /// </summary> /// <param name="data"></param> /// <param name="downResult"></param> /// <param name="downError"></param> public void AppVersionCall(byte[] data, DownStatus downResult = DownStatus.Sucess, string downError = "") { if (downResult != DownStatus.Sucess) { AFLogger.e("下载Version文件未成功,请检查!"); return; } AppInfoConfig appInfoConfig = SerializeHelper.FromJson <AppInfoConfig>(System.Text.Encoding.UTF8.GetString(data)); double appV = 0; if (ABConfig.isDevelopOrOnlineAB) { appV = ABConfig.ABDevelopmentVersion; } else { appV = ABConfig.ABOnlineVersion; } if (appInfoConfig.AvailableABVersions.Contains(appV)) { if (appInfoConfig.NewABVersion.Contains(appV)) { versionStatus = APPVersionStatus.Newest; } else { versionStatus = APPVersionStatus.Update; } if (CheckABConfig()) { ABInit(default(byte[])); } } else { versionStatus = APPVersionStatus.Abandon; ABCheckInitFinish.InvokeGracefully(versionStatus); IsABCheckFinish = true; } }
public static void OnPostProcessBuild(BuildTarget target, string path) { if (BuildTarget.iOS != target) { return; } string[] s = AssetDatabasex.GetAssetPathStr("AppInfoConfig").Split('/'); string XcodeSettingPath = PathTool.ProjectPath; for (int i = 0; i < s.Length - 1; i++) { XcodeSettingPath += s[i] + "/"; } XcodeSettingPath += "Editor/XcodeSetting.txt"; if (XcodeSettingPath == "" || !FileHelper.JudgeFilePathExit(XcodeSettingPath)) { return; } XcodeSetting XcodeSetting = SerializeHelper.FromJson <XcodeSetting>(AssetDatabasex.LoadAssetOfType <TextAsset>("XcodeSetting").text); string projPath = PBXProject.GetPBXProjectPath(path); PBXProject pbx = new PBXProject(); pbx.ReadFromString(File.ReadAllText(projPath)); string guid = pbx.TargetGuidByName("Unity-iPhone"); iOSXcodeSet.SetTeamId(pbx, guid, XcodeSetting.TeamID); iOSXcodeSet.SetFrameworks(pbx, guid, XcodeSetting.frameworkToProjectList); iOSXcodeSet.SetLibs(pbx, guid, XcodeSetting.StaticlibraryDic); iOSXcodeSet.SetBuildProperty(pbx, guid, XcodeSetting.buildPropertyDic); //拷贝文件 iOSXcodeSet.CopyFiles(pbx, guid, XcodeSetting.CopyFileDic, path); iOSXcodeSet.CopyFolders(pbx, guid, XcodeSetting.CopyFolderDic, path); iOSXcodeSet.SetFilesCompileFlag(pbx, guid, XcodeSetting.FilesCompileFlagDIC); File.WriteAllText(projPath, pbx.WriteToString()); //修改Info.plist string plistPath = path + "/Info.plist"; iOSInfoPlist pListEditor = new iOSInfoPlist(plistPath); if (XcodeSetting.Version != "") { pListEditor.Update("CFBundleShortVersionString", XcodeSetting.Version); } if (XcodeSetting.build != "") { pListEditor.Update("CFBundleVersion", XcodeSetting.build); } if (XcodeSetting.BundleIdentifier != "" && XcodeSetting.BundleIdentifier.Split('.').Length >= 3) { pListEditor.Update("CFBundleIdentifier", XcodeSetting.BundleIdentifier); } foreach (var entry in XcodeSetting.pListDataDic) { pListEditor.Update(entry.Key, entry.Value, entry.infoType, entry.isAdd); } foreach (var urlScheme in XcodeSetting.urlSchemeDic) { pListEditor.UpdateUrlScheme(urlScheme.Key, urlScheme.Value, urlScheme.isAdd); } foreach (var whiteUrlScheme in XcodeSetting.appQueriesSchemeList) { pListEditor.UpdateLSApplicationQueriesScheme(whiteUrlScheme.Value, whiteUrlScheme.isAdd); } pListEditor.Save(); }
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); } }
/// <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); }