/// <summary>
        /// 设置安卓app的参数  外部调用
        /// </summary>
        public static void SetAndroidApp(BuildPlatformConfig config, string bundlePath, string appSavePath, string platformName, string packMode, AppResSize resSize = AppResSize.Normal, bool isSplashEnabled = true)
        {
            string gameConfigPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/config.game", platformName);

            string        json    = File.ReadAllText(gameConfigPath);
            AppGameConfig gameCfg = AppGameConfig.FromJson(json);

            if (Directory.Exists(SDKStreamingAssetsFull))
            {
                AssetBuilderCtrl.CleanDirectory(SDKStreamingAssetsFull);
            }
            else
            {
                Directory.CreateDirectory(SDKStreamingAssetsFull);
            }

            File.Copy(gameConfigPath, configGame_gameFull);
            AssetDatabase.Refresh();

            CopyAndroidPlugins(config, platformName, packMode);
            ReplaceAndroidManifestPushInfo(config, platformName, gameCfg);

            CopyAndroidAssets(config, platformName, packMode);

            SetAndroidAppBuildSetting(config, appSavePath, platformName, packMode, gameCfg, isSplashEnabled, resSize);
        }
Exemple #2
0
        private void BuildAppOnly()
        {
            if (mBuildPlatform == BuildPlatform.Android)
            {
                BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.Android);
                string appSavePath         = "../app/" + config.platformName + "/";

                string        platformName   = mAppPlatform.ToString();
                string        gameConfigPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/config.game", platformName);
                string        json           = File.ReadAllText(gameConfigPath);
                AppGameConfig gameCfg        = AppGameConfig.FromJson(json);

                AssetBuilderCtrl.PackAndroidApp(config, appSavePath, platformName, mAppPackMode.ToString(), gameCfg, AssetBuilderConfig.IsSplashEnabled(mAppPlatform), AppResSize.Normal);
            }
            else if (mBuildPlatform == BuildPlatform.IOS)
            {
                BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.IOS);
                string appSavePath         = "../app/" + config.platformName + "/";

                string        platformName   = mAppPlatform.ToString();
                string        gameConfigPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/ios/config.game", platformName);
                string        json           = File.ReadAllText(gameConfigPath);
                AppGameConfig gameCfg        = AppGameConfig.FromJson(json);

                AssetBuilderCtrl.PackIOSApp(config, appSavePath, mAppPlatform.ToString(), mAppPackMode.ToString(), gameCfg, AppResSize.Normal);
            }
        }
        /// <summary>
        /// 修改AndroidManifest.xml,可通用
        /// </summary>
        private static void ReplaceAndroidManifestPushInfo(BuildPlatformConfig config, string platformName, AppGameConfig gameCfg)
        {
            return;

            string tempContent = string.Empty;
            string filePath    = Application.dataPath + config.pluginPath.Replace("Assets", "") + "AndroidManifest.xml";

            if (!File.Exists(filePath))
            {
                return;
            }

            string            packConfigPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/default.pack", platformName);
            string            packCfgJson    = File.ReadAllText(packConfigPath);
            AndroidPackConfig packCfg        = AndroidPackConfig.FromJson(packCfgJson);

            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                using (StreamReader sr = new StreamReader(fs))
                {
                    tempContent = sr.ReadToEnd();
                    tempContent = tempContent.Replace("__your_package_name", packCfg.PackageName);
                }
            }

            using (StreamWriter sw = new StreamWriter(filePath))
            {
                sw.Write(tempContent);
            }
        }
