Пример #1
0
    public static void BuildAssetBundles()
    {
        Debug.Log("Start Build AssetBundle......");

        string[] argArr = System.Environment.GetCommandLineArgs();
        if (argArr.Length != 11)
        {
            Debug.LogErrorFormat("AssetBundle Build Argument Error! {0}", argArr.Length);
            return;
        }

        if (argArr[9] == "android")
        {
            BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.Android);
            string savePath            = string.Format("../../../web/{0}/res/android/", argArr[10]);
            AssetBuilderCtrl.BuildAssetBundles(config, savePath);
        }
        else if (argArr[9] == "ios")
        {
            BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.IOS);
            string savePath            = string.Format("../../../web/{0}/res/ios/", argArr[10]);
            AssetBuilderCtrl.BuildAssetBundles(config, savePath);
        }
        else if (argArr[9] == "win")
        {
            BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.Win);
            string savePath            = string.Format("../../../web/{0}/res/win/", argArr[10]);
            AssetBuilderCtrl.BuildAssetBundles(config, savePath);
        }

        Debug.Log("Finish Build AssetBundle!");
    }
Пример #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);
            }
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
 /// <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();
         }
     }
 }
Пример #5
0
    public static void BuildApp()
    {
        Debug.Log("Start Build App......");
        string[] argArr = System.Environment.GetCommandLineArgs();
        if (argArr.Length != 12)
        {
            Debug.LogErrorFormat("App Build Argument Error! {0}", argArr.Length);
            return;
        }

        if (argArr[9] == "android")
        {
            BuildPlatformConfig config = AssetBuilderConfig.GetConfig(BuildPlatform.Android);
            string bundlePath          = string.Format("../../../web/{0}/res/android/", argArr[10]);
            string appSavePath         = string.Format("../../../web/{0}/app/android/", argArr[10]);
            AssetBuilderCtrl.BuildAndroidApp(config, bundlePath, appSavePath, argArr[10], argArr[11]);
        }

        Debug.Log("Finish Build App!");
    }
Пример #6
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 + "/";
     }
 }
Пример #7
0
        /// <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();
            }
        }
