浏览代码

and separated Basic/HDRLightEstimation scripts from LightEstimation.cs

/4.1
Shan Jiang 4 年前
当前提交
73f0e833
共有 9 个文件被更改,包括 126 次插入51 次删除
  1. 2
      Assets/Scenes/LightEstimation/HDRLightEstimation.unity
  2. 7
      Assets/Scripts/BasicLightEstimationUI.cs
  3. 20
      Assets/Scripts/HDRLightEstimationUI.cs
  4. 39
      Assets/Scripts/HDRLightEstimation.cs
  5. 2
      ProjectSettings/ProjectSettings.asset
  6. 96
      Assets/Scripts/BasicLightEstimation.cs
  7. 11
      Assets/Scripts/HDRLightEstimation.cs.meta
  8. 0
      /Assets/Scripts/BasicLightEstimation.cs.meta
  9. 0
      /Assets/Scripts/HDRLightEstimation.cs

2
Assets/Scenes/LightEstimation/HDRLightEstimation.unity


m_GameObject: {fileID: 1195718493}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 50c11494e9ace475f9dc92e2f907b42c, type: 3}
m_Script: {fileID: 11500000, guid: 847c0b77d9dc643c796f10eb8a022199, type: 3}
m_Name:
m_EditorClassIdentifier:
m_CameraManager: {fileID: 957600275}

7
Assets/Scripts/BasicLightEstimationUI.cs


/// <summary>
/// A simple UI controller to display light estimation information.
/// </summary>
[RequireComponent(typeof(LightEstimation))]
[RequireComponent(typeof(BasicLightEstimation))]
public class BasicLightEstimationUI : MonoBehaviour
{
[Tooltip("The UI Text element used to display the estimated ambient intensity in the physical environment.")]

void Awake()
{
m_LightEstimation = GetComponent<LightEstimation>();
m_LightEstimation = GetComponent<BasicLightEstimation>();
Debug.Log(m_LightEstimation.cameraManager.currentLightEstimation);
SetUIValue(m_LightEstimation.brightness, ambientIntensityText);
//Display either color temperature or color correction if supported

const string k_UnavailableText = "Unavailable";
LightEstimation m_LightEstimation;
BasicLightEstimation m_LightEstimation;
}
}

20
Assets/Scripts/HDRLightEstimationUI.cs


/// <summary>
/// A simple UI controller to display light estimation information.
/// </summary>
[RequireComponent(typeof(LightEstimation))]
[RequireComponent(typeof(HDRLightEstimation))]
public class HDRLightEstimationUI : MonoBehaviour
{
[Tooltip("The UI Text element used to display the estimated direction of the main light for the physical environment.")]

void Awake()
{
m_LightEstimation = GetComponent<LightEstimation>();
m_cameraManager = m_LightEstimation.cameraManager;
m_HDRLightEstimation = GetComponent<HDRLightEstimation>();
m_cameraManager = m_HDRLightEstimation.cameraManager;
SetUIValue(m_LightEstimation.mainLightDirection, mainLightDirectionText);
SetUIValue(m_LightEstimation.mainLightColor, mainLightColorText);
SetUIValue(m_LightEstimation.mainLightIntensityLumens, mainLightIntensityLumens);
SetSphericalHarmonicsUIValue(m_LightEstimation.sphericalHarmonics, ambientSphericalHarmonicsText);
SetModeSupportedUIValue(m_cameraManager.requestedLightEstimation, m_cameraManager.requestedFacingDirection);
SetUIValue(m_HDRLightEstimation.mainLightDirection, mainLightDirectionText);
SetUIValue(m_HDRLightEstimation.mainLightColor, mainLightColorText);
SetUIValue(m_HDRLightEstimation.mainLightIntensityLumens, mainLightIntensityLumens);
SetSphericalHarmonicsUIValue(m_HDRLightEstimation.sphericalHarmonics, ambientSphericalHarmonicsText);
SetModeSupportedUIValue(m_cameraManager.requestedFacingDirection);
}
void SetSphericalHarmonicsUIValue(SphericalHarmonicsL2? maybeAmbientSphericalHarmonics, Text text)

text.text = displayValue.HasValue ? displayValue.Value.ToString(): k_UnavailableText;
}
void SetModeSupportedUIValue(ARFoundation.LightEstimation lightEstimation, CameraFacingDirection direction)
void SetModeSupportedUIValue(CameraFacingDirection direction)
{
#if UNITY_IOS
if (direction == CameraFacingDirection.World)

const string k_UnavailableText = "Unavailable";
LightEstimation m_LightEstimation;
HDRLightEstimation m_HDRLightEstimation;
ARCameraManager m_cameraManager;
}

