public static void UpdateABClass() { string ABConfigPath = AssetDatabasex.GetAssetPathStr("AF_ABConfig"); AF_ABConfig abConfig = null; if (!ABConfigPath.IsNotNullAndEmpty()) { abConfig = new AF_ABConfig(); ABConfigPath = "Assets/Scripts/AFData/AF-ConfigPath/AF_ABConfig.asset"; } else { abConfig = AssetDatabase.LoadAssetAtPath <AF_ABConfig>(ABConfigPath); } foreach (ARForProductType aBClass in System.Enum.GetValues(typeof(ARForProductType))) { if (abConfig != null && abConfig.JudgeClassExit(aBClass)) { continue; } AF_ABOneClass aF_ABOneClass = new AF_ABOneClass(); aF_ABOneClass.ABClassType = aBClass.ToString(); abConfig.m_AllClass.Add(aF_ABOneClass); } if (!FileHelper.JudgeFilePathExit(System.Environment.CurrentDirectory + "/" + ABConfigPath)) { AssetDatabase.CreateAsset(abConfig, ABConfigPath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
public ARSDKConfig() { #if AF_ARSDK_Vuforia vuforiaConfiguration = AssetDatabasex.LoadAssetOfType <VuforiaConfiguration>("VuforiaConfiguration"); #endif SDKsetting = AssetDatabasex.LoadAssetOfType <ARSDKSetting>("ARSDKSetting"); }
public ABAndPathConfig() { ABConfig = AssetDatabasex.LoadAssetOfType <AF_ABConfig>("AF_ABConfig"); pathConfig = AssetDatabasex.LoadAssetOfType <AFPathConfig>("AFPathConfig"); Debug.Log(ABConfig); EditorAssetPath.InitABBuildPath(ABConfig); pathConfig.ServerABPath = Environment.CurrentDirectory + "/AF-ABForServer"; pathConfig.PhoneABPath = Environment.CurrentDirectory + "/AF-ABForPhone"; pathConfig.StreamingABPath = Application.streamingAssetsPath + "/AF-ABForLocal"; pathConfig.PersistentPath = Application.persistentDataPath; pathConfig.StreamingAssetPath = Application.streamingAssetsPath; }
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)); } } }
public static void CreateUIManager() { GameObject uiRoot = GameObject.Instantiate(AssetDatabasex.LoadAssetOfType <GameObject>("UIRoot")); uiRoot.name = uiRoot.name.RemoveString("(Clone)"); AFUIConfig AFUIconfig = AssetDatabasex.LoadAssetOfType <AFUIConfig>("AFUIConfig"); CanvasScaler canvasScaler = uiRoot.transform.Find("MainCanvas").GetComponent <CanvasScaler>(); canvasScaler.referenceResolution = AFUIconfig.Resolution; canvasScaler.screenMatchMode = AFUIconfig.MatchMode; canvasScaler.matchWidthOrHeight = AFUIconfig.IsVertical ? 1 : 0; Screen.SetResolution((int)AFUIconfig.Resolution.x, (int)AFUIconfig.Resolution.y, false); }
/// <summary> /// 导入图片以及压缩图片将会调用 /// </summary> void OnPreprocessTexture() { AFUnitySettingWindows aFUnitySettingWindows = AssetDatabasex.LoadAssetOfType <AFUnitySettingWindows>("AFUnitySetting"); if (aFUnitySettingWindows.TextureSettingSwitch) { TextureImporter importer = (TextureImporter)assetImporter; importer.mipmapEnabled = false; importer.textureType = aFUnitySettingWindows.textureType; if (importer.textureType == TextureImporterType.Sprite) { importer.spritePackingTag = aFUnitySettingWindows.spritePackingTag; } TextureImporterPlatformSettings AndroidTextureImport = new TextureImporterPlatformSettings(); TextureImporterPlatformSettings iOSTextureImport = new TextureImporterPlatformSettings(); TextureImporterPlatformSettings DefaultTextureImport = new TextureImporterPlatformSettings(); string s = importer.assetPath.Substring(importer.assetPath.LastIndexOf('.') + 1); if (s == "png") { importer.alphaIsTransparency = true; AndroidTextureImport.format = aFUnitySettingWindows.AndroidImporterPlatformSettings.AlphaTextureImporterFormat; iOSTextureImport.format = aFUnitySettingWindows.iOSImporterPlatformSettings.AlphaTextureImporterFormat; DefaultTextureImport.format = aFUnitySettingWindows.defaultImporterPlatformSettings.AlphaTextureImporterFormat; } else { importer.alphaIsTransparency = false; AndroidTextureImport.format = aFUnitySettingWindows.AndroidImporterPlatformSettings.NoAlphaTextureImporterFormat; iOSTextureImport.format = aFUnitySettingWindows.iOSImporterPlatformSettings.NoAlphaTextureImporterFormat; DefaultTextureImport.format = aFUnitySettingWindows.defaultImporterPlatformSettings.NoAlphaTextureImporterFormat; } importer.isReadable = false; AndroidTextureImport.name = "Android"; AndroidTextureImport.overridden = aFUnitySettingWindows.AndroidImporterPlatformSettings.overridden; AndroidTextureImport.maxTextureSize = aFUnitySettingWindows.AndroidImporterPlatformSettings.maxTextureSize; importer.SetPlatformTextureSettings(AndroidTextureImport); iOSTextureImport.name = "iPhone"; iOSTextureImport.overridden = aFUnitySettingWindows.iOSImporterPlatformSettings.overridden; iOSTextureImport.maxTextureSize = aFUnitySettingWindows.iOSImporterPlatformSettings.maxTextureSize; importer.SetPlatformTextureSettings(iOSTextureImport); DefaultTextureImport.name = "Standalone"; DefaultTextureImport.overridden = aFUnitySettingWindows.defaultImporterPlatformSettings.overridden; DefaultTextureImport.maxTextureSize = aFUnitySettingWindows.defaultImporterPlatformSettings.maxTextureSize; importer.SetPlatformTextureSettings(DefaultTextureImport); } }
bool CommonBuildSetting() { if ((buildPlatform == BuildPlatform.Android && AndroidAPKPath == "") || (buildPlatform == BuildPlatform.IOS && XCodeProjectPath == "")) { AFLogger.EditorErrorLog("APP目标打包路径不能为空"); return(false); } EditorUserBuildSettings.development = DevelopmentBuild; PlayerSettings.productName = DisplayName; AF_ABConfig ABConfig = AssetDatabasex.LoadAssetOfType <AF_ABConfig>("AF_ABConfig"); return(true); }
public static void CheckSDKState() { if (EditorApplication.isPlayingOrWillChangePlaymode) { return; } if (AssetDatabasex.LoadAssetOfType <ARSDKSetting>("ARSDKSetting").IsCheckSdkStatus) { if (AF_SDKManager.AvailableScriptingDefineSymbolPredicateInfos != null) { AF_SDKManager.ManageScriptingDefineSymbols(); } else { AFLogger.e("AF_SDKManager.AvailableScriptingDefineSymbolPredicateInfos为空"); } } }
public static void OpenCustomHierarchy() { bool flag = Menu.GetChecked(menuItemPath); HierarchySwitch = !flag; AssetDatabasex.LoadAssetOfType <AFUnitySettingWindows>("AFUnitySetting").HierarchySwitch = !flag; Menu.SetChecked(menuItemPath, !flag); if (HierarchySwitch) { EditorApplication.hierarchyWindowItemOnGUI += HierarchWindowOnGui; } else { EditorApplication.hierarchyWindowItemOnGUI -= HierarchWindowOnGui; } EditorApplication.RepaintHierarchyWindow(); }
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); }
public void AutoAddTarget() { if (TargetDataSetName.IsNullOrEmpty()) { AFLogger.EditorErrorLog("DataSet名称为空!"); return; } AF_ABConfig ABConfig = AssetDatabasex.LoadAssetOfType <AF_ABConfig>("AF_ABConfig"); char[] t = ABConfig.defaultDataSetPath.ToCharArray(); string xmlPath = ABConfig.defaultDataSetPath; if (t[t.Length - 1] == '/') { xmlPath += TargetDataSetName + ".xml"; } else { xmlPath += "/" + TargetDataSetName + ".xml"; } if (xmlPath == "") { AFLogger.d("未找到DataSet对应的xml文件,请检查m_AllFileAB中是否有配置CategoryOfOwnership为" + ABClassType + "且isHasDataset为true"); return; } if (mImagetTargetInfo == null) { mImagetTargetInfo = new List <OneTargetInfo>(); } List <string> allRecogTarget = AFSDK_DataSetHandle.GetDataSetTarget(xmlPath); if (allRecogTarget == null) { AFLogger.EditorErrorLog("解析xml失败!"); return; } for (int j = mImagetTargetInfo.Count - 1; j >= 0; j--) { bool isNeedRemove = true; for (int i = allRecogTarget.Count - 1; i >= 0; i--) { if (mImagetTargetInfo[j].ImageTargetName.Equals(allRecogTarget[i])) { isNeedRemove = false; allRecogTarget.RemoveAt(i); break; } } if (isNeedRemove) { mImagetTargetInfo.RemoveAt(j); } } foreach (string recogName in allRecogTarget) { OneTargetInfo oneTargetInfo = new OneTargetInfo(); oneTargetInfo.ImageTargetName = recogName; oneTargetInfo.oneResInfo.ResScale = new Vector3(1, 1, 1); mImagetTargetInfo.Add(oneTargetInfo); } }
public static void Build() { m_BundleTargetPath = EditorAssetPath.ProjectPath + "AssetBundle/" + buildTarget.ToString() + "/"; AppInfoConfig appInfoConfig = AssetDatabasex.LoadAssetOfType <AppInfoConfig>("AppInfoConfig"); AF_ABConfig abConfig = AssetDatabasex.LoadAssetOfType <AF_ABConfig>("AF_ABConfig"); EditorAssetPath.InitABBuildPath(abConfig); //清空 m_ConfigFile.Clear(); m_AllFileAB.Clear(); m_AllFileDir.Clear(); m_AllPrefabDir.Clear(); string mTargetPath = EditorAssetPath.ABTargetPath; string mInfoPath = EditorAssetPath.ABInfoPath; if (abConfig.packageABType != PackageABType.PhoneAB) { mTargetPath = EditorAssetPath.ABTargetPath + buildTarget.ToString() + "/"; mInfoPath = EditorAssetPath.ABInfoPath + buildTarget.ToString() + "/"; } if (Directory.Exists(mTargetPath)) { FileUtil.DeleteFileOrDirectory(mTargetPath); } if (Directory.Exists(mInfoPath)) { FileUtil.DeleteFileOrDirectory(mInfoPath); } Directory.CreateDirectory(mInfoPath); Directory.CreateDirectory(mTargetPath); Directory.CreateDirectory(m_BundleTargetPath); //创建APP版本文件 FileHelper.CreatFile(EditorAssetPath.AppInfoPath, SerializeHelper.ToByteArray(appInfoConfig), true); Dictionary <string, bool> ClassToNeedPackageAB = new Dictionary <string, bool>(); for (int i = 0; i < abConfig.m_AllClass.Count; i++) { if (abConfig.m_AllClass[i].isSameAppType(abConfig.CurrentAppType)) { ClassToNeedPackageAB.Add(abConfig.m_AllClass[i].ABClassType, abConfig.m_AllClass[i].isNeedPackageAB); } } //剔除重复路径,将单个文件及文件夹的路径保存下来 //先处理文件夹再处理单个文件,因为有可能prefab依赖某个文件中的东西,所以要进行过滤 foreach (AF_OneAB oneAB in abConfig.m_AllFileAB) { bool isNeedPackageAB = false; for (int k = 0; k < oneAB.CategoryOfOwnership.Count; k++) { if (ClassToNeedPackageAB.ContainsKey(oneAB.CategoryOfOwnership[k]) && ClassToNeedPackageAB[oneAB.CategoryOfOwnership[k]]) { isNeedPackageAB = true; break; } } if (!isNeedPackageAB) { continue; } if (m_AllFileDir.ContainsKey(oneAB.mABIdentifier)) { AFLogger.EditorErrorLog("AB包配置名字重复,请检查!"); EditorUtility.ClearProgressBar(); } else { m_AllFileDir.Add(oneAB.mABIdentifier, oneAB.Path); //保存已打包的AB包路径 m_AllFileAB.Add(oneAB.Path); m_ConfigFile.Add(oneAB.Path); } } string[] AllPrefabsPath = abConfig.GetAllPrefabsPath(); if (AllPrefabsPath.Length > 0) { //获取路径下的所有prefab string[] allStr = AssetDatabase.FindAssets("t:Prefab", AllPrefabsPath); AFLogger.EditorInfoLog("获取的路径长度:" + allStr.Length); for (int i = 0; i < allStr.Length; i++) { bool isNeedPackageAB = false; for (int k = 0; k < abConfig.m_AllPrefabAB[i].CategoryOfOwnership.Count; k++) { if (ClassToNeedPackageAB.ContainsKey(abConfig.m_AllPrefabAB[i].CategoryOfOwnership[k]) && ClassToNeedPackageAB[abConfig.m_AllPrefabAB[i].CategoryOfOwnership[k]]) { isNeedPackageAB = true; break; } } if (!isNeedPackageAB) { continue; } //GUID转asset路径 string path = AssetDatabase.GUIDToAssetPath(allStr[i]); EditorUtility.DisplayProgressBar("查找Prefab", "Prefab:" + path, i * 1.0f / allStr.Length); m_ConfigFile.Add(path); if (!ContainAllFileAB(path)) { //获取资源的所有依赖 string[] allDepend = AssetDatabase.GetDependencies(path); List <string> allDependPath = new List <string>(); //遍历依赖文件 for (int j = 0; j < allDepend.Length; j++) { if (!ContainAllFileAB(allDepend[j]) && !allDepend[j].EndsWith(".cs", System.StringComparison.Ordinal)) { m_AllFileAB.Add(allDepend[j]); allDependPath.Add(allDepend[j]); } } if (m_AllPrefabDir.ContainsKey(abConfig.m_AllPrefabAB[i].mABIdentifier)) { AFLogger.EditorErrorLog("存在相同名字的Prefab!名字:" + abConfig.m_AllPrefabAB[i].mABIdentifier); EditorUtility.ClearProgressBar(); } else { m_AllPrefabDir.Add(abConfig.m_AllPrefabAB[i].mABIdentifier, allDependPath); } } } } //点击打包之后可以看见更改的文件的.meta文件改变 //文件夹设置ABName foreach (string name in m_AllFileDir.Keys) { SetABName(name, m_AllFileDir[name]); } //单个文件设置包名 foreach (string name in m_AllPrefabDir.Keys) { SetABName(name, m_AllPrefabDir[name]); } //打包 BunildAssetBundle(abConfig); //清除AB包名,因为上面更改了.meta文件,我们很多时候会使用svn或者git,有可能会导致一不小心上传特别乱 string[] oldABNames = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < oldABNames.Length; i++) { AssetDatabase.RemoveAssetBundleName(oldABNames[i], true); EditorUtility.DisplayProgressBar("清除AB包名", "名字:" + oldABNames[i], i * 1.0f / oldABNames.Length); } EditorUtility.ClearProgressBar(); //根据设置生成文件 ABBuildFinishEvent.BundleFinish(mTargetPath, m_BundleTargetPath, abConfig, mInfoPath, appInfoConfig); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); }
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(); }