123. ButtonReceiverExampleのコード
(C) 2018 石井 勇一 123
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using HoloToolkit.Unity;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.Receivers;
using HoloToolkit.Unity.InputModule;
namespace HoloToolkit.Unity.Examples
{
public class ButtonReceiverExample : InteractionReceiver
{
public GameObject textObjectState;
private TextMesh txt;
void Start()
{
txt = textObjectState.GetComponentInChildren<TextMesh>();
}
144. ハンドジェスチャー入力
ISourceStateHandler(手の検出), IInputClickHandler(AirTapの検出)
(C) 2018 石井 勇一 144
public void OnSourceDetected(SourceStateEventData eventData) {
// If the source has positional info and there is currently no visible source
if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.Position))
{
trackedHandsCount++;
}
}
public void OnSourceLost(SourceStateEventData eventData) {
if (eventData.InputSource.SupportsInputInfo(eventData.SourceId, SupportedInputInfo.Position))
{
trackedHandsCount--;
}
}
public void OnInputClicked(InputClickedEventData eventData) {
if ((SpatialUnderstanding.Instance.ScanState == SpatialUnderstanding.ScanStates.Scanning) &&
!SpatialUnderstanding.Instance.ScanStatsReportStillWorking)
{
SpatialUnderstanding.Instance.RequestFinishScan();
}
}
指を検出したタイミングで
メッセージの色を変えるた
めにカウントを記録
十分なデータがえらたタイ
ミングで、AirTapで終了依
頼を発行するために使用
152. PrimaryTextプロパティの処理
ScanStateに合わせてメインメッセージを変更(続き)
(C) 2018 石井 勇一 152
// Scan state
if (SpatialUnderstanding.Instance.AllowSpatialUnderstanding){
switch (SpatialUnderstanding.Instance.ScanState) {
case SpatialUnderstanding.ScanStates.Scanning: //スキャン中
// Get the scan stats
IntPtr statsPtr = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceStatsPtr();
if (SpatialUnderstandingDll.Imports.QueryPlayspaceStats(statsPtr) == 0){
return "playspace stats query failed";
}
// 終了させても良さそうかどうか調べる(これも複雑なコードが付いているプロパティ)
if (DoesScanMeetMinBarForCompletion) {
return "When ready, air tap to finalize your playspace"; // AirTapで終了するというメッセージを表示
}
return "Walk around and scan in your playspace"; // まだ不十分なので歩き回ってスキャンしなさいと表示
:
:
153. PrimaryTextプロパティの処理
ScanStateに合わせてメインメッセージを変更(続き)
(C) 2018 石井 勇一 153
case SpatialUnderstanding.ScanStates.Finishing: // 終了処理中
return "Finalizing scan (please wait)";
case SpatialUnderstanding.ScanStates.Done: // 終了
return "Scan complete - Use the menu to run queries";
default:
return "ScanState = " + SpatialUnderstanding.Instance.ScanState.ToString();
}
}
return "";
}
154. PrimaryColorプロパティの処理
◦ ステータスに合わせてメッセージの色を変更。
(C) 2018 石井 勇一 154
public Color PrimaryColor {
get {
if (SpatialUnderstanding.Instance.ScanState == SpatialUnderstanding.ScanStates.Scanning){
if (trackedHandsCount > 0) {
return DoesScanMeetMinBarForCompletion ? Color.green : Color.red;
}
return DoesScanMeetMinBarForCompletion ? Color.yellow : Color.white;
}
// メニューを見ているときはそれを消す(実際には透明度15%にする)
Vector3 hitPos, hitNormal;
UnityEngine.UI.Button hitButton;
float alpha = AppCursor.RayCastUI(out hitPos, out hitNormal, out hitButton) ? 0.15f : 1.0f;
// 特殊ケース処理 &
return (!string.IsNullOrEmpty(SpaceQueryDescription) || !string.IsNullOrEmpty(ObjectPlacementDescription)) ?
(PrimaryText.Contains("processing") ? new Color(1.0f, 0.0f, 0.0f, 1.0f) : new Color(1.0f, 0.7f, 0.1f, alpha)) :
new Color(1.0f, 1.0f, 1.0f, alpha);
}
}
157. (C) 2018 石井 勇一 157
namespace HoloToolkit.Unity
{
public class SpatialUnderstandingDll {
public class PlayspaceStats {
public int IsWorkingOnStats; // 0 まだ統計を作成している場合
public float HorizSurfaceArea; // In m2 : 床から-0.15~1mの間にある上向きの全ての水平面
public float TotalSurfaceArea; // In m2 : すべて
public float UpSurfaceArea; // In m2 : 床を含むすべての上向きな水平面
public float DownSurfaceArea; // In m2 : 天井を含むすべて下向きの水平面
public float WallSurfaceArea; // In m2 : 壁だけでない、すべての垂直面
public float VirtualCeilingSurfaceArea; // In m2 : 実質的な天井面の推定数
public float VirtualWallSurfaceArea; // In m2 : 実質的な壁の推定数
public int NumFloor; // 各フロアのリスト数(カウントを含む)
public int NumCeiling; // 各天井のリスト数(カウントを含む)
public int NumWall_XNeg; // 各壁においてX軸マイナス方向を向いている数(カウントを含む)
public int NumWall_XPos; // 各壁においてX軸プラス方向を向いている数(カウントを含む)
public int NumWall_ZNeg; // 各壁においてZ軸マイナス方向を向いている数(カウントを含む)
public int NumWall_ZPos; // 各壁においてZ軸プラス方向を向いている数(カウントを含む)
public int NumPlatform; // 床を含まない水平面の数 (例えばテーブルや椅子など)(カウントを含む)
public int CellCount_IsPaintMode; // ペイントセル数(ペイント数で面積が推測できる)=> 1セルにつき8cm×8cm
public int CellCount_IsSeenQualtiy_None; // 見えないセルの数 => 1セルにつき8cm×8cm
public int CellCount_IsSeenQualtiy_Seen; // 見えるセルの数=> 1セルにつき8cm×8cm
public int CellCount_IsSeenQualtiy_Good; // 良質な見えるセルの数 => 1セルにつき8cm×8cm
};
}
}