MRが楽しい

MRやVRについて学習したことを書き残す

公式チュートリアル「MR and Azure 307 8章」を試してみる

本日はチュートリアルの実施枠です。
Academyの「MR and Azure 307: Machine learning」の実施内容をまとめます。
docs.microsoft.com
前回記事の続きです。
bluebirdofoz.hatenablog.com
今回は「Chapter 8」です。

Chapter 8:reate the ShelfKeeper class

ShelfKeeper クラスはUIや製品を制御します。
インポートされたパッケージに含まれる本クラスは不完全です。
本章でクラスを完成させます。

1.Scripts フォルダ内の ShelfKeeper スクリプトをダブルクリックしてVisual Studioで開きます。
f:id:bluebirdofoz:20181121022358j:plain

2.以下の通り、スクリプトを編集します。
・ShelfKeeper.cs

using UnityEngine;

public class ShelfKeeper : MonoBehaviour
{
    /// <summary>
    /// Provides this class Singleton-like behavior
    /// このクラスをシングルトンと同じように動作させます
    /// </summary>
    public static ShelfKeeper instance;

    /// <summary>
    /// Unity Inspector accessible Reference to the Text Mesh object needed for data
    /// 日付の表示に必要なText Meshオブジェクトへの参照
    /// </summary>
    public TextMesh dateText;

    /// <summary>
    /// Unity Inspector accessible Reference to the Text Mesh object needed for time
    /// 時間の表示に必要なText Meshオブジェクトへの参照
    /// </summary>
    public TextMesh timeText;

    /// <summary>
    /// Provides references to the spawn locations for the products prefabs
    /// プレハブ製品のスポーン場所への参照を提供する
    /// </summary>
    public Transform[] spawnPoint;

    private void Awake()
    {
        instance = this;
    }

    /// <summary>
    /// Set the text of the date in the scene
    /// シーン内の日付のテキストを設定する
    /// </summary>
    public void SetDate(string day, string month)
    {
        dateText.text = day + " " + month;
    }

    /// <summary>
    /// Set the text of the time in the scene
    /// シーンの時間のテキストを設定する
    /// </summary>
    public void SetTime(string hour)
    {
        timeText.text = hour + ":00";
    }

    /// <summary>
    /// Spawn a product on the shelf by providing the name and selling grade
    /// 名前と販売のグレードを指定して棚に商品をスポーンする
    /// </summary>
    /// <param name="name"></param>
    /// <param name="sellingGrade">0 being the best seller</param>
    public void SpawnProduct(string name, int sellingGrade)
    {
        Instantiate(Resources.Load(name),
            spawnPoint[sellingGrade].transform.position, spawnPoint[sellingGrade].transform.rotation);
    }
}

f:id:bluebirdofoz:20181121022410j:plain

3.Visual Studio で変更を保存して Unity に戻ります。
f:id:bluebirdofoz:20181121022419j:plain

4.Chapter 7 で MRTK を用いたシーン設定を行っている場合、以下の通り、ShelfKeeper をメインカメラに設定します。
Hierarchy の MixedRealityCameraParent を開きます。
直下の MixedRealityCamera を選択し、ShelfKeeper をアタッチします。
f:id:bluebirdofoz:20181121022430j:plain

5.インスペクタパネルから ShelfKeeper の各フィールドに以下の通り、設定を行います。

DateText:TimeDisplay/Date オブジェクト
TimeText:TimeDisplay/Timeオブジェクト
SpawnPoint
  Size:3
  Element0:Shelf/SpawnPoints/SpawnPoint(0)
  Element1:Shelf/SpawnPoints/SpawnPoint(1)
  Element2:Shelf/SpawnPoints/SpawnPoint(2)

f:id:bluebirdofoz:20181121022442j:plain

Chapter 8 はここまでです。
次回は Chapter 9 を実施します。
bluebirdofoz.hatenablog.com