Version: 2020.2
言語: 日本語
public static bool SwitchActiveBuildTargetAsync (BuildTargetGroup targetGroup, BuildTarget target);

パラメーター

targetGroup ビルド時の対象プラットフォームを選択します
target ビルドする対象プラットフォームを選択します

戻り値

bool True の場合、ビルドターゲットを正常に切り替えされました。False の場合はそれ以外 ( たとえば、ライセンスチェックを失敗してファイルが見つからなかった、ユーザーが UI を通じて操作をキャンセルした、など ) です。

説明

Select a new build target to be active during the next Editor update.

This function switches to the passed build target as the active build during the next Editor update. It has the same effect as changing the build target via the Build Player dialog in the Editor.

All script files and Assets that are affected by the current platform settings, are recompiled or reimported on the next Editor update when you change the currently active build target that this function returns. See SwitchActiveBuildTarget on how to immediately import Assets.

指定されたターゲットがスタンドアロンターゲットの場合、SwitchActiveBuildTarget を呼び出すことは EditorUserBuildSettings.selectedStandaloneTarget にも影響します。

Note: This function is not available when running the Editor in batch mode because changing the build target requires recompiling script code for the given target which cannot be done while your script code is executing. This is not a problem in in the Editor as the operation is deferred. However, batch mode will immediately exit after having executed the designated script code. Use the buildTarget command-line switch to specify a build target from batch mode.

using UnityEngine;
using UnityEditor;
using UnityEditor.Build;

public class SwitchPlatformExample : IActiveBuildTargetChanged { [MenuItem("Example/Switch Platform")] public static void PerformSwitch() { // Switch to Windows standalone build. EditorUserBuildSettings.SwitchActiveBuildTargetAsync(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows); }

public int callbackOrder { get { return 0; } } public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget) { Debug.Log("Active platform is now " + newTarget); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961