浏览代码

Code cleanup of the body height scale test script.

/3.1
Todd Stinson 5 年前
当前提交
0c870c08
共有 1 个文件被更改,包括 9 次插入24 次删除
  1. 33
      Assets/Scripts/TestBodyAnchorScale.cs

33
Assets/Scripts/TestBodyAnchorScale.cs


using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;

void OnEnable()
{
Debug.Assert(m_ImageInfo != null, "need a text field");
Debug.Assert(m_ImageInfo != null, "text field is required");
m_ImageInfo.enabled = true;
Debug.Assert(m_HumanBodyManager != null, "Human body manager is required.");

void OnDisable()
{
Debug.Assert(m_ImageInfo != null, "need a text field");
Debug.Assert(m_ImageInfo != null, "text field is required");
m_ImageInfo.enabled = false;
Debug.Assert(m_HumanBodyManager != null, "Human body manager is required.");

void OnHumanBodiesChanged(ARHumanBodiesChangedEventArgs eventArgs)
{
bool hasScale = false;
float scale = 0.0f;
// Currently, the ARKit provider only ever produces one body anchor, so just reference the first
float scale = ((eventArgs.added.Count > 0) ? eventArgs.added[0].estimatedHeightScaleFactor
: ((eventArgs.updated.Count > 0) ? eventArgs.updated[0].estimatedHeightScaleFactor
: Single.NaN));
foreach (var humanBody in eventArgs.added)
{
if (!hasScale)
{
scale = humanBody.estimatedHeightScaleFactor;
hasScale = true;
}
}
foreach (var humanBody in eventArgs.updated)
{
if (!hasScale)
{
scale = humanBody.estimatedHeightScaleFactor;
hasScale = true;
}
}
Debug.Assert(m_ImageInfo != null, "need a text field");
m_ImageInfo.text = hasScale ? scale.ToString("F10") : "<no scale>";
Debug.Assert(m_ImageInfo != null, "text field is required");
m_ImageInfo.text = scale.ToString("F10");
}
}
正在加载...
取消
保存