コマンドを追加する

AutomationTool に自動化プロジェクトを追加する方法を説明します。

Choose your operating system:

Windows

macOS

Linux

前提トピック

このページは以下のトピックへの知識があることを前提にしています。まず以下のトピックの内容についてご確認をお願いします。

コンテンツ

次の例では、フィボナッチ数列が出力されると正常に終了するサンプル コマンドを使用します。この例に従って、自動化プロジェクトに新しいコマンド (スクリプト) を追加します。

手順

必須手順 :続行する前に、空の「 *.cs 」ソース ファイルが自動化プロジェクトのスコープ内にあることを確認します。

  1. まず、ソース ファイルに名前を付けます。この例では、「 SimpleScript.cs 」としました。

  2. 次に、次のサンプル コードをスクリプトにコピーします。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using AutomationTool;
    
    namespace SampleScript.Automation
    {
        // Use [Help()] attributes to document your command and its arguments. (コマンドとその引数をドキュメント化するには、[Help()] 属性を使用します。)
        [Help("Sample script printing a Fibonacci sequence of values.")]
        [Help("Usage: SampleScript -Terms=<N>")]
        [Help("Terms=<N>", "N (int) represents how many terms to compute, and it must be greater than or equal to 1.")]
    
    // BuildCommand is the base class for all commands. (BuildCommand はすべてのコマンドの基本クラスです。)
        public class SampleCommand :BuildCommand
        {
            public override void ExecuteBuild()
            {
                // The ParseParamInt() method retrieves a command line argument for this example. (ParseParamInt() メソッドは、この例のコマンドライン引数を取得します。ParseParam() は bool 値を取得し、ParseParamValue は文字列を取得します。)ParseParam() retrieves a bool, and ParseParamValue retrieves a string.
                int NumTerms = ParseParamInt("Terms");
                if (NumTerms < 1)
                {
                    throw new AutomationException("Invalid number of terms specified.Enter -help for syntax.");
                }
                else
                {
                    LogInformation("Fibonnacci sequence:");
    
                    int TermA = 1;
                    int TermB = 1;
                    for (int TermIdx = 0; TermIdx < NumTerms; TermIdx++)
                    {
                        LogInformation("  {0}", TermA);
    
                        int NextTerm = TermA + TermB;
                        TermA = TermB;
                        TermB = NextTerm;
                    }
                }
            }
        }
    }
  3. 最後に、コマンド プロンプトを開いて、「 Engine\Build\BatchFiles 」に移動し、「 RunUAT.bat SampleCommand -terms=4 」と入力します。

最終結果

次の出力が表示されます。

AddingaCommand_EndResult.png

Unreal Engine のドキュメントを改善するために協力をお願いします!どのような改善を望んでいるかご意見をお聞かせください。
調査に参加する
閉じる