如何使用PHP在后台以批处理模式启动Unity



我正在尝试使用-executeMethod以批处理模式启动Unity实例,以使用以下命令构建2000多个纹理的资产包:

"C:Program FilesUnityHubEditor2020.3.1f1EditorUnity.exe" -batchmode -projectPath "D:UnityWorkbench2020Build Texture Asset Bundle" -executeMethod DummyNamespace.TexturesManager.BuildTextureAssetBundles -env TEST

现在,我想使用PHP创建一个REST API,以便在AWS EC2 windows服务器上执行此命令。我使用下面的脚本来启动实例,并在unity项目中执行静态方法。

<?php
$commandStr = '"C:Program FilesUnityHubEditor2020.3.1f1EditorUnity.exe" -batchmode -projectPath "D:UnityWorkbench2020Build Texture Asset Bundle" -executeMethod DummyNamespace.TexturesManager.BuildTextureAssetBundles -env TEST';
$output=null;
$retval=null;
exec($commandStr, $output, $retval);
echo "retval: ".$retval."nn";
echo "output: ".$output."nn";
?>

此脚本启动统一实例,然后等待执行以返回响应。因此,当它在资产包中构建2000多个图像时,它总是会达到PHP请求超时,这可能需要一些时间才能完成。

如何让它在后台以批处理模式启动实例,并立即返回是否启动的响应?

附言-我试过pclose(popen($commandStr,'r'((;但这根本没有启动团结的实例。请帮忙!

在搜索并尝试了几天不同的方法后,我终于按照这里类似的SO问题中所说的做了。在我的情况下,命令也将以批处理模式启动Unity实例。

代码如下:

<?php
$commandStr = '"C:Program FilesUnityHubEditor2020.3.1f1EditorUnity.exe" -batchmode -projectPath "D:UnityWorkbench2020Build Texture Asset Bundle" -executeMethod DummyNamespace.TexturesManager.BuildTextureAssetBundles -env TEST';
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($commandStr, 0, false);
if($oExec==0){
echo 'Unity started in background!'
} else {
echo 'Failure starting Unity in background!'
}
?>

最新更新