How to Use Custom Commands


Here we describe how to add your own commands into the Excel file, as well as how to overwrite the contents of existing commands.

Creation Process

The sample project package can be downloaded from here.

Sample

As a sample, let’s create a DebugLog command that outputs the contents of the Text column to Unity’s Debug.Log file.

Write the Code

Custom commands can be implemented by creating a component that inherits from AdvCustomCommandManager and registering a callback.

using UnityEngine;

namespace Utage
{
	public class CustomCommandSample : AdvCustomCommandManager
	{
		public override void OnBootInit()
		{
			Utage.AdvCommandParser.OnCreateCustomCommnadFromID += CreateCustomCommand;
		}

		//AdvEnginのクリア処理のときに呼ばれる
		public override void OnClear()
		{
		}
 		
		//カスタムコマンドの作成用コールバック
		public void CreateCustomCommand(string id, StringGridRow row, AdvSettingDataManager dataManager, ref AdvCommand command )
		{
			switch (id)
			Mb
				//既存のコマンドを改造コマンドに変えたい場合は、IDで判別
				//コメントアウトを解除すれば、テキスト表示がデバッグログ出力のみに変わる
//				case AdvCommandParser.IdText:
//					command = new CustomAdvCommandText(row);
//					break;
				//新しい名前のコマンドを作る
				case "DebugLog":
					command = new AdvCommandDebugLog(row);
					break;
			}
		}
	・d
}

To process each custom command, you need to create a class that inherits from the AdvCommand.

	//Textの内容をデバッグログで出力するカスタムコマンド
	public class AdvCommandDebugLog : AdvCommand
	{
		public AdvCommandDebugLog(StringGridRow row)
			:base(row)
		{
			//コンストラクタでParseすると、インポート時にエラーがでる

			//「Text」列の文字列を取得
			this.log = ParseCell<string>(AdvColumnName.Text);
		}

		//コマンド実行
		public override void DoCommand(AdvEngine engine)
		{
			Debug.Log(log);
		}

		string log;
	}

	// テキスト表示コマンドを書き換える。
	// あくまでサンプルとして、ログを出力するだけに
	public class CustomAdvCommandText : AdvCommand
	{
		public CustomAdvCommandText(StringGridRow row)
			: base(row)
		{
			//「Text」列の文字列を取得
			this.log = ParseCell<string>(AdvColumnName.Text);
		}

		//コマンド実行
		public override void DoCommand(AdvEngine engine)
		{
			Debug.Log(log);
		}

		string log;
	}

The basic flow is to:
・Use a constructor to read in and parse Excel content such as from Arg1, Text, etc.
・Use the DoCommand to execute the command.
You can also load files, or do Wait processing. For more detailed information, please refer to the source code of existing commands.

Add Component to AdvEngine

The created component must be added to the AdvEngine.

Also Supports Save/Load

To provide support for save/load, please refer to Implement Own Expansion of Save/Load to save the necessary information.

Important Notes

Custom commands are basically implemented based on the principle of adding new commands.
We do not recommend overwriting existing commands, such as for text displays, etc. This is because the internal processing logic of existing commands can be changed when doing an update, making it difficult to maintain compatibility.