Todd Stinson
5 年前
当前提交
46afd02c
共有 3 个文件被更改,包括 284 次插入 和 5 次删除
-
202Assets/Scenes/HumanSegmentation/HumanBodyTracking3D.unity
-
76Assets/Scripts/TestBodyAnchorScale.cs
-
11Assets/Scripts/TestBodyAnchorScale.cs.meta
|
|||
using UnityEngine; |
|||
using UnityEngine.UI; |
|||
using UnityEngine.XR.ARFoundation; |
|||
|
|||
public class TestBodyAnchorScale : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
[Tooltip("The ARHumanBodyManager which will produce frame events.")] |
|||
ARHumanBodyManager m_HumanBodyManager; |
|||
|
|||
/// <summary>
|
|||
/// Get or set the <c>ARHumanBodyManager</c>.
|
|||
/// </summary>
|
|||
public ARHumanBodyManager humanBodyManager |
|||
{ |
|||
get { return m_HumanBodyManager; } |
|||
set { m_HumanBodyManager = value; } |
|||
} |
|||
|
|||
[SerializeField] |
|||
Text m_ImageInfo; |
|||
|
|||
/// <summary>
|
|||
/// The UI Text used to display information about the image on screen.
|
|||
/// </summary>
|
|||
public Text imageInfo |
|||
{ |
|||
get { return m_ImageInfo; } |
|||
set { m_ImageInfo = value; } |
|||
} |
|||
|
|||
void OnEnable() |
|||
{ |
|||
Debug.Assert(m_ImageInfo != null, "need a text field"); |
|||
m_ImageInfo.enabled = true; |
|||
|
|||
Debug.Assert(m_HumanBodyManager != null, "Human body manager is required."); |
|||
m_HumanBodyManager.humanBodiesChanged += OnHumanBodiesChanged; |
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
Debug.Assert(m_ImageInfo != null, "need a text field"); |
|||
m_ImageInfo.enabled = false; |
|||
|
|||
Debug.Assert(m_HumanBodyManager != null, "Human body manager is required."); |
|||
m_HumanBodyManager.humanBodiesChanged -= OnHumanBodiesChanged; |
|||
} |
|||
|
|||
void OnHumanBodiesChanged(ARHumanBodiesChangedEventArgs eventArgs) |
|||
{ |
|||
bool hasScale = false; |
|||
float scale = 0.0f; |
|||
|
|||
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>"; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f7a99cf97577b431494054a0b0e5f423 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue