SendMessage


If using a Utage scenario, it calls a Unit processing program. Used for simple extension functionality.

Sample

Reference

Command Description Arg1 Arg2 Arg3 Arg4 Arg5 Arg6
SendMessage SendMessage to an object configured beforehand outside AdvEngine.
Used for simple extension functionality.
Name for identification Optional Optional Optional Optional Optional

By using SendMessage, you can call your own process on Unity from a Utage scenario.

Preparation for Using SendMessage

To receive a SendMessage, you set an object for receiving a message in the AdvScenarioPlayer component.

Use drag and drop to set the object with the attached component for receiving messages.

Sample for Receiving a SendMessage

You need to use AddComponent to add a script for receiving messages to the RecievMessage object.

The component for receiving messages needs the following two methods:

  • OnDoCommand: method for receiving the contents of the SendMessage command.
  • OnWait: method for making the SendMessage command wait.

Let’s have a look at the sample.

    using UnityEngine;
    using UnityEngine.UI;
    using Utage;


    /// <summary>
    /// ADV用SendMessageコマンドから送られたメッセージを受け取る処理のサンプル
    /// </summary>
    [AddComponentMenu("Utage/ADV/Examples/UtageRecieveMessageSample")]
    public class UtageRecieveMessageSample : MonoBehaviour
    {
        public AdvEngine engine;            //Advエンジン本体
        public InputField inputFiled;       //テキスト入力用のオブジェクト

        void Awake()
        {
            inputFiled.gameObject.SetActive(false);
        }

        //SendMessageコマンドが実行されたタイミング
        void OnDoCommand(AdvCommandSendMessage command)
        {
            switch (command.Name)
            {
                case "DebugLog":
                    DebugLog(command);
                    break;
                case "InputFileld":
                    InputFileld(command);
                    break;
                default:
                    Debug.Log("Unknown Message:" + command.Name );
                    break;
            }
        }

        //SendMessageコマンドの処理待ちタイミング
        void OnWait(AdvCommandSendMessage command)
        {
            switch (command.Name)
            {
                case "InputFileld":
                    //インプットフィールドが有効な間は待機
                    command.IsWait = inputFiled.gameObject.activeSelf;
                    break;
                default:
                    command.IsWait = false;
                    break;
            }
        }

        //デバッグログを出力
        void DebugLog(AdvCommandSendMessage command)
        {
            Debug.Log(command.Arg2);
        }

        //設定された入力フィールドを有効化
        void InputFileld(AdvCommandSendMessage command)
        {
            inputFiled.gameObject.SetActive(true);
            inputFiled.onEndEdit.RemoveAllListeners();
            inputFiled.onEndEdit.AddListener((string text) => OnEndEditInputFiled(command.Arg2, text));
        }

        //入力終了。入力されたテキストを宴のパラメーターに設定する
        void OnEndEditInputFiled(string paramName, string text)
        {
            if (!engine.Param.TrySetParameter(paramName, text))
            {
                Debug.LogError(paramName + "is not found");
            }
            inputFiled.gameObject.SetActive(false);
        }
    }

Please note that this is just a sample.
Feel free to copy this script or create a different script with a different name.
Please change the content of OnDoCommand and OnWait depending on the type of processing that you want to implement.

command.Name contains the characters set in Arg1 of the SendMessage command on the Excel sheet.
Please enter your own extension processing using switch by setting Arg1 as the name of your own extension process.

Arg2 to Arg5 of the command members contain character strings, so feel free to use them as you wish.

Supplementary Information: Using Utage Parameters

In addition, the parameters used in Utage scenarios can be accessed from a script as shown below:

        public AdvEngine engine;
        void Hoge()
        {
            engine.Param.GetParameter("flag1");
            engine.Param.TrySetParameter("flag1",true);
        }

One way in which this can be used is, for example, if you want to implement complex calculations, etc. you can call for a calculation process at the time of doing a SendMessage and you can then set only that result in the engine.Param.

Important Notes

Please note that Utage’s save/load functionality will not work with any of your own functionality set on Unity using SendMessage.
For example, even if you were to try using this functionality to display your own object, it would actually disappear after being loaded.
Basically, if the page has a process that runs until it is completed, this would have no impact on any save/load operation, hence you would be fine as long as the process does not attempt to skip over pages.
In addition, if you were to save the result of SendMessage in a parameter as shown in this sample, this way of using it would also be fine as it would be saved/loaded correctly.

Of course, you can also feel free to use it if you are not doing any save/load operations.