Пример #8
0
        /// <summary>
        /// 设置安卓的spalshicon  可通用
        /// </summary>
        private static void SetAndroidSpalshIcon(string platformName, AppGameConfig gameCfg)
        {
            //先清理资源文件
            FileUtils.CleanDirectory(UnityEngine.Application.dataPath + "/PlatformData/");
            AssetDatabase.Refresh();

            #region   unity splash
#if UNITY_5_6_OR_NEWER
            {
                List <PlayerSettings.SplashScreenLogo> logoList = new List <PlayerSettings.SplashScreenLogo>();

                string screenSourcePath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/splash_screen/", platformName);//源目录文件夹

                string screenTargetPath = string.Format(UnityEngine.Application.dataPath + "/PlatformData/{0}/android/splash_screen/", platformName);

                //存在splash文件时,拷贝到unity
                if (Directory.Exists(screenSourcePath))
                {
                    if (Directory.Exists(screenTargetPath))
                    {
                        AssetBuilderCtrl.CleanDirectory(screenTargetPath);
                    }
                    Directory.CreateDirectory(screenTargetPath);
                    AssetBuilderCtrl.CopyDirectory(screenSourcePath, screenTargetPath);//拷贝文件夹资源
                    AssetDatabase.Refresh();
                    screenTargetPath = string.Format("Assets/PlatformData/{0}/android/splash_screen/", platformName);
                }

                if (Directory.Exists(screenTargetPath))
                {
                    for (int i = 1; i <= 3; i++)
                    {
                        string logoPath = screenTargetPath + i + ".png";

                        if (!File.Exists(logoPath))
                        {
                            logoPath = screenTargetPath + i + ".jpg";
                        }

                        if (File.Exists(logoPath))
                        {
                            Sprite logoSp = (Sprite)AssetDatabase.LoadAssetAtPath(logoPath, typeof(Sprite));

                            if (logoSp == null)
                            {
                                TextureImporter import = AssetImporter.GetAtPath(logoPath) as TextureImporter;
                                import.textureType      = TextureImporterType.Sprite;
                                import.spriteImportMode = SpriteImportMode.Single;
                                import.mipmapEnabled    = false;
                                import.sRGBTexture      = true;
                                import.alphaSource      = TextureImporterAlphaSource.FromInput;
                                import.anisoLevel       = 16;

                                AssetDatabase.ImportAsset(logoPath);

                                logoSp = (Sprite)AssetDatabase.LoadAssetAtPath(logoPath, typeof(Sprite));
                            }

                            if (logoSp != null)
                            {
                                PlayerSettings.SplashScreenLogo logo =
                                    PlayerSettings.SplashScreenLogo.Create(2.5f, logoSp);
                                logoList.Add(logo);
                            }
                        }
                    }

                    PlayerSettings.SplashScreen.logos           = logoList.ToArray();
                    PlayerSettings.SplashScreen.drawMode        = PlayerSettings.SplashScreen.DrawMode.AllSequential;
                    PlayerSettings.SplashScreen.backgroundColor = Color.white;
                    PlayerSettings.SplashScreen.unityLogoStyle  = PlayerSettings.SplashScreen.UnityLogoStyle.DarkOnLight;
                    PlayerSettings.SplashScreen.show            = true;
                    PlayerSettings.SplashScreen.showUnityLogo   = false;
                }
                else
                {
                    PlayerSettings.SplashScreen.show          = false;
                    PlayerSettings.SplashScreen.showUnityLogo = false;
                }
                //  Directory.Delete(screenTargetPath);//设置完后删除?
            }
#endif
            #endregion

            #region    splash
            {
                string screenSourcePath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/assets/splash/", platformName);//源目录文件夹
                string screenTargetPath = string.Format(UnityEngine.Application.dataPath + "/PlatformData/{0}/android/assets/splash/", platformName);
                //存在splash文件时,拷贝到unity
                if (Directory.Exists(screenSourcePath))
                {
                    if (Directory.Exists(screenTargetPath))
                    {
                        AssetBuilderCtrl.CleanDirectory(screenTargetPath);
                    }
                    Directory.CreateDirectory(screenTargetPath);
                    AssetBuilderCtrl.CopyDirectory(screenSourcePath, screenTargetPath);//拷贝文件夹资源
                    AssetDatabase.Refresh();
                    screenTargetPath = string.Format("Assets/PlatformData/{0}/android/assets/splash/", platformName);
                }

                int splashCount = 0;
                for (int i = 1; i <= 3; i++)
                {
                    string    iconPath = string.Format("{0}{1}.png", screenTargetPath, i);
                    Texture2D tex2d    = AssetDatabase.LoadAssetAtPath <Texture2D>(iconPath);
                    if (tex2d != null)
                    {
                        splashCount++;
                        PlayerSettings.showUnitySplashScreen = false;

#if UNITY_2017_1_OR_NEWER
                        PlayerSettings.virtualRealitySplashScreen = tex2d;
#endif
                    }
                    else
                    {
                        break;
                    }
                }
                AssetDatabase.Refresh();
                gameCfg.Splash = splashCount;
            }
            PlayerSettings.showUnitySplashScreen = false;
            #endregion

            #region Set icon
            {
                string screenSourcePath = string.Format(Directory.GetParent(UnityEngine.Application.dataPath) + "/PlatformData/{0}/android/icon/", platformName);//源目录文件夹
                string screenTargetPath = string.Format(UnityEngine.Application.dataPath + "/PlatformData/{0}/android/icon/", platformName);
                if (Directory.Exists(screenSourcePath))
                {
                    if (Directory.Exists(screenTargetPath))
                    {
                        AssetBuilderCtrl.CleanDirectory(screenTargetPath);
                    }
                    Directory.CreateDirectory(screenTargetPath);
                    AssetBuilderCtrl.CopyDirectory(screenSourcePath, screenTargetPath);//拷贝文件夹资源
                    AssetDatabase.Refresh();
                }
                screenTargetPath = string.Format("Assets/PlatformData/{0}/android/icon/", platformName);
                int[]       sizeList = PlayerSettings.GetIconSizesForTargetGroup(BuildTargetGroup.Android);
                Texture2D[] icons    = new Texture2D[sizeList.Length];
                for (int i = 0; i < sizeList.Length; i++)
                {
                    string    iconPath = string.Format("{0}icon_{1}.png", screenTargetPath, sizeList[i]);
                    Texture2D textIcon = (Texture2D)AssetDatabase.LoadAssetAtPath(iconPath, typeof(Texture2D));
                    icons[i] = textIcon;
                }

                PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, icons);
            }
            #endregion
        }