Exemple #4
0
 private string GetResPath(BuildPlatformConfig cfg)
 {
     if (mAppResSource == AppResSource.Private)
     {
         return("../assets/" + cfg.platformName + "/");
         //return "C:/apache-tomcat-9.0.8/webapps/downloads/" + cfg.platformName + "/";
     }
     else
     {
         string resSource = "";
         if (mAppResSource == AppResSource.Dev)
         {
             resSource = "dev";
         }
         else if (mAppResSource == AppResSource.Trial)
         {
             resSource = "trial";
         }
         else if (mAppResSource == AppResSource.Base)
         {
             resSource = "base";
         }
         else if (mAppResSource == AppResSource.LeNiu)
         {
             resSource = "leniu";
         }
         else if (mAppResSource == AppResSource.GongHui)
         {
             resSource = "gonghui";
         }
         else if (mAppResSource == AppResSource.HKTW_Dev)
         {
             resSource = "hktw_dev";
         }
         else if (mAppResSource == AppResSource.HKTW_Base)
         {
             resSource = "hktw_base";
         }
         else if (mAppResSource == AppResSource.Korea_Dev)
         {
             resSource = "korea_dev";
         }
         else if (mAppResSource == AppResSource.Korea_Base)
         {
             resSource = "korea_base";
         }
         else if (mAppResSource == AppResSource.ZhuanJia)
         {
             resSource = "zj";
         }
         return(string.Format("../../../web/{0}/res/{1}/", resSource, cfg.platformName));
     }
 }
 /// <summary>
 /// 拷贝assets资源到StreamingAssets文件夹下 可通用
 /// </summary>
 private static void CopyAndroidAssets(BuildPlatformConfig config, string platformName, string packMode)
 {
     // copy android assets
     {
         string assetsPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/assets", platformName);
         if (Directory.Exists(assetsPath))
         {
             string assetsSavePath = config.pluginPath + "assets";
             Directory.CreateDirectory(assetsSavePath);
             AssetBuilderCtrl.CopyDirectory(assetsPath, assetsSavePath);
             AssetDatabase.Refresh();
         }
     }
 }
        /// <summary>
        /// 设置打包时unity的所有参数
        /// </summary>
        private static void SetAndroidAppBuildSetting(BuildPlatformConfig config, string appSavePath, string platformName, string packMode, AppGameConfig gameCfg, bool isSplashEnabled, AppResSize resSize)
        {
            gameCfg.ResetAppVersion();
            switch (resSize)
            {
            case AppResSize.Mini:
                gameCfg.DownloadPriority = 9800;
                break;

            case AppResSize.Mini_1:
                gameCfg.DownloadPriority = 9800;
                break;

            case AppResSize.Mini_2:
                gameCfg.DownloadPriority = 9000;
                break;

            case AppResSize.Mini_3:
                gameCfg.DownloadPriority = 7400;
                break;

            case AppResSize.Normal:
                gameCfg.DownloadPriority = 1000;
                break;

            default:
                break;
            }

            // load pack config
            string            packConfigPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/default.pack", platformName);
            string            packCfgJson    = File.ReadAllText(packConfigPath);
            AndroidPackConfig packCfg        = AndroidPackConfig.FromJson(packCfgJson);

            //设置安卓icon,动画
            SetAndroidSpalshIcon(platformName, gameCfg);
            AssetDatabase.Refresh();

            // save game config  永恒不save,全部由表自己控制
            //File.WriteAllText(configGame_gameFull, gameCfg.ToJson());
            //AssetDatabase.Refresh();

            // build app
            SetAndroidBuildSetting(packCfg, gameCfg, packMode);
            AssetDatabase.Refresh();

            Debug.LogWarning("Set AndroidApp BuildSetting success!");
        }
