Beispiel #1
0
    public static string GetPlayerPathForAndroid(string sChannel, string sVersion, bool bIsAssetbundle)
    {
        //Android_uc_TLBB3D_0_580_0_0_148480_2015_03_06_1107.apk
        string sFolder = BuildAndroidConfig.PLAYER_BASE_DIRECTORY + GetCurDay() + "/";

        if (!Directory.Exists(sFolder))
        {
            Directory.CreateDirectory(sFolder);
        }

        //if (sChannel.StartsWith("Android_"))
        //{
        //    sChannel = sChannel.Substring("Android_".Length);
        //}
        string sVersionCode = BuildPlayerHelper.GetVersionCode(sVersion).ToString();

        sVersion = sVersion.Replace(".", "_");
        string sPath = sFolder + sChannel + "_" + "Cabal" + "_" + sVersion + "_" + sVersionCode + "_" + GetCurDay() + "_" + GetCurTime();

        if (bIsAssetbundle)
        {
            return(sPath + ".apk");
        }
        else
        {
            return(sPath + "_off.apk");
        }
    }
    public static void BuildAndroid(string sBuildChannels, string sVersion, bool bIsAssetbundle, bool bIsSDKServerList)
    {
        try
        {
            Debug.Log("BuildAndroidProcess.BuildAndroid start:" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"));
            if (string.IsNullOrEmpty(sBuildChannels) || string.IsNullOrEmpty(sVersion))
            {
                return;
            }

            //Debug.Log("BuildAndroidProcess.BuildAndroid BuildChannels:" + sBuildChannels);
            string[] channelList = BuildPlayerHelper.ParseChannelListForAndroid(sBuildChannels);
            Debug.Log(string.Format("BuildAndroidProcess.BuildAndroid channelList number is:" + channelList.Length.ToString()));
            if (null == channelList || 0 == channelList.Length)
            {
                throw new Exception("BuildAndroidProcess.BuildAndroid channel list is null!");
            }
            else
            {
                //for (int index = 0; index < channelList.Length;++index)
                //{
                //    Debug.Log(string.Format("BuildPlayerProcess.BuildPlayerByCommandline channelList[{0}]:{1}", index.ToString(), channelList[index]));
                //}

                AssetDatabase.Refresh();
                SetupPlayerSettings(sVersion);

                foreach (string sChannel in channelList)
                {
                    if (!BuildAndroidForChannel(sChannel, sVersion, bIsAssetbundle, bIsSDKServerList))
                    {
                        throw new Exception("BuildAndroidProcess.BuildAndroid failed. channel is:" + sChannel);
                    }
                }
            }
            Debug.Log("BuildAndroidProcess.BuildAndroid end:" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"));
        }
        catch (System.Exception ex)
        {
            Debug.LogError("BuildAndroidProcess.BuildAndroid exception is: " + ex.Message);
        }
    }
    private static bool BuildAndroidForChannel(string sChannel, string sVersion, bool bIsAssetbundle, bool bIsSDKServerList)
    {
        try
        {
            Debug.Log(string.Format("BuildAndroidProcess.BuildAndroidForChannel Channel:{0}, Version:{1}, IsAssetbundle{2}", sChannel, sVersion, bIsAssetbundle.ToString()));
            Debug.Log("BuildAndroidProcess.BuildAndroidForChannel start:" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"));

            if (string.IsNullOrEmpty(sChannel))
            {
                throw new Exception("BuildAndroidProcess.BuildAndroidForChannel channel is null");
            }
            if (string.IsNullOrEmpty(sVersion))
            {
                throw new Exception("BuildAndroidProcess.BuildAndroidForChannel Version is null");
            }

            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);

            if (!CopyChannelPlugin(sChannel, sVersion, bIsSDKServerList))
            {
                throw new Exception("BuildAndroidProcess.BuildAndroidForChannel CopyChannelPlugin failed");
            }

            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);

            if (!SetupChannelPlugin(sChannel))
            {
                throw new Exception("BuildAndroidProcess.BuildAndroidForChannel SetupChannelPlugin failed");
            }

            string sPlayerPath = BuildPlayerHelper.GetPlayerPathForAndroid(sChannel, sVersion, bIsAssetbundle);
            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            BuildPipeline.BuildPlayer(BuildAndroidConfig.GetAllScenes(), sPlayerPath, BuildTarget.Android, BuildOptions.None);
            Debug.Log("BuildAndroidProcess.BuildAndroidForChannel end:" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"));
        }
        catch (System.Exception ex)
        {
            Debug.LogError("BuildAndroidProcess.BuildAndroidForChannel exception is:" + ex.Message);
            return(false);
        }
        return(true);
    }
    private static bool WritePlayerConfigPropertiesFile(List <string> sLineList, string sVersion, bool bIsSDKServerList)
    {
        string sConfigPropertiesFile = GetPlayerConfigPropertiesFile();

        if (File.Exists(sConfigPropertiesFile))
        {
            FileStream   fs = new FileStream(sConfigPropertiesFile, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            foreach (string sItem in sLineList)
            {
                if (sItem.StartsWith(CONFIG_PROPERTIES_RES_DOWNLOAD_URL))
                {
                    string sResURL = sItem + BuildPlayerHelper.GetResDownloadUrlVersion(sVersion);
                    sw.WriteLine(sResURL);
                }
                else if (sItem.StartsWith(CONFIG_PROPERTIES_SERVERLIST_URL))
                {
                    if (bIsSDKServerList)
                    {
                        sw.WriteLine(sItem);
                    }
                    else
                    {
                        sw.WriteLine(LOCAL_CONFIG_SERVERLIST_URL);
                    }
                }
                else
                {
                    sw.WriteLine(sItem);
                }
            }
            sw.Close();
            fs.Close();
            sLineList.Clear();
            return(true);
        }
        return(false);
    }
    private static void SetupPlayerSettings(string sVersion)
    {
        try
        {
            Debug.Log("BuildAndroidProcess.SetupPlayerSettings start:" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"));
            //TODO BY MAWENBIN 1 //E:\AndroidPlugins\Android_360\assets\config.properties
            //设置AppName GroupName ChannelName NoticeConfigUrl ServerListUrl,并生产版本文件
            //BuildGameConfig.Load(Path.Combine(Application.streamingAssetsPath, BuildGameConfig.c_GameConfigFile));
            //BuildGameConfig.Save(buildchannel);

            //context["androidBase"] = androidBase.EvaluateIn(context); //BundleEditor.ExportBundleData

            //context["resourceVersion"] = resourceVersion.EvaluateIn(context); //wangdi
            if (!BuildPlayerHelper.UpdateResourceVersionFile(sVersion))
            {
                throw new Exception("BuildAndroidProcess.SetupPlayerSettings UpdateResourceVersionFile failed!");
            }

            PlayerSettings.companyName = BuildAndroidConfig.DEFAULT_COMPANY_NAME;

            PlayerSettings.bundleVersion             = sVersion;
            PlayerSettings.Android.bundleVersionCode = BuildPlayerHelper.GetVersionCode(sVersion);

            PlayerSettings.defaultInterfaceOrientation            = UIOrientation.AutoRotation;
            PlayerSettings.statusBarHidden                        = true;
            PlayerSettings.use32BitDisplayBuffer                  = true;
            PlayerSettings.Android.use24BitDepthBuffer            = true;
            PlayerSettings.Android.showActivityIndicatorOnLoading = AndroidShowActivityIndicatorOnLoading.DontShow;

            PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel10;
            PlayerSettings.Android.targetDevice  = AndroidTargetDevice.ARMv7;

            //TODO BY MAWENBIN 2
            //#if UNITY_3_5
            //        PlayerSettings.Android.targetGraphics = targetGraphics.EvaluateIn (context);
            //#endif
            //#if UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1
            //        PlayerSettings.targetGlesGraphics = targetGlesGraphics.EvaluateIn(context);
            //#endif

            PlayerSettings.Android.preferredInstallLocation = AndroidPreferredInstallLocation.Auto;
            PlayerSettings.Android.forceInternetPermission  = true;
            PlayerSettings.Android.forceSDCardPermission    = true;

            PlayerSettings.apiCompatibilityLevel     = ApiCompatibilityLevel.NET_2_0_Subset;
            PlayerSettings.stripUnusedMeshComponents = true;
            PlayerSettings.strippingLevel            = StrippingLevel.UseMicroMSCorlib;

//			string res = lowQuality.EvaluateIn(context).ToString();
//			if (res.Equals("True")) {
//				BuildAssetProcess.BuildAndroid();//资源高低配处理
//			}


            //already added in BuildAssetProcess::DoAndroidLowTextrue
            //context["lowQuality"] = lowQuality.EvaluateIn(context);
            //E:\Main\Project\Client\Assets\BuildTools\Android\uTomate\Editor\Actions\UTMyTextureAction.cs
            //MLDJ/UIRes/Atlas/Common/Common.prefab

            //#if UNITY_3_5
            //        PlayerSettings.debugUnloadMode = debugUnloadMode.EvaluateIn(context);
            //#endif

            PlayerSettings.allowedAutorotateToLandscapeLeft  = true;
            PlayerSettings.allowedAutorotateToLandscapeRight = true;
            Debug.Log("BuildAndroidProcess.SetupPlayerSettings end:" + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"));
        }
        catch (System.Exception ex)
        {
            Debug.LogError("BuildAndroidProcess.SetupPlayerSettings exception is: " + ex.Message);
        }
    }