using System;
using UnityEngine.UI;
namespace UnityEngine.XR.ARFoundation.Samples
{
///
/// A simple UI controller to display basic light estimation information.
///
[RequireComponent(typeof(BasicLightEstimation))]
public class BasicLightEstimationUI : MonoBehaviour
{
[Tooltip("The UI Text element used to display the estimated ambient intensity in the physical environment.")]
[SerializeField]
Text m_AmbientIntensityText;
///
/// The UI Text element used to display the estimated ambient intensity value.
///
public Text ambientIntensityText
{
get { return m_AmbientIntensityText; }
set { m_AmbientIntensityText = ambientIntensityText; }
}
[Tooltip("The UI Text element used to display the estimated ambient color in the physical environment.")]
[SerializeField]
Text m_AmbientColorText;
///
/// The UI Text element used to display the estimated ambient color in the scene.
///
public Text ambientColorText
{
get { return m_AmbientColorText; }
set { m_AmbientColorText = value; }
}
void Awake()
{
m_BasicLightEstimation = GetComponent();
}
void Update()
{
SetUIValue(m_BasicLightEstimation.brightness, ambientIntensityText);
//Display color temperature or color correction if supported
if (m_BasicLightEstimation.colorTemperature != null)
SetUIValue(m_BasicLightEstimation.colorTemperature, ambientColorText);
else if (m_BasicLightEstimation.colorCorrection != null)
SetUIValue(m_BasicLightEstimation.colorCorrection, ambientColorText);
else
SetUIValue(null, ambientColorText);
}
void SetUIValue(T? displayValue, Text text) where T : struct
{
if (text != null)
text.text = displayValue.HasValue ? displayValue.Value.ToString(): "Unavailable";
}
BasicLightEstimation m_BasicLightEstimation;
}
}