浏览代码

Adding configuration chooser sample.

/4.1
Todd Stinson 4 年前
当前提交
ed37099b
共有 11 个文件被更改,包括 1329 次插入0 次删除
  1. 3
      ProjectSettings/EditorBuildSettings.asset
  2. 8
      Assets/Scenes/Configurations.meta
  3. 149
      Assets/Scripts/DisplayARSessionInformation.cs
  4. 11
      Assets/Scripts/DisplayARSessionInformation.cs.meta
  5. 41
      Assets/Scripts/TestCameraSwapper.cs
  6. 11
      Assets/Scripts/TestCameraSwapper.cs.meta
  7. 87
      Assets/Scripts/TestConfigurationChooser.cs
  8. 11
      Assets/Scripts/TestConfigurationChooser.cs.meta
  9. 1001
      Assets/Scenes/Configurations/ConfigurationChooser.unity
  10. 7
      Assets/Scenes/Configurations/ConfigurationChooser.unity.meta

3
ProjectSettings/EditorBuildSettings.asset


- enabled: 1
path: Assets/Scenes/Interaction/Interaction.unity
guid: ff9b6e62e970e432a9e8d51604b3bad8
- enabled: 0
path: Assets/Scenes/Configurations/ConfigurationChooser.unity
guid: 3aae069bebee946a090ed6a756a1e77b
m_configObjects:
UnityEditor.XR.ARCore.ARCoreSettings: {fileID: 11400000, guid: f8ce26fe3bc69499b9be4b2378e97a94,
type: 2}

8
Assets/Scenes/Configurations.meta


fileFormatVersion: 2
guid: c8b7d187eded9494aacba3b5d7216b2a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

149
Assets/Scripts/DisplayARSessionInformation.cs


using System;
using System.Text;
using Unity.Collections;
using UnityEngine.UI;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.XR.ARFoundation;
namespace UnityEngine.XR.ARFoundation.Samples
{
public class DisplayARSessionInformation : MonoBehaviour
{
/// <summary>
/// A string builder used for logging.
/// </summary>
readonly StringBuilder m_StringBuilder = new StringBuilder();
/// <summary>
/// The text UI to display the logging information.
/// </summary>
public Text infoText
{
get => m_InfoText;
set => m_InfoText = value;
}
[SerializeField]
Text m_InfoText;
/// <summary>
/// The camera manager for logging.
/// </summary>
public ARCameraManager cameraManager
{
get => m_CameraManager;
set => m_CameraManager = value;
}
[SerializeField]
ARCameraManager m_CameraManager;
/// <summary>
/// The plane manager for logging.
/// </summary>
public ARPlaneManager planeManager
{
get => m_PlaneManager;
set => m_PlaneManager = value;
}
[SerializeField]
ARPlaneManager m_PlaneManager;
/// <summary>
/// The occlusion manager for logging.
/// </summary>
public AROcclusionManager occlusionManager
{
get => m_OcclusionManager;
set => m_OcclusionManager = value;
}
[SerializeField]
AROcclusionManager m_OcclusionManager;
void Update()
{
// Clear the string builder for a new log information.
m_StringBuilder.Clear();
// Log the various manager states.
LogCameraManger();
LogPlaneManger();
LogOcclusionManger();
// 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();
}
}
void LogCameraManger()
{
m_StringBuilder.Append("ARCameraManager\n");
if (m_CameraManager == null)
{
m_StringBuilder.Append(" <null>\n");
}
else if (!m_CameraManager.enabled)
{
m_StringBuilder.Append(" <disabled>\n");
}
else
{
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");
}
}
void LogPlaneManger()
{
m_StringBuilder.Append("ARPlaneManager\n");
if (m_PlaneManager == null)
{
m_StringBuilder.Append(" <null>\n");
}
else if (!m_PlaneManager.enabled)
{
m_StringBuilder.Append(" <disabled>\n");
}
else
{
m_StringBuilder.Append(" Detection mode:\n");
m_StringBuilder.Append($" Requested: {m_PlaneManager.requestedDetectionMode}\n");
m_StringBuilder.Append($" Current: {m_PlaneManager.currentDetectionMode}\n");
}
}
void LogOcclusionManger()
{
m_StringBuilder.Append("AROcclusionManager\n");
if (m_OcclusionManager == null)
{
m_StringBuilder.Append(" <null>\n");
}
else if (!m_OcclusionManager.enabled)
{
m_StringBuilder.Append(" <disabled>\n");
}
else
{
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");
}
}
}
}

11
Assets/Scripts/DisplayARSessionInformation.cs.meta


