浏览代码

Adding a drop-down UI to allow for the setting of the configuration chooser.

/4.1
Todd Stinson 4 年前
当前提交
79f03d67
共有 4 个文件被更改,包括 1069 次插入51 次删除
  1. 950
      Assets/Scenes/Configurations/ConfigurationChooser.unity
  2. 101
      Assets/Scripts/DisplayARSessionInformation.cs
  3. 8
      Assets/Scripts/TestCameraSwapper.cs
  4. 61
      Assets/Scripts/TestConfigurationChooser.cs

950
Assets/Scenes/Configurations/ConfigurationChooser.unity
文件差异内容过多而无法显示
查看文件

101
Assets/Scripts/DisplayARSessionInformation.cs


using System;
using Unity.Collections;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.XR.ARFoundation;
namespace UnityEngine.XR.ARFoundation.Samples

m_StringBuilder.Clear();
// Log the various manager states.
LogCameraManger();
LogPlaneManger();
LogOcclusionManger();
BuildCameraMangerInfo(m_StringBuilder);
BuildPlaneMangerInfo(m_StringBuilder);
BuildOcclusionMangerInfo(m_StringBuilder);
// If there is a text UI, set the text to the UI. Otherwise, debug log to console.
if (m_InfoText == null)
{
Debug.Log(m_StringBuilder.ToString());
}
else
{
m_InfoText.text = m_StringBuilder.ToString();
}
LogText(m_StringBuilder.ToString());
void LogCameraManger()
/// <summary>
/// Construct the camera manager information.
/// </summary>
void BuildCameraMangerInfo(StringBuilder stringBuilder)
m_StringBuilder.Append("ARCameraManager\n");
stringBuilder.AppendLine("ARCameraManager");
m_StringBuilder.Append(" <null>\n");
stringBuilder.AppendLine(" <null>");
m_StringBuilder.Append(" <disabled>\n");
stringBuilder.AppendLine(" <disabled>");
m_StringBuilder.Append(" Facing direction:\n");
m_StringBuilder.Append($" Requested: {m_CameraManager.requestedFacingDirection}\n");
m_StringBuilder.Append($" Current: {m_CameraManager.currentFacingDirection}\n");
m_StringBuilder.Append(" Auto-focus:\n");
m_StringBuilder.Append($" Requested: {m_CameraManager.autoFocusRequested}\n");
m_StringBuilder.Append($" Current: {m_CameraManager.autoFocusEnabled}\n");
stringBuilder.AppendLine(" Facing direction:");
stringBuilder.AppendLine($" Requested: {m_CameraManager.requestedFacingDirection}");
stringBuilder.AppendLine($" Current: {m_CameraManager.currentFacingDirection}");
stringBuilder.AppendLine(" Auto-focus:");
stringBuilder.AppendLine($" Requested: {m_CameraManager.autoFocusRequested}");
stringBuilder.AppendLine($" Current: {m_CameraManager.autoFocusEnabled}");
void LogPlaneManger()
/// <summary>
/// Construct the plane manager information.
/// </summary>
void BuildPlaneMangerInfo(StringBuilder stringBuilder)
m_StringBuilder.Append("ARPlaneManager\n");
stringBuilder.AppendLine("ARPlaneManager");
m_StringBuilder.Append(" <null>\n");
stringBuilder.AppendLine(" <null>");
m_StringBuilder.Append(" <disabled>\n");
stringBuilder.AppendLine(" <disabled>");
m_StringBuilder.Append(" Detection mode:\n");
m_StringBuilder.Append($" Requested: {m_PlaneManager.requestedDetectionMode}\n");
m_StringBuilder.Append($" Current: {m_PlaneManager.currentDetectionMode}\n");
stringBuilder.AppendLine(" Detection mode:");
stringBuilder.AppendLine($" Requested: {m_PlaneManager.requestedDetectionMode}");
stringBuilder.AppendLine($" Current: {m_PlaneManager.currentDetectionMode}");
void LogOcclusionManger()
/// <summary>
/// Construct the occlusion manager information.
/// </summary>
void BuildOcclusionMangerInfo(StringBuilder stringBuilder)
m_StringBuilder.Append("AROcclusionManager\n");
stringBuilder.AppendLine("AROcclusionManager");
m_StringBuilder.Append(" <null>\n");
stringBuilder.AppendLine(" <null>");
m_StringBuilder.Append(" <disabled>\n");
stringBuilder.AppendLine(" <disabled>");
m_StringBuilder.Append(" Human stencil mode:\n");
m_StringBuilder.Append($" Requested: {m_OcclusionManager.requestedHumanStencilMode}\n");
m_StringBuilder.Append($" Current: {m_OcclusionManager.currentHumanStencilMode}\n");
m_StringBuilder.Append(" Human depth mode:\n");
m_StringBuilder.Append($" Requested: {m_OcclusionManager.requestedHumanDepthMode}\n");
m_StringBuilder.Append($" Current: {m_OcclusionManager.currentHumanDepthMode}\n");
stringBuilder.AppendLine(" Environment depth mode:");
stringBuilder.AppendLine($" Requested: {m_OcclusionManager.requestedEnvironmentDepthMode}");
stringBuilder.AppendLine($" Current: {m_OcclusionManager.currentEnvironmentDepthMode}");
stringBuilder.AppendLine(" Human stencil mode:");
stringBuilder.AppendLine($" Requested: {m_OcclusionManager.requestedHumanStencilMode}");
stringBuilder.AppendLine($" Current: {m_OcclusionManager.currentHumanStencilMode}");
stringBuilder.AppendLine(" Human depth mode:");
stringBuilder.AppendLine($" Requested: {m_OcclusionManager.requestedHumanDepthMode}");
stringBuilder.AppendLine($" Current: {m_OcclusionManager.currentHumanDepthMode}");
}
}
/// <summary>
/// Log the given text to the screen if the image info UI is set. Otherwise, log the string to debug.
/// </summary>
/// <param name="text">The text string to log.</param>
void LogText(string text)
{
if (m_InfoText != null)
{
m_InfoText.text = text;
}
else
{
Debug.Log(text);
}
}
}

