MRが楽しい

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

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

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

Chapter 7:Create the AzureServices class

最初に作成するスクリプトは AzureServices クラスです。
AzureServicesのクラスの役割は以下になります。
・Azure アカウントの資格情報を格納しています。
・Azure アプリケーション機能を呼び出す。

本章ではこのクラスを作成していきます。

1.Script フォルダを作成します。
Asset フォルダで右クリックし、Create > Folder を選択します。
f:id:bluebirdofoz:20181008225701j:plain

2-3.作成した Script フォルダを開き、フォルダ内で右クリックして、Creapte -> C# Script を選択します。
Script の名称は AzureServices に設定します。
f:id:bluebirdofoz:20181008225708j:plain

4.新しいスクリプトをダブルクリックしてVisual Studioで開きます。

5-9.以下の通り、スクリプトを編集します。
・AzureServices.cs

// 名前空間の追加
using System;
using System.Collections;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.File;
using System.IO;
using System.Net;

public class AzureServices : MonoBehaviour {
    // インスペクタフィールドの追加
    /// <summary>
    /// Provides Singleton-like behavior to this class.
    /// このクラスをシングルトンと同じように動作させます
    /// </summary>
    public static AzureServices instance;

    /// <summary>
    /// Reference Target for AzureStatusText Text Mesh object
    /// AzureStatusText Text Meshオブジェクトの参照先
    /// </summary>
    public TextMesh azureStatusText;

    // メンバ変数の追加
    /// <summary>
    /// Holds the Azure Function endpoint - Insert your Azure Function Connection String here.
    /// Azure Function のエンドポイントを保持します 
    /// 第2章で作成した Azure Function のエンドポイントをここに挿入します。
    /// Connection String here.
    /// </summary>
    private string azureFunctionEndpoint = "--Insert here you AzureFunction Endpoint--";

    /// <summary>
    /// Holds the Storage Connection String - Insert your Azure Storage Connection String here.
    /// Azure Storage のエンドポイントを保持します
    /// 第1章で作成した Azure Storage のエンドポイントをここに挿入します。
    /// </summary>
    private string storageConnectionString = "--Insert here you AzureStorage Connection String--";

    /// <summary>
    /// Name of the Cloud Share - Hosts directories.
    /// 共有クラウドの名前 - ホストディレクトリ
    /// </summary>
    private const string fileShare = "fileshare";

    /// <summary>
    /// Name of a Directory within the Share
    /// 共有内のディレクトリ名
    /// </summary>
    private const string storageDirectory = "storagedirectory";

    /// <summary>
    /// The Cloud File
    /// クラウドファイル
    /// </summary>
    private CloudFile shapeIndexCloudFile;

    /// <summary>
    /// The Linked Storage Account
    /// リンクされたストレージアカウント
    /// </summary>
    private CloudStorageAccount storageAccount;

    /// <summary>
    /// The Cloud Client
    /// クラウドクライアント
    /// </summary>
    private CloudFileClient fileClient;

    /// <summary>
    /// The Cloud Share - Hosts Directories
    /// クラウド共有 - ホストディレクトリ
    /// </summary>
    private CloudFileShare share;

    /// <summary>
    /// The Directory in the share that will host the Cloud file
    /// クラウドファイルをホストする共有内のディレクトリ
    /// </summary>
    private CloudFileDirectory dir;


    /// <summary>
    /// Called on initialization
    /// 初期化処理
    /// </summary>
    private void Awake()
    {
        instance = this;
    }

    /// <summary>
    /// Runs at initialization right after Awake method
    /// StartメソッドはAwakeメソッドの直後の初期化時に実行されます
    /// </summary>
    private void Start()
    {
        // Set the Status text to loading, whilst attempting connection to Azure.
        // Azureへの接続を試みている間、ステータステキストを[Loading...]に設定します。
        azureStatusText.text = "Loading...";
    }

    /// <summary>
    /// Call to the Azure Function App to request a Shape.
    /// Azure Function の App を呼び出して図形を要求します。
    /// </summary>
    public async void CallAzureFunctionForNextShape()
    {

    }
}

f:id:bluebirdofoz:20181008225727j:plain
※ エディター上で以下のエラーが表示されることがあります。
(「Feature 'async function' is not available in C# 4. Please use language version 5 or greater」)
これらはエディター上のみのエラーメッセージのため、無視して問題ありません。
以下の記事を参考にしてください。
bluebirdofoz.hatenablog.com

azureFunctionEndpoint を、第2章で作成した Azure Function のエンドポイントで置き換えます。
storageConnectionString を、第1章で作成した Azure Storage の接続用文字列で置き換えます。
f:id:bluebirdofoz:20181008225738j:plain

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

11.Hierarchy パネルの MixedRealityCameraParent を開くと、直下に MixedRealityCamera オブジェクトがあります。
AzureServices スクリプトをこの MixedRealityCamera オブジェクトにドラッグして追加します。
f:id:bluebirdofoz:20181008225754j:plain

12.Hierarchy パネルの GazeButton を開きます。
直下にある AzureStatusText オブジェクトを AzureServices スクリプトの AzureStatusText 変数に設定します。
f:id:bluebirdofoz:20181008225804j:plain

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