facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
2021年8月3日 (火) 17:54時点におけるAdmin (トーク | 投稿記録)による版 (ページの作成:「Assets/Editor/BuildPlayerExample.cs <pre> using UnityEditor; using UnityEngine; using UnityEditor.Build.Reporting; public class BuildPlayerExample : MonoBehaviour { [...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索

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"/*, "Assets/Scene2.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");
        }
    }
}