设置完参数化构建过程后的面板如下:



将参数传递到Python脚本中:

P4_Version = os.environ["P4_Version"];  #P4版本号
P4_Version = P4_Version.strip();

DevelopmentBuild = os.environ["DevelopmentBuild"];  #DevelopmentBuild
DevelopmentBuild = DevelopmentBuild.strip();

Unity_Version = os.environ["Unity_Version"];  #Unity的Build Setting版本号
Unity_Version = Unity_Version.strip();

Bundle_Version_Code = os.environ["Bundle_Version_Code"];  #Unity中Build Setting的Bundle Version Code
Bundle_Version_Code = Bundle_Version_Code.strip();

Scripting_Define_Symbols = os.environ["Scripting_Define_Symbols"]; #Unity中的宏定义
Scripting_Define_Symbols = Scripting_Define_Symbols.strip();

P4_Path = os.environ["P4_Path"];   #分支或主支的服务器路径,格式如上(默认为主支路径)
P4_Path = P4_Path.strip();

def GetEnviromentParam():
    print(P4_Version);
    print(DevelopmentBuild);
    print(Unity_Version);
    print(Bundle_Version_Code);
    print(Scripting_Define_Symbols);
    print(P4_Path);
    print("获取环境化参数完成!~");

将参数传递到Unity中:

Python脚本中执行以下代码:

def AutoPack():
    cmdLine = "";
    cmdLine += "cd/d D:\Program Files\Unity5.3.4p4\Editor\n";
    cmdLine += "Unity.exe -batchMode -projectPath " + localClientPath + " -executeMethod AndroidAutoVersionTool.MyMethod -quit ";
    cmdLine += DevelopmentBuild + " ";
    cmdLine += Unity_Version + " ";
    cmdLine += Bundle_Version_Code + " ";
    cmdLine += Scripting_Define_Symbols;
    print(cmdLine);

    cmdPath = "G:/Key_doc.bat";
    fdoc = open(cmdPath, "w");
    fdoc.write(cmdLine);
    fdoc.close();
    print("命令行文件生成完成!~");

    ExecuteCmd(cmdPath);
    print("OK!~");

Unity中执行以下代码,获取对应的参数:

 static void MyMethod()
    {
        SwitchToAndroidPlatform();
        commandList.Clear();
        Caching.CleanCache();
        foreach(string arg in System.Environment.GetCommandLineArgs())
        {
            commandList.Add(arg);
		}
        bool DevelopmentBuild = false;
        string Unity_Version = "";
        int Bundle_Version_Code = 101;
        string Scripting_Define_Symbols = "";

        DevelopmentBuild = bool.Parse(commandList[commandList.Count - 4]);
        Unity_Version = commandList[commandList.Count - 3].ToString();
        Bundle_Version_Code = int.Parse(commandList[commandList.Count - 2]);
        Scripting_Define_Symbols = commandList[commandList.Count - 1].ToString();
        Scripting_Define_Symbols = Scripting_Define_Symbols.Replace(',', ';');
    }


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