Exemple #7
0
 private void BuildApp()
 {
     if (mBuildPlatform == BuildPlatform.Android)
     {
         BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.Android);
         string bundlePath          = GetResPath(config);
         string appSavePath         = "../app/" + config.platformName + "/";
         AssetBuilderCtrl.BuildAndroidApp(config, bundlePath, appSavePath, mAppPlatform.ToString(), mAppPackMode.ToString(), mAppResSize, AssetBuilderConfig.IsSplashEnabled(mAppPlatform));
     }
     else if (mBuildPlatform == BuildPlatform.IOS)
     {
         BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.IOS);
         string bundlePath          = GetResPath(config);
         string appSavePath         = "../app/" + config.platformName + "/";
         AssetBuilderCtrl.BuildIOSApp(config, bundlePath, appSavePath, mAppPlatform.ToString(), mAppPackMode.ToString(), mAppResSize, mAddGarbageCode);
     }
     else if (mBuildPlatform == BuildPlatform.Win)
     {
         BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.Win);
         string bundlePath          = GetResPath(config);
         string appSavePath         = "../app/" + config.platformName + "/";
     }
 }
        /// <summary>
        /// 拷贝plugins资源,可通用(拷贝前会先清除)
        /// </summary>
        private static void CopyAndroidPlugins(BuildPlatformConfig config, string platformName, string packMode)
        {
            string pluginPath = config.pluginPath;

            // clear plugin dir
            {
                string platfromDataPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/{1}", platformName, packMode);
                if (Directory.Exists(pluginPath))
                {
                    Directory.Delete(pluginPath, true);
                    Directory.CreateDirectory(pluginPath);
                }
                AssetBuilderCtrl.CopyDirectory(platfromDataPath, pluginPath);
                AssetDatabase.Refresh();
            }

            // copy android data
            string resPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/res", platformName);

            if (Directory.Exists(resPath))
            {
                string resSavePath = pluginPath + "res";
                Directory.CreateDirectory(resSavePath);
                AssetBuilderCtrl.CopyDirectory(resPath, resSavePath);
                AssetDatabase.Refresh();
            }

            {
                string binSavePath = pluginPath + "bin";
                Directory.CreateDirectory(binSavePath);

                string binPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/bin", platformName);
                if (Directory.Exists(binPath))
                {
                    AssetBuilderCtrl.CopyDirectory(binPath, binSavePath);
                    AssetDatabase.Refresh();

                    DirectoryInfo dir = new DirectoryInfo(binSavePath);
                    foreach (FileInfo item in dir.GetFiles())
                    {
                        if (item.Extension == ".jar")
                        {
                            string         jarPath  = binSavePath + "/" + item.Name;
                            PluginImporter importer = AssetImporter.GetAtPath(jarPath) as PluginImporter;
                            importer.SetCompatibleWithPlatform(BuildTarget.Android, true);
                            importer.SaveAndReimport();
                        }
                    }
                    AssetDatabase.Refresh();
                }
            }

            {
                string libsSavePath = pluginPath + "libs";
                Directory.CreateDirectory(libsSavePath);

                string libsPath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/libs", platformName);
                if (Directory.Exists(libsPath))
                {
                    AssetBuilderCtrl.CopyDirectory(libsPath, libsSavePath);
                    AssetDatabase.Refresh();

                    DirectoryInfo dir = new DirectoryInfo(libsSavePath);
                    foreach (DirectoryInfo item in dir.GetDirectories())
                    {
                        foreach (var soFile in item.GetFiles())
                        {
                            if (soFile.Extension == ".so")
                            {
                                string         soPath   = libsSavePath + "/" + item.Name + "/" + soFile.Name;
                                PluginImporter importer = AssetImporter.GetAtPath(soPath) as PluginImporter;
                                importer.SetCompatibleWithPlatform(BuildTarget.Android, true);
                                //importer.SetPlatformData(BuildTarget.Android, "CPU", "x86");
                                importer.SaveAndReimport();
                            }
                        }
                    }
                    AssetDatabase.Refresh();
                }
            }
            {
                string         jarPath  = pluginPath + "bin/androidu3d.jar";
                PluginImporter importer = AssetImporter.GetAtPath(jarPath) as PluginImporter;
                importer.SetCompatibleWithPlatform(BuildTarget.Android, true);
                importer.SaveAndReimport();
                AssetDatabase.Refresh();
            }
        }