8
Assets/Scripts/TestCameraSwapper.cs


using System;
using System.Text;
using Unity.Collections;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.XR.ARFoundation;
namespace UnityEngine.XR.ARFoundation.Samples

/// <summary>
/// The camera manager for switching the camera direction.
/// </summary>
public ARCameraManager cameraManager
{
get => m_CameraManager;

[SerializeField]
ARCameraManager m_CameraManager;
/// <summary>
/// On button press callback to toggle the requested camera facing direction.
/// </summary>
public void OnSwapCameraButtonPress()
{
Debug.Assert(m_CameraManager != null, "camera manager cannot be null");

61
Assets/Scripts/TestConfigurationChooser.cs


using System;
using Unity.Collections;
using UnityEngine.UI;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.XR.ARFoundation;

{
/// <summary>
/// The configuration chooser mode. Values must match the UI dropdown.
/// </summary>
enum ConfigurationChooserMode
{
Default = 0,
PreferCamera = 1,
}
/// <summary>
/// The AR session on which to set the configuration chooser.
/// </summary>
public ARSession session

[SerializeField]
ARSession m_Session;
/// <summary>
/// The instantiated instance of the default configuration chooser.
/// </summary>
static readonly ConfigurationChooser m_DefaultConfigurationChooser = new DefaultConfigurationChooser();
/// <summary>
/// The instantiated instance of the prefer camera configuration chooser.
/// </summary>
static readonly ConfigurationChooser m_PreferCameraConfigurationChooser = new PreferCameraConfigurationChooser();
/// <summary>
/// The current configuration chooser mode.
/// </summary>
ConfigurationChooserMode m_ConfigurationChooserMode = ConfigurationChooserMode.Default;
// On start, set our custom configuration chooser.
UpdateConfigurationChooser();
}
/// <summary>
/// Callback when the depth mode dropdown UI has a value change.
/// </summary>
/// <param name="dropdown">The dropdown UI that changed.</param>
public void OnDepthModeDropdownValueChanged(Dropdown dropdown)
{
// Update the display mode from the dropdown value.
m_ConfigurationChooserMode = (ConfigurationChooserMode)dropdown.value;
// Update the configuration chooser.
UpdateConfigurationChooser();
}
/// <summary>
/// Update the configuration chooser based on the current mode.
/// </summary>
void UpdateConfigurationChooser()
{
m_Session.subsystem.configurationChooser = new ARFSamplesConfigurationChooser();
Debug.Assert(m_Session.subsystem != null, "ARSession must have a subsystem");
switch (m_ConfigurationChooserMode)
{
case ConfigurationChooserMode.PreferCamera:
m_Session.subsystem.configurationChooser = m_PreferCameraConfigurationChooser;
break;
case ConfigurationChooserMode.Default:
default:
m_Session.subsystem.configurationChooser = m_DefaultConfigurationChooser;
break;
}
class ARFSamplesConfigurationChooser : ConfigurationChooser
class PreferCameraConfigurationChooser : ConfigurationChooser
{
/// <summary>
/// Selects a configuration from the given <paramref name="descriptors"/> and <paramref name="requestedFeatures"/>.

正在加载...
取消
保存