如何从命令行将Unity3D游戏项目编译为WebGL?

jim*_*r04 5 unity-game-engine

我已经实现将其编译为Windows或Mac,但是使用WebGL却没有运气。

看我的台词

从Windows到Windows(将它们放在.bat文件中)

set mypath=%cd%
@echo %mypath%
"C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -logFile stdout.log -projectPath %mypath% -buildWindowsPlayer "builds\mygame.exe"
Run Code Online (Sandbox Code Playgroud)

从Linux到Windows(将它们放在.sh文件中)

#/bin/bash
projectPath=`pwd`
xvfb-run --auto-servernum --server-args='-screen 0 1024x768x24:32' /opt/Unity/Editor/Unity -batchmode -nographics -logfile stdout.log -force-opengl -quit -projectPath ${projectPath} -buildWindowsPlayer "builds/mygame.exe"
Run Code Online (Sandbox Code Playgroud)

从Windows或Linux到Mac:更换-buildWindowsPlayer-buildOSXPlayermygame.exemygame.app

但是,我遇到了WebGL的麻烦。Unity3D的文档:https ://docs.unity3d.com/Manual/CommandLineArguments.html 没有提供任何帮助

有命令参数 -buildTarget webgl,
但是没有任何反应。

HEEEEEEEELLLLLLLLLLLLLPPPPPPP !!!! :(

jim*_*r04 7

好吧,我找到了

制作一个文件夹Assets / Editor

并放置cs脚本

using UnityEditor;
class WebGLBuilder {
    static void build() {

        // Place all your scenes here
        string[] scenes = {"Assets/scenes/S_MainMenu.unity", 
                            "Assets/scenes/S_Login.unity",
                            "Assets/scenes/S_Help.unity",
                            "Assets/scenes/S_1.unity",
                            "Assets/scenes/S_Reward.unity",
                            "Assets/scenes/S_Credits.unity",
                            "Assets/scenes/S_Settings.unity",
                            "Assets/scenes/S_SceneSelector.unity"};

        string pathToDeploy = "builds/WebGLversion/";       

        BuildPipeline.BuildPlayer(scenes, pathToDeploy, BuildTarget.WebGL, BuildOptions.None);      
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以使用以下bat文件从命令行进行编译:

    set mypath=%cd%
    @echo %mypath%
    "C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -logFile
 stdout.log -projectPath %mypath% -executeMethod WebGLBuilder.build
Run Code Online (Sandbox Code Playgroud)

即WebGLBuilder成为可从命令行使用的参数。