39
Assets/Scripts/HDRLightEstimation.cs


/// AR device.
/// </summary>
[RequireComponent(typeof(Light))]
public class LightEstimation : MonoBehaviour
public class HDRLightEstimation : MonoBehaviour
{
[SerializeField]
[Tooltip("The ARCameraManager which will produce frame events containing light estimation information.")]

m_CameraManager.frameReceived += FrameChanged;
}
}
/// <summary>
/// The estimated brightness of the physical environment, if available.
/// </summary>
public float? brightness { get; private set; }
/// <summary>
/// The estimated color temperature of the physical environment, if available.
/// </summary>
public float? colorTemperature { get; private set; }
/// <summary>
/// The estimated color correction value of the physical environment, if available.
/// </summary>
public Color? colorCorrection { get; private set; }
/// <summary>
/// The estimated direction of the main light of the physical environment, if available.
/// </summary>

void FrameChanged(ARCameraFrameEventArgs args)
{
if (args.lightEstimation.averageBrightness.HasValue)
{
brightness = args.lightEstimation.averageBrightness.Value;
m_Light.intensity = brightness.Value;
}
if (args.lightEstimation.averageColorTemperature.HasValue)
{
colorTemperature = args.lightEstimation.averageColorTemperature.Value;
m_Light.colorTemperature = colorTemperature.Value;
}
if (args.lightEstimation.colorCorrection.HasValue)
{
colorCorrection = args.lightEstimation.colorCorrection.Value;
m_Light.color = colorCorrection.Value;
}
if (args.lightEstimation.mainLightDirection.HasValue)
{
mainLightDirection = args.lightEstimation.mainLightDirection;

Light m_Light;
}
}
}

2
ProjectSettings/ProjectSettings.asset


Others: 1
bundleVersion: 0.1
preloadedAssets:
- {fileID: 0}
- {fileID: 4800000, guid: c9f956787b1d945e7b36e0516201fc76, type: 3}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1

96
Assets/Scripts/BasicLightEstimation.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.XR.ARFoundation;
namespace UnityEngine.XR.ARFoundation.Samples
{
/// <summary>
/// A component that can be used to access the most
/// recently received light estimation information
/// for the physical environment as observed by an
/// AR device.
/// </summary>
[RequireComponent(typeof(Light))]
public class BasicLightEstimation : MonoBehaviour
{
[SerializeField]
[Tooltip("The ARCameraManager which will produce frame events containing light estimation information.")]
ARCameraManager m_CameraManager;
/// <summary>
/// Get or set the <c>ARCameraManager</c>.
/// </summary>
public ARCameraManager cameraManager
{
get { return m_CameraManager; }
set
{
if (m_CameraManager == value)
return;
if (m_CameraManager != null)
m_CameraManager.frameReceived -= FrameChanged;
m_CameraManager = value;
if (m_CameraManager != null & enabled)
m_CameraManager.frameReceived += FrameChanged;
}
}
/// <summary>
/// The estimated brightness of the physical environment, if available.
/// </summary>
public float? brightness { get; private set; }
/// <summary>
/// The estimated color temperature of the physical environment, if available.
/// </summary>
public float? colorTemperature { get; private set; }
/// <summary>
/// The estimated color correction value of the physical environment, if available.
/// </summary>
public Color? colorCorrection { get; private set; }
void Awake ()
{
m_Light = GetComponent<Light>();
}
void OnEnable()
{
if (m_CameraManager != null)
m_CameraManager.frameReceived += FrameChanged;
}
void OnDisable()
{
if (m_CameraManager != null)
m_CameraManager.frameReceived -= FrameChanged;
}
void FrameChanged(ARCameraFrameEventArgs args)
{
if (args.lightEstimation.averageBrightness.HasValue)
{
brightness = args.lightEstimation.averageBrightness.Value;
m_Light.intensity = brightness.Value;
}
if (args.lightEstimation.averageColorTemperature.HasValue)
{
colorTemperature = args.lightEstimation.averageColorTemperature.Value;
m_Light.colorTemperature = colorTemperature.Value;
}
if (args.lightEstimation.colorCorrection.HasValue)
{
colorCorrection = args.lightEstimation.colorCorrection.Value;
m_Light.color = colorCorrection.Value;
}
}
Light m_Light;
}
}

11
Assets/Scripts/HDRLightEstimation.cs.meta


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

/Assets/Scripts/LightEstimation.cs.meta → /Assets/Scripts/BasicLightEstimation.cs.meta

/Assets/Scripts/LightEstimation.cs → /Assets/Scripts/HDRLightEstimation.cs

正在加载...
取消
保存