예제 #1
0
        public static CommandArgs Parse(string[] args)
        {
            char[] kEqual = new char[] {'='};
            char[] kArgStart = new char[] {'-', '\\'};
            CommandArgs ca = new CommandArgs();

            int ii = -1;
            string token = NextToken(args, ref ii);

            while (token != null)
            {
                if (IsArg(token))
                {
                    string arg = token.TrimStart(kArgStart).TrimEnd(kEqual);
                    string value = null;

                    if (arg.Contains("="))
                    {
                        string[] r = arg.Split(kEqual, 2);

                        if (r.Length == 2 && r[1] != string.Empty)
                        {
                            arg = r[0];
                            value = r[1];
                        }
                    }

                    while (value == null)
                    {
                        if (ii > args.Length)
                            break;

                        string next = NextToken(args, ref ii);
                        if (next != null)
                        {
                            if (IsArg(next))
                            {
                                ii--;
                                value = "true";
                            }
                            else if (next != "=")
                            {
                                value = next.TrimStart(kEqual);
                            }
                        }
                    }
                    ca.ArgPairs.Add(arg, value);
                }
                else if (token != string.Empty)
                {
                    ca.Params.Add(token);
                }

                token = NextToken(args, ref ii);
            }
            return ca;
        }
예제 #2
0
        /// <summary>
        /// 命令行给unity传参数 示例:-BundleVersion=1.0.1 -AndroidKeyStoreName=KSFramework
        /// Unity.exe -batchmode -projectPath %codePath%\ -nographics -executeMethod BuildTest.PerformAndroidBuild -BundleVersion=1.0.1 -AndroidKeyStoreName=KSFramework -logFile %~dp0\build.log -quit
        /// </summary>
        /// <param name="opt"></param>
        /// <param name="outputpath"></param>
        private static void ParseArgs(ref BuildOptions opt, ref string outputpath)
        {
            string[] args = System.Environment.GetCommandLineArgs();
            if (!Directory.Exists(AppConfig.ProductRelPath))
            {
                Directory.CreateDirectory(AppConfig.ProductRelPath);
            }

            if (args.Length >= 2)
            {
                CommandArgs commandArg = CommandLine.Parse(args);
                //List<string> lparams = commandArg.Params;
                Dictionary <string, string> argPairs = commandArg.ArgPairs;

                foreach (KeyValuePair <string, string> item in argPairs)
                {
                    switch (item.Key)
                    {
                    case "BundleVersion":
                        PlayerSettings.bundleVersion = item.Value;
                        break;

                    case "AndroidVersionCode":
                        PlayerSettings.Android.bundleVersionCode = System.Int32.Parse(item.Value);
                        break;

                    case "AndroidKeyStoreName":
                        PlayerSettings.Android.keystoreName = item.Value;
                        break;

                    case "AndroidKeyStorePass":
                        PlayerSettings.Android.keystorePass = item.Value;
                        break;

                    case "AndroidkeyAliasName":
                        PlayerSettings.Android.keyaliasName = item.Value;
                        break;

                    case "AndroidKeyAliasPass":
                        PlayerSettings.Android.keyaliasPass = item.Value;
                        break;

                    case "BuildOptions":
                    {
                        opt = BuildOptions.None;
                        string[] opts = item.Value.Split('|');
                        foreach (string o in opts)
                        {
                            opt = opt | (BuildOptions)System.Enum.Parse(typeof(BuildOptions), o);
                        }
                    }
                    break;

                    case "Outputpath":
                        outputpath = item.Value;
                        break;
                    }
                    UnityEngine.Debug.Log("parse arg -> " + item.Key + " : " + item.Value);
                }
            }
        }