本日はチュートリアルの実施枠です。
Academyの「MR and Azure 303: Natural language understanding (LUIS)」の実施内容をまとめます。
docs.microsoft.com
前回記事の続きです。
bluebirdofoz.hatenablog.com
今回は「Chapter 7」です。
Chapter 7:Create the Behaviours class
3つ目に作成するスクリプトは Behaviors クラスです。
このクラスは LuisManager クラスによって提供されるエンティティを使用してアクションをトリガーします。
1.Script フォルダを開きます。
2.フォルダ内で右クリックして、Creapte -> C# Script を選択します。
Script の名称は Behaviors に設定します。
3.新しいスクリプトをダブルクリックしてVisual Studioで開きます。
4-7.以下の通り、スクリプトを編集します。
・Behaviors.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Behaviours : MonoBehaviour { // メンバ変数の追加 // help to access instance of this object // このオブジェクトのインスタンスにアクセスするのに利用します public static Behaviours instance; // the following variables are references to possible targets // 次の変数は操作可能なターゲットへの参照です public GameObject sphere; public GameObject cylinder; public GameObject cube; internal GameObject gazedTarget; /// <summary> /// Initialises this class /// 初期化クラス /// </summary> void Awake() { // allows this class instance to behave like a singleton // このクラスをシングルトンと同じように動作させます instance = this; } /// <summary> /// Changes the color of the target GameObject by providing the name of the object /// and the name of the color /// オブジェクトの名前と色を指定して、ターゲット GameObject の色を変更します /// </summary> public void ChangeTargetColor(string targetName, string colorName) { GameObject foundTarget = FindTarget(targetName); if (foundTarget != null) { Debug.Log("Changing color " + colorName + " to target: " + foundTarget.name); switch (colorName) { case "blue": foundTarget.GetComponent<Renderer>().material.color = Color.blue; break; case "red": foundTarget.GetComponent<Renderer>().material.color = Color.red; break; case "yellow": foundTarget.GetComponent<Renderer>().material.color = Color.yellow; break; case "green": foundTarget.GetComponent<Renderer>().material.color = Color.green; break; case "white": foundTarget.GetComponent<Renderer>().material.color = Color.white; break; case "black": foundTarget.GetComponent<Renderer>().material.color = Color.black; break; } } } /// <summary> /// Reduces the size of the target GameObject by providing its name /// ターゲット GameObject の名前を指定することによってそのサイズを縮小します /// </summary> public void DownSizeTarget(string targetName) { GameObject foundTarget = FindTarget(targetName); foundTarget.transform.localScale -= new Vector3(0.5F, 0.5F, 0.5F); } /// <summary> /// Increases the size of the target GameObject by providing its name /// ターゲット GameObject の名前を指定することによってそのサイズを拡大します /// </summary> public void UpSizeTarget(string targetName) { GameObject foundTarget = FindTarget(targetName); foundTarget.transform.localScale += new Vector3(0.5F, 0.5F, 0.5F); } /// <summary> /// Determines which obejct reference is the target GameObject by providing its name /// オブジェクトの名前を指定することで、ターゲット GameObject の参照先を決定します /// </summary> private GameObject FindTarget(string name) { GameObject targetAsGO = null; switch (name) { case "sphere": targetAsGO = sphere; break; case "cylinder": targetAsGO = cylinder; break; case "cube": targetAsGO = cube; break; // as an example of target words that the user may use when looking at an object // オブジェクトを見ているとき、ユーザが使用するターゲット単語の例として使用する case "this": // as this is the default, these are not actually needed in this example // これらはデフォルトの処理であるため、この例では実際には case は必要ありません case "it": case "that": // if the target name is none of those above, check if the user is looking at something // ターゲット名が上記のいずれでもない場合、ユーザーが何かを見ているかでターゲットを設定します default: if (gazedTarget != null) { targetAsGO = gazedTarget; } break; } return targetAsGO; } }
8.Visual Studio で変更を保存して Unity に戻ります。
Chapter 7 はここまでです。
次回は Chapter 8 を実施します。
bluebirdofoz.hatenablog.com