MRが楽しい

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

HoloLens2でホロモンアプリを作る その33(ホロモンが見ているものを判別する)

本日はアプリ作成枠です。
HoloLens2でホロモンアプリを作る進捗を書き留めていきます。
f:id:bluebirdofoz:20210429224411j:plain

今回はホロモンが見ているものを判別するメモです。

ホロモンが見ているものを判別する

前回まででホロモンが様々なオブジェクトを検知できるようになりました。
bluebirdofoz.hatenablog.com

今回はホロモンがオブジェクトを判別できるように、以下のような共通の特徴クラスを作成しました。
・ObjectFeatures.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HMProject.HoloMon
{
    public class ObjectFeatures : MonoBehaviour
    {
        [SerializeField, Tooltip("ホロモンが知っているオブジェクトの特徴")]
        public HoloMonKnownObjectFeatures Features;
    }
}

・HolomonCommonEnum.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace HMProject.HoloMon
{
    // 共通定義

    /// <summary>
    /// ホロモンが知っているオブジェクトの特徴
    /// </summary>
    public enum HoloMonKnownObjectFeatures
    {
        Nothing,                       // なし
        LearnLater,                    // 追加学習の特徴
        HoloFriend_Head,               // 友達の顔(通常)
        HoloFriend_Head_Tilt,          // 友達の顔(首を傾げる)
        HoloFriend_RightHand,          // 友達の右手(通常)
        HoloFriend_RightHand_Gur,      // 友達の右手(グー)
        HoloFriend_RightHand_Choki,    // 友達の右手(チョキ)
        HoloFriend_RightHand_Par,      // 友達の右手(パー)
        HoloFriend_RightHand_Pistol,   // 友達の右手(ピストル)
        HoloFriend_RightHand_ThumbsUp, // 友達の右手(サムズアップ)
        HoloFriend_LeftHand,           // 友達の左手(通常)
        HoloFriend_LeftHand_Gur,       // 友達の左手(グー)
        HoloFriend_LeftHand_Choki,     // 友達の左手(チョキ)
        HoloFriend_LeftHand_Par,       // 友達の左手(パー)
        HoloFriend_LeftHand_Pistol,    // 友達の左手(ピストル)
        HoloFriend_LeftHand_ThumbsUp,  // 友達の左手(サムズアップ)
        Meal_Food,                     // 食べ物(お肉)
        Shit,                          // うんち
        Attention,                     // 注目物
    }
}

f:id:bluebirdofoz:20210429224435j:plain

このスクリプトをオブジェクトに設定することで、ホロモンがオブジェクトの特徴を理解できるようにします。
f:id:bluebirdofoz:20210429224449j:plain

視界の検知スクリプトには以下の特徴取得のコードを設定します。
共通クラスが設定されていない場合は、オブジェクト名を特徴として取得するようにしています。

        /// <summary>
        /// オブジェクトの特徴からホロモンのオブジェクト理解を取得する
        /// </summary>
        /// <returns></returns>
        public ObjectUnderstand GetObjectUnderstandType(GameObject a_GameObject)
        {
            // オブジェクトの特徴を取得する(規定クラスが設定されていない場合はオブジェクト名を特徴として取得する)
            string objectFeatures = a_GameObject.GetComponent<ObjectFeatures>()?.Features.ToString() ?? a_GameObject.name;

            return p_ObjectUnderstandDatabase.GetObjectUnderstandType(objectFeatures);
        }

これでホロモンがオブジェクトを発見した際、そのオブジェクトの種別を理解できるようになりました。
f:id:bluebirdofoz:20210429224504j:plain