facebook twitter hatena line email

Unity/Editor/プレイヤービルド

提供: 初心者エンジニアの簡易メモ
2021年8月3日 (火) 17:54時点におけるAdmin (トーク | 投稿記録)による版

移動: 案内検索

Assets/Editor/BuildPlayerExample.cs

using UnityEditor;
using UnityEngine;
using UnityEditor.Build.Reporting;
public class BuildPlayerExample : MonoBehaviour
{
    [MenuItem("Build/Build WebGL")]
    public static void MyBuild()
    {
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scenes/SampleScene.unity" };
        buildPlayerOptions.locationPathName = "WebGLBuild"; // 生成されるビルドのディレクトリ名
        buildPlayerOptions.target = BuildTarget.WebGL;
        buildPlayerOptions.options = BuildOptions.None;
        BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
        BuildSummary summary = report.summary;
        if (summary.result == BuildResult.Succeeded)
        {
            Debug.Log("Build succeeded: " + summary.totalSize + " bytes");
        }
        if (summary.result == BuildResult.Failed)
        {
            Debug.Log("Build failed");
        }
    }
}