/// <summary> /// 支付函数. /// </summary> /// <param name="iTarget">游戏对象.</param> /// <param name="iIapItemPrice">购买道具价格.</param> /// <param name="iIapItemName">购买道具名.</param> /// <param name="iIapItemCount">购买道具数量.</param> /// <param name="iOtherDiyInfo">其他自定义信息.</param> /// <param name="iNotifyUrl">支付结果通知URL(一般与游戏服务器上设置该URL).</param> /// <param name="iOnPayCompleted">支付完成回调函数.</param> protected override void SdkPay( GameObject iTarget, int iIapItemPrice, string iIapItemName, int iIapItemCount, string iOtherDiyInfo, string iNotifyUrl, Action <string> iOnPayCompleted) { Info("SdkPay()::Price:{0} Name:{1} Count:{2} OtherDIYInfo:{3} NotifyUrl:{4}/ Target:{5} Callback:{6}", iIapItemPrice, iIapItemName, iIapItemCount, iOtherDiyInfo, iNotifyUrl, iTarget.name, iOnPayCompleted.Method.Name); // 接入易接SDK的场合 if (SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK)) { OneSdkLibs.Instance.Pay( iTarget, iIapItemPrice, iIapItemName, iIapItemCount, iOtherDiyInfo, iNotifyUrl, iOnPayCompleted); } else { Error("SDKLogout():There is invalid options settings in sdk settings!!!"); } }
/// <summary> /// 添加玩家信息. /// </summary> /// <param name="iTarget">游戏对象.</param> /// <param name="iGameRank">游戏等级.</param> /// <param name="iGameRole">游戏角色.</param> /// <param name="iGameArea">游戏区.</param> /// <param name="iGameSociaty">游戏工会.</param> /// <param name="iOnCompleted">完成回调函数.</param> protected override void SdkAddPlayerInfo( GameObject iTarget, string iGameRank, string iGameRole, string iGameArea, string iGameSociaty, Action <string> iOnCompleted = null) { if (PlatformType.None == SysSettings.GetInstance().PlatformType) { Error("AddPlayerInfo():The platformType is none in AppSettings.asset file!!!"); return; } if (false == Application.isMobilePlatform) { return; } var jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); var jo = jc.GetStatic <AndroidJavaObject>("currentActivity"); jo.Call("UToA_AddPlayerInfo", iTarget.name, iGameRank, iGameRole, iGameArea, iGameSociaty, iOnCompleted?.Method.Name); }
/// <summary> /// 创建SDK角色信息. /// </summary> /// <returns>SDK角色信息.</returns> /// <param name="iRoleId">角色ID(必须为数字).</param> /// <param name="iRoleName">角色名(不能为空,不能为null).</param> /// <param name="iRoleLevel">角色等级(必须为数字,不能为0,默认1).</param> /// <param name="iZoneId">游戏区ID(必须为数字,不能为0,默认为1).</param> /// <param name="iZoneName">游戏区名(不能为空,不能为null).</param> /// <param name="iBalance">游戏币余额(必须为数字,默认0).</param> /// <param name="iVip">VIP等级(必须为数字,默认诶1).</param> /// <param name="iPartyName">当前所属帮派(不能为空,不能为null,默认:无帮派).</param> /// <param name="iRoleCTime">角色创建时间(单位:秒).</param> /// <param name="iRoleLevelMTime">角色等级变化时间(单位:秒).</param> public override SdkRoleBaseInfo SdkCreateRoleInfo( string iRoleId, string iRoleName, string iRoleLevel, string iZoneId, string iZoneName, string iBalance, string iVip, string iPartyName, string iRoleCTime, string iRoleLevelMTime) { // 接入易接SDK的场合 if (true != SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK)) { return(null); } var roleIfo = new OneSdkRoleInfo(); roleIfo.Reset(); roleIfo.id = iRoleId; roleIfo.name = iRoleName; roleIfo.level = iRoleLevel; roleIfo.zoneId = iZoneId; roleIfo.zoneName = iZoneName; roleIfo.balance = iBalance; // _roleIfo.Vip = iVip; // _roleIfo.PartyName = iPartyName; roleIfo.cTime = iRoleCTime; roleIfo.roleLevelMTime = iRoleLevelMTime; return(roleIfo); }
/// <summary> /// 输出打包信息(导出的XCode工程 打包ipa文件时使用). /// </summary> /// <param name="iProjectName">工程名.</param> /// <param name="iProjectVersion">工程版本.</param> private static void OutputBuildInfo( string iProjectName, string iProjectVersion) { const string funcBlock = "ProjectBuild:OutputBuildInfo()"; var buildId = SysSettings.GetInstance().BuildId; Loger.BuildStart(funcBlock); var filePath = $"{Application.dataPath}/../Shell/BuildInfo"; if (File.Exists(filePath)) { File.Delete(filePath); } var fStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); var buildInfo = $"{BuildParameters.BuildTime}:{iProjectName}:{iProjectVersion}:{buildId}"; Loger.BuildLog($"BuildInfo:{buildInfo}"); // 获得字节数组 var data = System.Text.Encoding.Default.GetBytes(buildInfo); // 写入 fStream.Write(data, 0, data.Length); // 清空缓冲区、关闭流 fStream.Flush(); fStream.Close(); fStream.Dispose(); Loger.BuildEnd(); }
/// <summary> /// 初始化Appliction. /// </summary> protected void InitApplicationInfo() { var manifestNode = GetManifestNode(); var manifestNodeTmp = manifestNode as XmlElement; if (manifestNodeTmp == null) { return; } // Android NameSpace AndroidNameSpace = GetNodeAttribute_s(manifestNodeTmp, "xmlns:android"); var appNode = GetApplicationNode(); var appNodeTmp = appNode as XmlElement; if (appNodeTmp == null) { return; } // Icon SetNodeAttribute(appNodeTmp, "icon", "@drawable/app_icon"); // debug SetNodeAttribute(appNodeTmp, "debuggable", BuildMode.Debug == SysSettings.GetInstance().BuildMode ? "true" : "false"); }
/// <summary> /// SDK解析用户信息. /// </summary> /// <returns>用户信息.</returns> /// <param name="iUserInfo">用户信息(Json格式数据).</param>> protected override SdkAccountBaseInfo SdkParserAccountInfo(string iUserInfo) { Info("SdkParserAccountInfo()"); // 接入易接SDK的场合 return(SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK) ? OneSdkLibs.Instance.ParserLoginResponseInfo(iUserInfo) : JsonUtility.FromJson <TiangeAccountInfo> (iUserInfo)); }
/// <summary> /// 更新等级信息(升级时). /// </summary> /// <param name="iRoleInfo">角色信息.</param> public override void SdkUpdateRoleInfoWhenEnterServer(SdkRoleBaseInfo iRoleInfo) { // 接入易接SDK的场合 if (SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK)) { OneSdkLibs.Instance.UpdateRoleInfoWhenEnterServer((OneSdkRoleInfo)iRoleInfo); } }
/// <summary> /// 退出. /// </summary> /// <param name="iTarget">游戏对象.</param> /// <param name="iOnExited">退出回调函数.</param> public override void SdkExit( GameObject iTarget = null, Action <string> iOnExited = null) { // 接入易接SDK的场合 if (SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK)) { OneSdkLibs.Instance.Exit(iTarget, iOnExited); } }
/// <summary> /// 应用. /// </summary> /// <param name="iUserInfo">用户数据.</param> public void Apply(OneSdkUserInfo iUserInfo) { Reset(); app = iUserInfo.productCode; sdk = iUserInfo.channelId; uin = iUserInfo.channelUserId; sess = iUserInfo.token; channel = iUserInfo.channelId; platform = SysSettings.GetInstance().PlatformType.ToString(); option = "OneSDK"; }
/// <summary> /// 登出. /// </summary> protected override void SdkLogout() { Info("SdkLogout()"); // 接入易接SDK的场合 if (SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK)) { OneSdkLibs.Instance.Logout(); } else { Error("SDKLogout():There is invalid options settings in sdk settings!!!"); } }
private static void InitForAndroidBuild() { // 初始化打包信息 BuildSettings.GetInstance(BuildSettings.AssetFileDir); #if UNITY_ANDROID // 设定选项 // 天鸽的场合 if (PlatformType.Tiange == SysSettings.GetInstance().PlatformType) { // 初始化SDK设定信息&导入最新 TiangeSdkSettings.GetInstance(TiangeSdkSettings.AssetFileDir).ImportFromJsonFile(); Loger.BuildLog("TiangeSdkSettings -> ImportFromJsonFile()."); var oneSDk = TiangeSdkSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK); var metaDatasCount = TiangeSdkSettings.GetInstance().data.Options.OneSDK.metaDatas.Count; Loger.BuildLog($"TiangeSdkSettings::OneSDK:{oneSDk}(MetaData:{metaDatasCount})."); TiangeSdkSettings.GetInstance().data.Options.data = SysSettings.GetInstance().data.Options.data; } // 清空Plugins/Android目录 ClearPluginsAndroid(); // 重置Plugins/Android ResetPluginsAndroid(); // 设置相关AndroidSDK相关设定 var androidSdk = GetCurAndroidSdkSetting(); if (androidSdk != null) { var gameName = SysSettings.GetInstance().BuildName; var packageName = SysSettings.GetInstance().BuildId; // 打包Android(apk文件)之前,提前应用设定 androidSdk.PreApplyAndroidBuild(gameName, packageName); } else { Loger.BuildWarningLog("Android SDK invalid!!"); } #endif // 刷新 UtilsAsset.AssetsRefresh(); }
/// <summary> /// 取得当前AndroidSDK设定信息. /// </summary> /// <returns>当前AndroidSDK设定信息.</returns> private static IAndroidSdkSettings GetCurAndroidSdkSetting() { IAndroidSdkSettings settings = null; // 平台类型 var platformType = SysSettings.GetInstance().PlatformType; Loger.BuildLog($"PlatformType:{platformType}."); switch (platformType) { // 华为 case PlatformType.Huawei: { settings = HuaweiSdkSettings.GetInstance(HuaweiSdkSettings.AssetFileDir); } break; // 天鸽 case PlatformType.Tiange: { settings = TiangeSdkSettings.GetInstance(TiangeSdkSettings.AssetFileDir); } break; case PlatformType.Android: break; case PlatformType.None: break; case PlatformType.iOS: break; default: { // 清空/Plugins/Android下的文件 } break; } return(settings); }
/// <summary> /// 登录. /// </summary> /// <param name="iTarget">登陆启动的目标对象.</param> /// <param name="iOnCompleted">完成回调函数.</param> protected override void SdkLogin( GameObject iTarget, Action <string> iOnCompleted) { Info("SdkLogin()"); // 接入易接SDK的场合 if (SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK)) { OneSdkLibs.Instance.Login( iTarget, iOnCompleted, LoginCheckBaseUrl, LoginCheckCallback, OnLoginCheckSucceeded, OnLoginCheckFailed, AutoReloginMaxCount, AutoReloginCallback); } else { Error("SDKLogin():There is invalid options settings in sdk settings!!!"); } }
/// <summary> /// 解析支付信息. /// </summary> /// <returns>支付信息.</returns> /// <param name="iPayInfo">支付信息(Json格式数据).</param> /// <param name="iOnPaymentSucceeded">支付成功回调函数.</param> protected override SdkPaymentBaseInfo SdkParserPaymentInfo( string iPayInfo, Action <SdkAccountBaseInfo, string> iOnPaymentSucceeded) { Info("SdkParserPaymentInfo()"); #if IAP_UI_TEST iOnPaymentSucceeded(null, null); return(null); #else if (null == iOnPaymentSucceeded) { Warning("SDKParserPaymentInfo()::OnPaymentSucceeded is null!!!"); } // 接入易接SDK的场合 return(SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK) ? OneSdkLibs.Instance.ParserPayResponseInfo(iPayInfo, iOnPaymentSucceeded) : UtilsJson <TiangePaymentInfo> .ConvertFromJsonString(iPayInfo)); #endif }
/// <summary> /// 取得安卓SDK实例. /// </summary> /// <returns>The android SDK instance.</returns> private AndroidSdkBase GetAndroidSdkInstance() { AndroidSdkBase objRet = null; var _platformType = SysSettings.GetInstance().PlatformType; switch (_platformType) { case PlatformType.Huawei: { objRet = new HuaweiSdk(); } break; case PlatformType.Tiange: { objRet = new TiangeSDK(); } break; case PlatformType.None: break; case PlatformType.iOS: break; case PlatformType.Android: break; default: { Error("GetAndroidSDKInstance():The platformType is invalid setting in buildinfo.asset!!!(TPlatformType:{0})", _platformType); } break; } return(objRet); }
/// <summary> /// 打包资源文件 /// </summary> /// <param name="iBuildTarget">打包目标.</param> /// <param name="iNeedCompress">压缩标识位.</param> private static void BuildAssetBundle(BuildTarget iBuildTarget, bool iNeedCompress = false) { const string funcBlock = "AssetBundlesBuild:BuildAssetBundle()"; Loger.BuildStart(funcBlock); Loger.BuildLog($"BuildTarget:{iBuildTarget} NeedCompress:{iNeedCompress}"); // 清空上传信息 BundlesResult.GetInstance().Clear(); // 打包名 BundlesResult.GetInstance().BuildName = SysSettings.GetInstance().BuildName; // 打包名 BundlesResult.GetInstance().AppVersion = SysSettings.GetInstance().BuildVersion; // 打包名 BundlesResult.GetInstance().CheckMode = CheckMode.CustomMd5; // 设置上传的打包类型 BundlesResult.GetInstance().BuildTarget = iBuildTarget.ToString(); var bcConfig = BundlesConfig.GetInstance(); if (null == bcConfig || 0 >= bcConfig.Resources.Count) { Loger.BuildErrorLog("BundlesConfig is invalid!!!"); return; } // 清空依赖关系列表 var bundlesMap = BundlesMap.GetInstance(); if (null == bundlesMap) { Loger.BuildErrorLog("BundlesMap is invalid!!!"); return; } bundlesMap.Clear(); var allConfig = bcConfig.Resources; // make bundle config foreach (var bc in allConfig) { switch (bc.mode) { // filter file case BundleMode.OneDir: { var bundleId = BundlesMap.GetBundleId(bc.path); var bm = BundlesMap.GetOrCreateBundlesMap(bundleId); bm.id = bundleId; bm.path = bc.path; // 取得当前目录的文件列表 var files = GetAllFiles(bc.path); // 遍历文件列表 foreach (var file in files) { // .DS_Store文件 if (file.EndsWith(".DS_Store")) { continue; } // *.meta文件 if (file.EndsWith(".meta")) { continue; } // 若为忽略文件,则跳过 if (bcConfig.IsIgnoreFile(bc, file)) { bm.RemoveIgnorFile(file); continue; } bm.AddFile(file); } bundlesMap.Maps.Add(bm); break; } case BundleMode.SceneOneToOne: { // 取得当前目录的文件列表 var files = GetAllFiles(bc.path); foreach (var file in files) { // .DS_Store文件 if (file.EndsWith(".DS_Store")) { continue; } // *.meta文件 if (file.EndsWith(".meta")) { continue; } // 若非场景文件,则跳过 if (file.EndsWith(".unity") == false) { continue; } // 若为忽略文件,则跳过 var bundleId = BundlesMap.GetBundleId(file); var bm = BundlesMap.GetOrCreateBundlesMap(bundleId); if (bcConfig.IsIgnoreFile(bc, file)) { bm.RemoveIgnorFile(file); continue; } bm.id = bundleId; bm.path = bc.path; bm.type = BundleType.Scene; bm.AddFile(file); bundlesMap.Maps.Add(bm); } break; } case BundleMode.FileOneToOne: { // 取得当前目录的文件列表 var files = GetAllFiles(bc.path); foreach (var file in files) { // .DS_Store文件 if (file.EndsWith(".DS_Store")) { continue; } // *.meta文件 if (file.EndsWith(".meta")) { continue; } // 若为忽略文件,则跳过 var bundleId = BundlesMap.GetBundleId(file); var bm = BundlesMap.GetOrCreateBundlesMap(bundleId); if (bcConfig.IsIgnoreFile(bc, file)) { bm.RemoveIgnorFile(file); continue; } bm.id = bundleId; bm.path = bc.path; bm.AddFile(file); bundlesMap.Maps.Add(bm); } break; } case BundleMode.TopDirOneToOne: { // 取得目录列表 var directories = Directory.GetDirectories(bc.path); if (directories.Length <= 0) { Loger.BuildWarningLog($"The no subfolder in this path!!!(dir:{bc.path})"); continue; } foreach (var dir in directories) { // 取得当前目录的文件列表 var files = GetAllFiles(dir); var bundleId = BundlesMap.GetBundleId(dir); if (string.IsNullOrEmpty(bundleId)) { continue; } var bm = BundlesMap.GetOrCreateBundlesMap(bundleId); bm.id = bundleId; bm.path = bc.path; foreach (var file in files) { // .DS_Store文件 if (file.EndsWith(".DS_Store")) { continue; } // *.meta文件 if (file.EndsWith(".meta")) { continue; } // 若为忽略文件,则跳过 if (bcConfig.IsIgnoreFile(bc, file)) { bm.RemoveIgnorFile(file); continue; } bm.AddFile(file); } bundlesMap.Maps.Add(bm); } break; } } } // 目录检测 var checkDir = BundlesResult.GetInstance().BundlesOutputDir; if (Directory.Exists(checkDir) == false) { Directory.CreateDirectory(checkDir); } checkDir = BundlesResult.GetInstance().BundlesOutputDirOfNormal; if (Directory.Exists(checkDir) == false) { Directory.CreateDirectory(checkDir); } checkDir = BundlesResult.GetInstance().BundlesOutputDirOfScene; if (Directory.Exists(checkDir) == false) { Directory.CreateDirectory(checkDir); } var succeeded = false; AssetBundleManifest result = null; string[] allAssets = null; // 一般Bundles try { var targets = bundlesMap.GetAllNormalBundleTargets(); const BuildAssetBundleOptions options = BuildAssetBundleOptions.None; result = BuildPipeline.BuildAssetBundles( BundlesResult.GetInstance().BundlesOutputDirOfNormal, targets, options, iBuildTarget); Loger.BuildLog(" -> BuildPipeline.BuildAssetBundles"); if (result != null) { allAssets = result.GetAllAssetBundles(); if (allAssets != null && targets.Length == allAssets.Length) { succeeded = true; } } } catch (Exception exp) { Loger.BuildErrorLog($"BuildAssetBundles Detail : {exp.Message}"); succeeded = false; } // 更新导出标志位 if (succeeded) { Loger.BuildLog(" -> BundlesConfig.UpdateBundleStateWhenCompleted"); var hashCodes = new Dictionary <string, string>(); foreach (var asset in allAssets) { var hashCode = result.GetAssetBundleHash(asset); if (string.IsNullOrEmpty(hashCode.ToString())) { continue; } var fileSuffix = BundlesResult.GetInstance().FileSuffix; var key = asset; if (string.IsNullOrEmpty(fileSuffix) == false) { fileSuffix = fileSuffix.ToLower(); fileSuffix = $".{fileSuffix}"; key = key.Replace(fileSuffix, ""); } hashCodes[key] = hashCode.ToString(); } // 初始化检测信息(Hash Code) bundlesMap.PushBundleResult(BundleType.Normal, hashCodes); Loger.BuildLog(" -> BundlesMap.UpdateUploadList Normal"); } // Scene Bundles var targetScenes = bundlesMap.GetAllSceneBundleTargets(); if (targetScenes != null && targetScenes.Count > 0) { foreach (var scene in targetScenes) { if (scene?.GetAllTargets() == null || scene.GetAllTargets().Length <= 0) { continue; } try { var options = BuildOptions.BuildAdditionalStreamedScenes; if (BuildMode.Debug == SysSettings.GetInstance().BuildMode) { options |= BuildOptions.Development; } var sceneState = BuildPipeline.BuildPlayer( scene.GetAllTargets(), BundlesResult.GetLocalSceneBundleFilePath(scene.BundleId), iBuildTarget, options); Loger.BuildLog($" -> BuildPipeline.BuildStreamedSceneAssetBundle(State:{sceneState})"); } catch (Exception exp) { Loger.BuildErrorLog($"BuildStreamedSceneAssetBundle Detail:{exp.Message}"); succeeded = false; } } } // 更新导出标志位 if (succeeded) { Loger.BuildLog(" -> BundlesConfig.UpdateBundleStateWhenCompleted"); // 初始化检测信息(Hash Code) bundlesMap.PushBundleResult(BundleType.Scene); Loger.BuildLog(" -> BundlesMap.UpdateUploadList Scene"); } SysSettings.GetInstance().ExportToJsonFile(); Loger.BuildLog(" -> BuildInfo.ExportToJsonFile"); Loger.BuildEnd(); }
private static void CreateUploadShellByCurl() { const string funcBlock = "AssetBundlesBuild:CreateUploadShellByCurl()"; Loger.BuildStart(funcBlock); var filePath = $"{Application.dataPath}/../Shell/UploadABByCurl.sh"; if (File.Exists(filePath)) { File.Delete(filePath); } var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); var sw = new StreamWriter(fs); // 写入文件头 sw.WriteLine("#!/bin/bash"); sw.Flush(); sw.WriteLine(""); sw.Flush(); // 设定变量 sw.WriteLine("# 上传根目录"); sw.WriteLine("ROOT_DIR=bundles"); sw.Flush(); sw.WriteLine("# 本地上传路径"); sw.WriteLine("UPLOAD_FROM_ROOT_DIR={0}/StreamingAssets", Application.dataPath); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 上传目标平台"); sw.WriteLine("BUILD_TARGET={0}", BundlesResult.GetInstance().BuildTarget); sw.Flush(); sw.WriteLine("# App Version"); sw.WriteLine("APP_VERSION={0}", BundlesResult.GetInstance().AppVersion); sw.Flush(); var resourceServer = SysSettings.GetInstance().data.network.resourceServer; sw.WriteLine("# 认证"); sw.WriteLine("UPLOAD_SERVER_ROOT_URL=\"ftp://{0}:{1}\"", resourceServer.ipAddresss, resourceServer.portNo); sw.WriteLine("VERIFY_CODE={0}:{1}", resourceServer.accountId, resourceServer.pwd); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 检测上传目录"); sw.WriteLine("# $1 上传目录"); sw.WriteLine("checkUploadDir()"); sw.WriteLine("{"); sw.WriteLine(" # 检测URL"); sw.WriteLine(" CHK_URL=${UPLOAD_SERVER_ROOT_URL}"); sw.WriteLine(" "); sw.WriteLine(" # 目标文件夹名"); sw.WriteLine(" CHK_DIRS=$1"); sw.WriteLine(" CHK_DIRS_ARRAY=(${CHK_DIRS//\\// })"); sw.WriteLine(" CHK_DIRS_SIZE=${#CHK_DIRS_ARRAY[@]}"); sw.WriteLine(" if [ $CHK_DIRS_SIZE -ge 1 ]; then"); sw.WriteLine(" "); sw.WriteLine(" # 检测目录"); sw.WriteLine(" CHK_DIR=${CHK_DIRS_ARRAY[CHK_DIRS_SIZE-1]}"); sw.WriteLine(" PREV_DIR=${CHK_DIRS}"); sw.WriteLine(" "); sw.WriteLine(" # 检测"); sw.WriteLine(" if [ -n $CHK_DIR ]; then "); sw.WriteLine(" # 取得之前目录"); sw.WriteLine(" if [ $CHK_DIRS_SIZE -gt 1 ]; then"); sw.WriteLine(" PREV_DIR=${CHK_DIRS/\\/$CHK_DIR/}"); sw.WriteLine(" else"); sw.WriteLine(" PREV_DIR=${CHK_DIRS/$CHK_DIR/}"); sw.WriteLine(" fi"); sw.WriteLine(" "); sw.WriteLine(" # 检测路径"); sw.WriteLine(" if [ -z $PREV_DIR ]; then"); sw.WriteLine(" CHK_URL=\"${CHK_URL}/\""); sw.WriteLine(" else"); sw.WriteLine(" CHK_URL=\"${CHK_URL}/${PREV_DIR}/\""); sw.WriteLine(" fi"); sw.WriteLine(" "); sw.WriteLine(" # 检测文件夹"); sw.WriteLine(" CHK_INFO=`curl ${CHK_URL} -u ${VERIFY_CODE}`"); sw.WriteLine(" # 已存在目录"); sw.WriteLine(" EXIST_DIRS=(${CHK_INFO// / })"); sw.WriteLine(" # 存在标识位"); sw.WriteLine(" EXIST_FLG=0"); sw.WriteLine(" for DIR in ${EXIST_DIRS[@]}"); sw.WriteLine(" do"); sw.WriteLine(" if [ \"${DIR}\" == \"${CHK_DIR}\" ]; then"); sw.WriteLine(" EXIST_FLG=1"); sw.WriteLine(" break"); sw.WriteLine(" fi"); sw.WriteLine(" "); sw.WriteLine(" done"); sw.WriteLine(" "); sw.WriteLine(" if [ $EXIST_FLG -le 0 ]; then"); sw.WriteLine(" curl ${CHK_URL} -u ${VERIFY_CODE} -X \"MKD ${CHK_DIR}\""); sw.WriteLine(" echo \"Create Directory : ${CHK_URL}${CHK_DIR}\""); sw.WriteLine(" fi"); sw.WriteLine(" "); sw.WriteLine(" fi"); sw.WriteLine(" else"); sw.WriteLine(" echo \"[Error] The dirs for check is not invalid!!(Check Dir=${CHK_DIRS})\""); sw.WriteLine(" fi"); sw.WriteLine("}"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# # 文件上传函数"); sw.WriteLine("# $1 远程上传目录"); sw.WriteLine("# $2 本地上传文件路径"); sw.WriteLine("uploadFile()"); sw.WriteLine("{"); sw.WriteLine(" # 远程上传目标目录"); sw.WriteLine(" UPLOAD_DIR=$1"); sw.WriteLine(" # 本地上传文件"); sw.WriteLine(" LOCAL_FILE_PATH=$2"); sw.WriteLine(" "); sw.WriteLine(" # 检测URL"); sw.WriteLine(" UPLOAD_URL=${UPLOAD_SERVER_ROOT_URL}/${UPLOAD_DIR}"); sw.WriteLine(" #curl ${UPLOAD_URL} -v -u ${VERIFY_CODE} -T \"${LOCAL_FILE_PATH}\""); sw.WriteLine(" echo \"${LOCAL_FILE_PATH}\""); sw.WriteLine(" curl ${UPLOAD_URL} -u ${VERIFY_CODE} -T \"${LOCAL_FILE_PATH}\""); sw.WriteLine("}"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 检测目录"); sw.WriteLine("checkUploadDir $ROOT_DIR"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 上传资源文件"); var targets = BundlesResult.GetInstance().Targets; var normals = targets .Where(iO => BundleType.Normal == iO.bundleType) .OrderBy(iO => iO.no) .ToArray(); if (0 < normals.Length) { sw.WriteLine("# 检测一般文件目录"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0}", BundleType.Normal); sw.WriteLine("# 一般文件"); foreach (var loop in normals) { var fileName = BundlesResult.GetLocalBundleFileName(loop.id, loop.fileType); sw.WriteLine("uploadFile $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0}/ $UPLOAD_FROM_ROOT_DIR/{0}/{1}", BundleType.Normal, fileName); } sw.WriteLine(""); sw.Flush(); } var scenes = targets .Where(iO => BundleType.Scene == iO.bundleType) .OrderBy(iO => iO.no) .ToArray(); if (0 < scenes.Length) { sw.WriteLine("# 检测场景文件目录"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0}", BundleType.Scene); sw.WriteLine("# 场景文件"); foreach (var loop in scenes) { var fileName = BundlesResult.GetLocalBundleFileName(loop.id, loop.fileType); sw.WriteLine("uploadFile $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0}/ $UPLOAD_FROM_ROOT_DIR/{0}/{1}", BundleType.Scene, fileName); } sw.WriteLine(""); sw.Flush(); } if (0 < targets.Count) { sw.WriteLine("# 清空上传文件"); sw.WriteLine("rm -rfv $UPLOAD_FROM_ROOT_DIR"); sw.WriteLine(""); sw.Flush(); } sw.Close(); sw.Dispose(); fs.Close(); fs.Dispose(); Loger.BuildEnd(); }
public static void CreateShellOfRefreshCdn() { const string funcBlock = "AssetBundlesBuild:CreateShellOfRefreshCdn()"; Loger.BuildStart(funcBlock); var cdn = SysSettings.GetInstance().data.network.cdnServer; if (null == cdn) { Loger.BuildErrorLog("CreateShellOfRefreshCDN()::CDN Server info is invalid!!!"); Loger.BuildEnd(); return; } var filePath = $"{Application.dataPath}/../Shell/RefreshCDN.sh"; if (File.Exists(filePath)) { File.Delete(filePath); } var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); var sw = new StreamWriter(fs); // 写入文件头 sw.WriteLine("#!/bin/bash"); sw.Flush(); sw.WriteLine(""); sw.Flush(); // 设定变量 sw.WriteLine("# 用户名"); if (string.IsNullOrEmpty(cdn.userName)) { Loger.BuildErrorLog("CreateShellOfRefreshCDN()::The username of CDN Server info is invalid or empty!!!"); } sw.WriteLine("username=\"{0}\"", cdn.userName); sw.WriteLine("# APIKey"); if (string.IsNullOrEmpty(cdn.apiKey)) { Loger.BuildErrorLog("CreateShellOfRefreshCDN()::The apikey of CDN Server info is invalid or empty!!!"); } sw.WriteLine("apiKey=\"{0}\"", cdn.apiKey); sw.Flush(); sw.WriteLine("# 刷新时间"); sw.WriteLine("date=`env LANG=\"en_US.UTF-8\" date -u \"+%a, %d %b %Y %H:%M:%S GMT\"`"); sw.WriteLine("# 密码"); sw.WriteLine("password=`echo -en \"$date\" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64`"); sw.Flush(); sw.WriteLine("# 开始刷新"); if (string.IsNullOrEmpty(cdn.cdnUrl)) { Loger.BuildErrorLog("CreateShellOfRefreshCDN()::The url of CDN Server info is invalid or empty!!!"); } sw.WriteLine("curl -i --url \"{0}\" \\", cdn.cdnUrl); sw.WriteLine("-X \"POST\" \\"); sw.WriteLine("-u \"$username:$password\" \\"); sw.WriteLine("-H \"Date:$date\" \\"); sw.WriteLine("-H \"Content-Type: application/json\" \\"); sw.WriteLine("-d '{"); sw.WriteLine(" \"urlAction\":\"delete\","); sw.WriteLine(" \"dirs\": ["); for (var idx = 0; idx < cdn.refreshUrls.Count; ++idx) { sw.WriteLine(0 == idx ? $" \"{cdn.refreshUrls[idx]}\"" : $" , \"{cdn.refreshUrls[idx]}\""); } sw.WriteLine(" ]"); sw.WriteLine(" }'"); sw.Flush(); sw.Close(); sw.Dispose(); fs.Close(); fs.Dispose(); Loger.BuildEnd(); }
/// <summary> /// 创建角色信息. /// </summary> /// <returns>角色信息.</returns> public static SdkRoleBaseInfo CreateRoleInfo() { return(true != SysSettings.GetInstance().data.Options.IsOptionValid(SDKOptions.OneSDK) ? null : new OneSdkRoleInfo()); }
public static void ExportXcodeProject() { // 输出路径 // 游戏输出目录(Android):{OutputDir}/Android/{ProjectName} var outputDir = GetOutputDir( BuildTarget.iOS, BuildParameters.BuildNumber, BuildParameters.OutputDir); if (outputDir == null) { Loger.BuildErrorLog($"Create Dir Failed.!!(Dir:{BuildParameters.OutputDir})"); throw new ApplicationException(); } const string funcBlock = "ProjectBuild:ExportXcodeProject()"; Loger.BuildStart(funcBlock); // 设定打包信息 SetBuildInfoFromParameters(false); // 平台类型 SysSettings.GetInstance().PlatformType = PlatformType.iOS; var buildMode = SysSettings.GetInstance().BuildMode; Loger.BuildLog($"BuildMode:{buildMode}"); // 初始化 InitForExportXcodeProject(); Loger.BuildLog(" --> InitForExportXcodeProject()"); // 预定义宏 //PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS, "GAMELINK"); // 打包选项 var buildOptionTmp = BuildOptions.None; if (BuildMode.Debug == buildMode) { buildOptionTmp |= BuildOptions.Development; buildOptionTmp |= BuildOptions.AllowDebugging; buildOptionTmp |= BuildOptions.ConnectWithProfiler; } else { var isCheatMode = BuildParameters.IsCheatMode; if (isCheatMode) { buildOptionTmp |= BuildOptions.Development; } } Loger.BuildLog($"BuildOption:{buildOptionTmp}"); // 工程名 var projectName = SysSettings.GetInstance().BuildName; Loger.BuildLog($"ProjectName:{projectName}"); // 游戏名字 var gameName = BuildParameters.GameName; if (string.IsNullOrEmpty(gameName)) { gameName = projectName; } PlayerSettings.iOS.applicationDisplayName = gameName; Loger.BuildLog($"GameName:{gameName}"); // BuildID var buildId = SysSettings.GetInstance().BuildId; if (false == string.IsNullOrEmpty(buildId)) { #if UNITY_5_5_OR_NEWER PlayerSettings.applicationIdentifier = buildId; #else PlayerSettings.bundleIdentifier = buildId; #endif } Loger.BuildLog($"BuildID:{buildId}"); // 版本号 var buildVersion = SysSettings.GetInstance().BuildVersion; PlayerSettings.bundleVersion = buildVersion; Loger.BuildLog($"BuildVersion:{buildVersion}"); // 前端服务器Host var webHost = SysSettings.GetInstance().data.network.webServer.host; Loger.BuildLog($"WebServer:Host:{webHost}"); // 前端服务器端口号 var webPortNo = SysSettings.GetInstance().data.network.webServer.portNo; Loger.BuildLog($"WebServer:PortNo:{webPortNo}"); // 输出宏定义 var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.iOS); Loger.BuildLog($"Defines:{defines}"); // XCode工程目录 var xcodeProject = outputDir; // 输出打包信息 OutputBuildInfo(buildVersion, projectName); // 开发者模式 if (BuildOptions.Development == buildOptionTmp) { // 打包之前,将非资源对象,临时移动到临时文件夹 //AssetBundles.Common.MoveUnResources(); } // 打包成XCode工程目录 var report = BuildPipeline.BuildPlayer( GetBuildScenes(), xcodeProject, BuildTarget.iOS, buildOptionTmp); // 开发者模式 if (BuildOptions.Development == buildOptionTmp) { // 恢复非资源性文件 //AssetBundles.Common.MoveBackUnResources(); } #if UNITY_2018_3 || UNITY_2018_3_OR_NEWER // 存在错误则,打包编译失败 if (0 > report.summary.totalErrors) { Loger.BuildErrorLog($"Android Build Failed!!!(error:{report.summary})"); Loger.BuildEnd(); throw new ApplicationException(); } #else // 存在错误则,打包编译失败 if (false == string.IsNullOrEmpty(report)) { Loger.BuildErrorLog($"iOS Build Failed!!!(error:{report})"); Loger.BuildEnd(); throw new ApplicationException(); } #endif Loger.BuildLog("iOS Build Succeeded."); Loger.BuildEnd(); }
/// <summary> /// 生成上传用的Shell脚本 /// </summary> /// <param name="iBuildNo">打包No</param> /// <param name="iTarget">打包目标类型(iOS/Android)</param> /// <param name="iPath">ipa/apk输出目录</param> private static void CreateUploadShell(int iBuildNo, BuildTarget iTarget, string iPath) { const string funcBlock = "AssetBundlesBuild:CreateUploadShell()"; Loger.BuildStart(funcBlock); // ReSharper disable HeapView.BoxingAllocation var filePath = $"{Application.dataPath}/../Shell/Upload{iTarget}.sh"; // ReSharper restore HeapView.BoxingAllocation if (File.Exists(filePath)) { File.Delete(filePath); } var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); var sw = new StreamWriter(fs); // 写入文件头 sw.WriteLine("#!/bin/bash"); sw.Flush(); sw.WriteLine(""); sw.Flush(); // 设定变量 sw.WriteLine("# 打包No"); sw.WriteLine("BUILD_NO={0}", iBuildNo); sw.Flush(); sw.WriteLine("# 上传根目录"); sw.WriteLine("ROOT_DIR=\"Download\""); sw.Flush(); sw.WriteLine("# 平台类型"); sw.WriteLine("BUILD_TARGET={0}", iTarget); sw.Flush(); sw.WriteLine("# 本地上传路径"); sw.WriteLine("UPLOAD_FROM_ROOT_DIR={0}/StreamingAssets", Application.dataPath); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# App Version"); sw.WriteLine("APP_VERSION={0}", SysSettings.GetInstance().BuildVersion); sw.Flush(); var resourceServer = SysSettings.GetInstance().data.network.resourceServer; sw.WriteLine("# 认证"); sw.WriteLine("UPLOAD_SERVER_ROOT_URL=\"ftp://{0}:{1}\"", resourceServer.ipAddresss, resourceServer.portNo); sw.WriteLine("VERIFY_CODE={0}:{1}", resourceServer.accountId, resourceServer.pwd); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 检测上传目录"); sw.WriteLine("# $1 上传目录"); sw.WriteLine("checkUploadDir()"); sw.WriteLine("{"); sw.WriteLine(" # 检测URL"); sw.WriteLine(" CHK_URL=${UPLOAD_SERVER_ROOT_URL}"); sw.WriteLine(" "); sw.WriteLine(" # 目标文件夹名"); sw.WriteLine(" CHK_DIRS=$1"); sw.WriteLine(" CHK_DIRS_ARRAY=(${CHK_DIRS//\\// })"); sw.WriteLine(" CHK_DIRS_SIZE=${#CHK_DIRS_ARRAY[@]}"); sw.WriteLine(" if [ $CHK_DIRS_SIZE -ge 1 ]; then"); sw.WriteLine(" "); sw.WriteLine(" # 检测目录"); sw.WriteLine(" CHK_DIR=${CHK_DIRS_ARRAY[CHK_DIRS_SIZE-1]}"); sw.WriteLine(" PREV_DIR=${CHK_DIRS}"); sw.WriteLine(" "); sw.WriteLine(" # 检测"); sw.WriteLine(" if [ -n $CHK_DIR ]; then "); sw.WriteLine(" # 取得之前目录"); sw.WriteLine(" if [ $CHK_DIRS_SIZE -gt 1 ]; then"); sw.WriteLine(" PREV_DIR=${CHK_DIRS/\\/$CHK_DIR/}"); sw.WriteLine(" else"); sw.WriteLine(" PREV_DIR=${CHK_DIRS/$CHK_DIR/}"); sw.WriteLine(" fi"); sw.WriteLine(" "); sw.WriteLine(" # 检测路径"); sw.WriteLine(" if [ -z $PREV_DIR ]; then"); sw.WriteLine(" CHK_URL=\"${CHK_URL}/\""); sw.WriteLine(" else"); sw.WriteLine(" CHK_URL=\"${CHK_URL}/${PREV_DIR}/\""); sw.WriteLine(" fi"); sw.WriteLine(" "); sw.WriteLine(" # 检测文件夹"); sw.WriteLine(" CHK_INFO=`curl ${CHK_URL} -u ${VERIFY_CODE}`"); sw.WriteLine(" # 已存在目录"); sw.WriteLine(" EXIST_DIRS=(${CHK_INFO// / })"); sw.WriteLine(" # 存在标识位"); sw.WriteLine(" EXIST_FLG=0"); sw.WriteLine(" for DIR in ${EXIST_DIRS[@]}"); sw.WriteLine(" do"); sw.WriteLine(" if [ \"${DIR}\" == \"${CHK_DIR}\" ]; then"); sw.WriteLine(" EXIST_FLG=1"); sw.WriteLine(" break"); sw.WriteLine(" fi"); sw.WriteLine(" "); sw.WriteLine(" done"); sw.WriteLine(" "); sw.WriteLine(" if [ $EXIST_FLG -le 0 ]; then"); sw.WriteLine(" curl ${CHK_URL} -u ${VERIFY_CODE} -X \"MKD ${CHK_DIR}\""); sw.WriteLine(" echo \"Create Directory : ${CHK_URL}${CHK_DIR}\""); sw.WriteLine(" fi"); sw.WriteLine(" "); sw.WriteLine(" fi"); sw.WriteLine(" else"); sw.WriteLine(" echo \"[Error] The dirs for check is not invalid!!(Check Dir=${CHK_DIRS})\""); sw.WriteLine(" fi"); sw.WriteLine("}"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# # 文件上传函数"); sw.WriteLine("# $1 远程上传目录"); sw.WriteLine("# $2 本地上传文件路径"); sw.WriteLine("uploadFile()"); sw.WriteLine("{"); sw.WriteLine(" # 远程上传目标目录"); sw.WriteLine(" UPLOAD_DIR=$1"); sw.WriteLine(" # 本地上传文件"); sw.WriteLine(" LOCAL_FILE_PATH=$2"); sw.WriteLine(" "); sw.WriteLine(" # 检测URL"); sw.WriteLine(" UPLOAD_URL=${UPLOAD_SERVER_ROOT_URL}/${UPLOAD_DIR}"); sw.WriteLine(" #curl ${UPLOAD_URL} -v -u ${VERIFY_CODE} -T \"${LOCAL_FILE_PATH}\""); sw.WriteLine(" echo \"${LOCAL_FILE_PATH}\""); sw.WriteLine(" curl ${UPLOAD_URL} -u ${VERIFY_CODE} -T \"${LOCAL_FILE_PATH}\""); sw.WriteLine("}"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 检测目录"); sw.WriteLine("checkUploadDir $ROOT_DIR"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_NO"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_NO/$BUILD_TARGET"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_NO/$BUILD_TARGET/$APP_VERSION"); sw.WriteLine("# 上传文件"); sw.WriteLine("uploadFile $ROOT_DIR/$BUILD_NO/$BUILD_TARGET/$APP_VERSION/ {0}", iPath); sw.Close(); sw.Dispose(); fs.Close(); fs.Dispose(); Loger.BuildEnd(); }
private static void CreateUploadShellByFtp() { const string funcBlock = "AssetBundlesBuild:CreateUploadShellByFtp()"; Loger.BuildStart(funcBlock); var filePath = $"{Application.dataPath}/../Shell/UploadABByFtp.sh"; if (File.Exists(filePath)) { File.Delete(filePath); } var fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); var sw = new StreamWriter(fs); // 写入文件头 sw.WriteLine("#!/bin/bash"); sw.Flush(); sw.WriteLine(""); sw.Flush(); // 设定变量 sw.WriteLine("# 上传根目录"); sw.WriteLine("ROOT_DIR=bundles"); sw.Flush(); sw.WriteLine("# 本地上传路径"); sw.WriteLine("UPLOAD_FROM_ROOT_DIR={0}/StreamingAssets", Application.dataPath); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 上传目标平台"); sw.WriteLine("BUILD_TARGET={0}", BundlesResult.GetInstance().BuildTarget); sw.Flush(); sw.WriteLine("# App Version"); sw.WriteLine("APP_VERSION={0}", BundlesResult.GetInstance().AppVersion); sw.Flush(); var resourceServer = SysSettings.GetInstance().data.network.resourceServer; sw.WriteLine("# 检测上传目录"); sw.WriteLine("# $1 上传目录"); sw.WriteLine("checkUploadDir()"); sw.WriteLine("{"); sw.WriteLine("ftp -n<<!"); sw.WriteLine("open {0} {1}", resourceServer.ipAddresss, resourceServer.portNo); sw.WriteLine("user {0} {1}", resourceServer.accountId, resourceServer.pwd); sw.WriteLine("binary"); sw.WriteLine("pwd"); sw.WriteLine("mkdir $1"); sw.WriteLine("prompt"); // sw.WriteLine("ls -l"); sw.WriteLine("close"); sw.WriteLine("bye"); sw.WriteLine("!"); sw.WriteLine("}"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 文件上传函数(单个)"); sw.WriteLine("# $1 本地上传目录"); sw.WriteLine("# $2 上传目标目录"); sw.WriteLine("# $3 上传目标文件"); sw.WriteLine("uploadFile()"); sw.WriteLine("{"); sw.WriteLine("ftp -n<<!"); sw.WriteLine("open {0} {1}", resourceServer.ipAddresss, resourceServer.portNo); sw.WriteLine("user {0} {1}", resourceServer.accountId, resourceServer.pwd); sw.WriteLine("binary"); // 开启FTP被动模式上传 sw.WriteLine("quote pasv"); sw.WriteLine("passive"); // 设置远程目录 sw.WriteLine("cd $2"); sw.WriteLine("pwd"); // 设置本地目录 sw.WriteLine("lcd $1"); sw.WriteLine("prompt off"); // 上传文件(单个) sw.WriteLine("put $3"); sw.WriteLine("close"); sw.WriteLine("bye"); sw.WriteLine("!"); sw.WriteLine("}"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 文件夹上传函数"); sw.WriteLine("# $1 本地上传目录"); sw.WriteLine("# $2 上传目标目录"); sw.WriteLine("uploadDir()"); sw.WriteLine("{"); sw.WriteLine("ftp -n<<!"); sw.WriteLine("open {0} {1}", resourceServer.ipAddresss, resourceServer.portNo); sw.WriteLine("user {0} {1}", resourceServer.accountId, resourceServer.pwd); sw.WriteLine("binary"); // 开启FTP被动模式上传 sw.WriteLine("quote pasv"); sw.WriteLine("passive"); // 设置远程目录 sw.WriteLine("cd $2"); sw.WriteLine("pwd"); // 设置本地目录 sw.WriteLine("lcd $1"); sw.WriteLine("prompt off"); // 上传文件(单个) sw.WriteLine("mput *"); sw.WriteLine("close"); sw.WriteLine("bye"); sw.WriteLine("!"); sw.WriteLine("}"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 检测目录"); sw.WriteLine("checkUploadDir $ROOT_DIR"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION"); sw.WriteLine(""); sw.Flush(); sw.WriteLine("# 上传资源文件"); var targets = BundlesResult.GetInstance().Targets; var normals = targets .Where(iO => BundleType.Normal == iO.bundleType) .OrderBy(iO => iO.no) .ToArray(); if (0 < normals.Length) { sw.WriteLine("# 检测一般文件目录"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0}", BundleType.Normal); sw.WriteLine("# 一般文件"); foreach (var loop in normals) { var fileName = BundlesResult.GetLocalBundleFileName(loop.id, loop.fileType); sw.WriteLine("uploadFile $UPLOAD_FROM_ROOT_DIR/{0} $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0} {1}", BundleType.Normal, fileName); } sw.WriteLine(""); sw.Flush(); } var scenes = targets .Where(iO => BundleType.Scene == iO.bundleType) .OrderBy(iO => iO.no) .ToArray(); if (0 < scenes.Length) { sw.WriteLine("# 检测场景文件目录"); sw.WriteLine("checkUploadDir $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0}", BundleType.Scene); sw.WriteLine("# 场景文件"); foreach (var loop in scenes) { var fileName = BundlesResult.GetLocalBundleFileName(loop.id, loop.fileType); sw.WriteLine("uploadFile $UPLOAD_FROM_ROOT_DIR/{0} $ROOT_DIR/$BUILD_TARGET/$APP_VERSION/{0} {1}", BundleType.Scene, fileName); } sw.WriteLine(""); sw.Flush(); } if (0 < targets.Count) { sw.WriteLine("# 清空上传文件"); sw.WriteLine("rm -rfv $UPLOAD_FROM_ROOT_DIR"); sw.WriteLine(""); sw.Flush(); } sw.Close(); sw.Dispose(); fs.Close(); fs.Dispose(); Loger.BuildEnd(); }
/// <summary> /// 设定打包信息 /// </summary> /// <param name="iIsAndroid">是否为安卓平台</param> private static void SetBuildInfoFromParameters(bool iIsAndroid) { // 平台类型 var platformType = BuildParameters.PlatformType; if (PlatformType.None != platformType) { SysSettings.GetInstance().PlatformType = platformType; } else { if (PlatformType.None == SysSettings.GetInstance().PlatformType) { SysSettings.GetInstance().PlatformType = iIsAndroid ? PlatformType.Android : PlatformType.iOS; } } Loger.BuildLog($"PlatformType:{SysSettings.GetInstance ().PlatformType}"); // 工程名 var projectName = BuildParameters.ProjectName; if (false == string.IsNullOrEmpty(projectName)) { SysSettings.GetInstance().BuildName = projectName; } Loger.BuildLog($"ProjectName:{SysSettings.GetInstance ().BuildName}"); // 打包ID var buildId = BuildParameters.BuildId; if (false == string.IsNullOrEmpty(buildId)) { SysSettings.GetInstance().BuildId = buildId; } Loger.BuildLog($"BuildId:{SysSettings.GetInstance ().BuildId}"); // 打包模式 var buildMode = BuildParameters.BuildMode; SysSettings.GetInstance().BuildMode = buildMode; Loger.BuildLog($"BuildMode:{SysSettings.GetInstance ().BuildMode}"); // 版本号 var buildVersion = BuildParameters.BuildVersion; if (false == string.IsNullOrEmpty(buildVersion)) { SysSettings.GetInstance().BuildVersion = buildVersion; } Loger.BuildLog($"BuildVersion:{SysSettings.GetInstance ().BuildVersion}"); // VersionCode var buildVersionCode = BuildParameters.BuildVersionCode; if (-1 != buildVersionCode) { SysSettings.GetInstance().BuildVersionCode = buildVersionCode; } Loger.BuildLog($"BuildVersionCode:{SysSettings.GetInstance ().BuildVersionCode}"); // 日志等级 var logLevel = BuildParameters.LogLevel; SysSettings.GetInstance().LogLevel = logLevel; Loger.BuildLog($"LogLevel:{SysSettings.GetInstance ().LogLevel}"); // 打包号 var buildNumber = BuildParameters.BuildNumber; if (-1 < buildNumber) { SysSettings.GetInstance().BuildNumber = buildNumber; } Loger.BuildLog($"BuildNumber:{SysSettings.GetInstance ().BuildNumber}"); var fps = BuildParameters.Fps; SysSettings.GetInstance().Fps = fps; // 是否跳过下载 var isSkipDownload = BuildParameters.IsSkipDownload; SysSettings.GetInstance().data.network.SkipDownload = isSkipDownload; Loger.BuildLog($"SkipDownload:{SysSettings.GetInstance ().data.network.SkipDownload}"); // 前端 Host var webHost = BuildParameters.WebHost; if (false == string.IsNullOrEmpty(webHost)) { SysSettings.GetInstance().data.network.WebHost = webHost; } // 前端端口号 var webPortNo = BuildParameters.WebPortNo; if (-1 < webPortNo) { SysSettings.GetInstance().data.network.WebPortNo = webPortNo; } Loger.BuildLog($"Web(Host:{SysSettings.GetInstance ().data.network.WebHost} PortNo:{SysSettings.GetInstance ().data.network.WebPortNo})"); }
public static void BuildForAndroid() { // 输出路径 // 游戏输出目录(Android):{OutputDir}/Android/{ProjectName} var outputDir = GetOutputDir( BuildTarget.Android, BuildParameters.BuildNumber, BuildParameters.OutputDir); if (outputDir == null) { Loger.BuildErrorLog($"Create Dir Failed.!!(Dir:{BuildParameters.OutputDir})"); throw new ApplicationException(); } const string funcBlock = "ProjectBuild.BuildForAndroid()"; Loger.BuildStart(funcBlock); // 设定打包信息 SetBuildInfoFromParameters(true); var buildMode = SysSettings.GetInstance().BuildMode; Loger.BuildLog($"BuildMode:{buildMode}"); // 输出格式({ProjectName}_v{ProjectVersion}_{buildNumber}_YYYYMMDDHHMMSS.apk) var buildTime = BuildParameters.BuildTime; // 打包选项 var buildOptionTmp = BuildOptions.None; if (BuildMode.Debug == buildMode) { buildOptionTmp |= BuildOptions.Development; buildOptionTmp |= BuildOptions.AllowDebugging; buildOptionTmp |= BuildOptions.ConnectWithProfiler; } else { var isCheatMode = BuildParameters.IsCheatMode; if (isCheatMode) { buildOptionTmp |= BuildOptions.Development; } } Loger.BuildLog($"BuildOption:{buildOptionTmp}"); // 版本号 var buildVersion = SysSettings.GetInstance().BuildVersion; if (string.IsNullOrEmpty(buildVersion) == false) { PlayerSettings.bundleVersion = buildVersion; } Loger.BuildLog($"BuildVersion:{buildVersion}"); // buildVersionCode var buildVersionCode = SysSettings.GetInstance().BuildVersionCode; PlayerSettings.Android.bundleVersionCode = buildVersionCode; Loger.BuildLog($"BundleVersionCode:{buildVersionCode}"); // 工程名 var projectName = SysSettings.GetInstance().BuildName; Loger.BuildLog($"ProjectName:{projectName}"); // 游戏名字 var gameName = BuildParameters.GameName; if (string.IsNullOrEmpty(gameName)) { gameName = projectName; } PlayerSettings.productName = gameName; Loger.BuildLog($"GameName:{gameName}"); // BuildID var buildId = SysSettings.GetInstance().BuildId; if (false == string.IsNullOrEmpty(buildId)) { #if UNITY_5_5_OR_NEWER PlayerSettings.applicationIdentifier = buildId; #else PlayerSettings.bundleIdentifier = buildId; #endif } Loger.BuildLog($"BuildID:{buildId}"); // 初始化 InitForAndroidBuild(); Loger.BuildLog(" --> InitForAndroidBuild()"); // Apk输出路径 var buildNumber = SysSettings.GetInstance().BuildNumber; Loger.BuildLog($"BuildNumber:{buildNumber}"); // 前端服务器Host var webHost = SysSettings.GetInstance().data.network.webServer.host; Loger.BuildLog($"WebServer:Host:{webHost}"); // 前端服务器端口号 var webPortNo = SysSettings.GetInstance().data.network.webServer.portNo; Loger.BuildLog($"WebServer:PortNo:{webPortNo}"); // 输出宏定义 var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android); Loger.BuildLog($"Defines:{defines}"); var apkPath = $"{outputDir}/{projectName}_{buildMode}_v{buildVersion}_-_{buildTime}_{buildId}.apk"; if (0 < buildNumber) { apkPath = $"{outputDir}/{projectName}_{buildMode}_v{buildVersion}_{buildNumber}_{buildTime}_{buildId}.apk"; } Loger.BuildLog($"Apk File Path:{apkPath}"); // 输出打包信息 OutputBuildInfo(buildVersion, projectName); // 开发者模式 if (BuildOptions.Development == buildOptionTmp) { // 打包之前,移除非资源对象 // AssetBundles.Common.MoveUnResources(); } // Android下IL2CPP不支持,所以设置回Mono #pragma warning disable 618 PlayerSettings.SetPropertyInt("ScriptingBackend", (int)ScriptingImplementation.Mono2x, BuildTarget.Android); #pragma warning restore 618 var report = BuildPipeline.BuildPlayer(GetBuildScenes(), apkPath, BuildTarget.Android, buildOptionTmp); // 开发者模式 if (BuildOptions.Development == buildOptionTmp) { // 打包之后,恢复非资源对象 // AssetBundles.Common.MoveBackUnResources(); } #if UNITY_2018_3 || UNITY_2018_3_OR_NEWER if (0 > report.summary.totalErrors) { Loger.BuildErrorLog($"Android Build Failed!!!(error:{report.summary})"); Loger.BuildEnd(); throw new ApplicationException(); } #else if (report != null) { Loger.BuildErrorLog($"Android Build Failed!!!(error:{report})"); Loger.BuildEnd(); throw new ApplicationException(); } #endif Loger.BuildLog("Android Build Succeeded."); // 生成上传用的Shell脚本 CreateUploadShell(buildNumber, BuildTarget.Android, apkPath); // 生成远程CDN服务器刷新脚本 AssetBundlesBuild.CreateShellOfRefreshCdn(); Loger.BuildEnd(); }