本日はチュートリアルの実施枠です。
Academyの「MR and Azure 303: Natural language understanding (LUIS)」の実施内容をまとめます。
docs.microsoft.com
前回記事の続きです。
bluebirdofoz.hatenablog.com
今回は「Chapter 8」です。
Chapter 8:Create the Gaze Class
最後に作成するスクリプトは Gaze クラスです。
このクラスは現在ユーザーの視覚的なフォーカスにあるGameObjectへの参照を更新します。
1.Script フォルダを開きます。
2.フォルダ内で右クリックして、Creapte -> C# Script を選択します。
Script の名称は Gaze に設定します。
3.新しいスクリプトをダブルクリックしてVisual Studioで開きます。
4.以下の通り、スクリプトを編集します。
・Gaze.cs
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Experimental.XR; using UnityEngine.UI; using UnityEngine.XR; using UnityEngine.XR.WSA.Input; public class Gaze : MonoBehaviour { internal GameObject gazedObject; public float gazeMaxDistance = 300; void Update() { // Uses a raycast from the Main Camera to determine which object is gazed upon. // メインカメラからのレイキャストを使用して、どのオブジェクトが注視されているかを判断します。 Vector3 fwd = gameObject.transform.TransformDirection(Vector3.forward); Ray ray = new Ray(Camera.main.transform.position, fwd); RaycastHit hit; Debug.DrawRay(Camera.main.transform.position, fwd); if (Physics.Raycast(ray, out hit, gazeMaxDistance) && hit.collider != null) { if (gazedObject == null) { gazedObject = hit.transform.gameObject; // Set the gazedTarget in the Behaviours class // Behaviorsクラスでの注視ターゲットを設定します Behaviours.instance.gazedTarget = gazedObject; } } else { ResetGaze(); } } // Turn the gaze off, reset the gazeObject in the Behaviours class. // 注視をオフにし、Behaviorsクラスの注視オブジェクトをリセットします。 public void ResetGaze() { if (gazedObject != null) { Behaviours.instance.gazedTarget = null; gazedObject = null; } } }
5.Visual Studio で変更を保存して Unity に戻ります。
Chapter 8 はここまでです。
次回は Chapter 9 を実施します。
bluebirdofoz.hatenablog.com