fileFormatVersion: 2
guid: a8793e59c6aea4d1a91bfa0038a7e8e5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

41
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
{
public class TestCameraSwapper : MonoBehaviour
{
/// <summary>
/// The camera manager for switching the camera direction.
public ARCameraManager cameraManager
{
get => m_CameraManager;
set => m_CameraManager = value;
}
[SerializeField]
ARCameraManager m_CameraManager;
public void OnSwapCameraButtonPress()
{
Debug.Assert(m_CameraManager != null, "camera manager cannot be null");
CameraFacingDirection newFacingDirection;
switch (m_CameraManager.requestedFacingDirection)
{
case CameraFacingDirection.World:
newFacingDirection = CameraFacingDirection.User;
break;
case CameraFacingDirection.User:
default:
newFacingDirection = CameraFacingDirection.World;
break;
}
Debug.Log($"Switching ARCameraManager.requestedFacingDirection from {m_CameraManager.requestedFacingDirection} to {newFacingDirection}");
m_CameraManager.requestedFacingDirection = newFacingDirection;
}
}
}

11
Assets/Scripts/TestCameraSwapper.cs.meta


fileFormatVersion: 2
guid: 29bd2bf6583a54738a6b2063140ee4ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

87
Assets/Scripts/TestConfigurationChooser.cs


using System;
using System.Text;
using Unity.Collections;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.XR.ARFoundation;
namespace UnityEngine.XR.ARFoundation.Samples
{
public class TestConfigurationChooser : MonoBehaviour
{
/// <summary>
/// The AR session to set the configuration chooser.
/// </summary>
public ARSession session
{
get => m_Session;
set => m_Session = value;
}
[SerializeField]
ARSession m_Session;
void Start()
{
// On start, set our custom configuration chooser.
Debug.Assert(m_Session != null, "ARSession must be nonnull");
m_Session.subsystem.configurationChooser = new ARFSamplesConfigurationChooser();
}
/// <summary>
/// A custom implementation of a <see cref="ConfigurationChooser"/>.
/// </summary>
class ARFSamplesConfigurationChooser : ConfigurationChooser
{
/// <summary>
/// Selects a configuration from the given <paramref name="descriptors"/> and <paramref name="requestedFeatures"/>.
/// </summary>
public override Configuration ChooseConfiguration(NativeSlice<ConfigurationDescriptor> descriptors, Feature requestedFeatures)
{
if (descriptors.Length == 0)
{
throw new ArgumentException("No configuration descriptors to choose from.", nameof(descriptors));
}
if (requestedFeatures.Intersection(Feature.AnyTrackingMode).Count() > 1)
{
throw new ArgumentException($"Zero or one tracking mode must be requested. Requested tracking modes => {requestedFeatures.Intersection(Feature.AnyTrackingMode).ToStringList()}", nameof(requestedFeatures));
}
if (requestedFeatures.Intersection(Feature.AnyCamera).Count() > 1)
{
throw new ArgumentException($"Zero or one camera mode must be requested. Requested camera modes => {requestedFeatures.Intersection(Feature.AnyCamera).ToStringList()}", nameof(requestedFeatures));
}
// Get the requested camera features out of the set of requested features.
Feature requestedCameraFeatures = requestedFeatures.Intersection(Feature.AnyCamera);
int highestFeatureWeight = -1;
int highestRank = int.MinValue;
ConfigurationDescriptor bestDescriptor = default;
foreach (var descriptor in descriptors)
{
// Initialize the feature weight with each feature being an equal weight.
int featureWeight = requestedFeatures.Intersection(descriptor.capabilities).Count();
// Increase the weight if there are matching camera features.
if (requestedCameraFeatures.Intersection(descriptor.capabilities) > 0)
{
featureWeight += 100;
}
// Store the descriptor with the highest feature weight.
if ((featureWeight > highestFeatureWeight) ||
(featureWeight == highestFeatureWeight && descriptor.rank > highestRank))
{
highestFeatureWeight = featureWeight;
highestRank = descriptor.rank;
bestDescriptor = descriptor;
}
}
// Return the configuration with the best matching descriptor.
return new Configuration(bestDescriptor, requestedFeatures.Intersection(bestDescriptor.capabilities));
}
}
}
}

11
Assets/Scripts/TestConfigurationChooser.cs.meta


fileFormatVersion: 2
guid: f1cdc0d7a6c9d42ed9fe5aff9dbe95c3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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

7
Assets/Scenes/Configurations/ConfigurationChooser.unity.meta


fileFormatVersion: 2
guid: 3aae069bebee946a090ed6a756a1e77b
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存