Alexandra Serralta
4 年前
当前提交
9510827f
共有 2 个文件被更改,包括 158 次插入 和 0 次删除
|
|||
using UnityEngine; |
|||
using UnityEngine.UI; |
|||
using System.Text; |
|||
|
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.XR.ARFoundation.Samples |
|||
{ |
|||
/// <summary>
|
|||
/// A simple UI controller to display light estimation information.
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(LightEstimation))] |
|||
public class HDRLightEstimationUI : MonoBehaviour |
|||
{ |
|||
[Tooltip("The UI Text element used to display the estimated brightness in the physical environment.")] |
|||
[SerializeField] |
|||
Text m_BrightnessText; |
|||
|
|||
/// <summary>
|
|||
/// The UI Text element used to display the estimated brightness value.
|
|||
/// </summary>
|
|||
public Text brightnessText |
|||
{ |
|||
get { return m_BrightnessText; } |
|||
set { m_BrightnessText = brightnessText; } |
|||
} |
|||
|
|||
[Tooltip("The UI Text element used to display the estimated color temperature in the physical environment.")] |
|||
[SerializeField] |
|||
Text m_ColorTemperatureText; |
|||
|
|||
/// <summary>
|
|||
/// The UI Text element used to display the estimated color temperature in the scene.
|
|||
/// </summary>
|
|||
public Text colorTemperatureText |
|||
{ |
|||
get { return m_ColorTemperatureText; } |
|||
set { m_ColorTemperatureText = value; } |
|||
} |
|||
|
|||
[Tooltip("The UI Text element used to display the estimated color correction value for the physical environment.")] |
|||
[SerializeField] |
|||
Text m_ColorCorrectionText; |
|||
|
|||
[Tooltip("The UI Text element used to display the estimated direction of the main light for the physical environment.")] |
|||
[SerializeField] |
|||
Text m_MainLightDirectionText; |
|||
public Text mainLightDirectionText |
|||
{ |
|||
get => m_MainLightDirectionText; |
|||
set => m_MainLightDirectionText = value; |
|||
} |
|||
|
|||
[Tooltip("The UI Text element used to display the estimated intensity in lumens of the main light for the physical environment.")] |
|||
[SerializeField] |
|||
Text m_MainLightIntensityLumens; |
|||
public Text mainLightIntensityLumens |
|||
{ |
|||
get => m_MainLightIntensityLumens; |
|||
set => m_MainLightIntensityLumens = value; |
|||
} |
|||
|
|||
[Tooltip("The UI Text element used to display the estimated color of the main light for the physical environment.")] |
|||
[SerializeField] |
|||
Text m_MainLightColor; |
|||
public Text mainLightColorText |
|||
{ |
|||
get => m_MainLightColor; |
|||
set => m_MainLightColor = value; |
|||
} |
|||
|
|||
[Tooltip("The UI Text element used to display the estimated spherical harmonics coefficients for the physical environment.")] |
|||
[SerializeField] |
|||
Text m_SphericalHarmonicsText; |
|||
public Text ambientSphericalHarmonicsText |
|||
{ |
|||
get => m_SphericalHarmonicsText; |
|||
set => m_SphericalHarmonicsText = value; |
|||
} |
|||
StringBuilder m_SphericalHarmonicsStringBuilder = new StringBuilder(""); |
|||
|
|||
/// <summary>
|
|||
/// The UI Text element used to display the estimated color correction value for the scene.
|
|||
/// </summary>
|
|||
public Text colorCorrectionText |
|||
{ |
|||
get { return m_ColorCorrectionText; } |
|||
set { m_ColorCorrectionText = value; } |
|||
} |
|||
|
|||
void Awake() |
|||
{ |
|||
m_LightEstimation = GetComponent<LightEstimation>(); |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
SetUIValue(m_LightEstimation.brightness, brightnessText); |
|||
SetUIValue(m_LightEstimation.colorTemperature, colorTemperatureText); |
|||
SetUIValue(m_LightEstimation.colorCorrection, colorCorrectionText); |
|||
SetUIValue(m_LightEstimation.mainLightDirection, mainLightDirectionText); |
|||
SetUIValue(m_LightEstimation.mainLightColor, mainLightColorText); |
|||
SetUIValue(m_LightEstimation.mainLightIntensityLumens, mainLightIntensityLumens); |
|||
SetSphericalHarmonicsUIValue(m_LightEstimation.sphericalHarmonics, ambientSphericalHarmonicsText); |
|||
} |
|||
|
|||
void SetSphericalHarmonicsUIValue(SphericalHarmonicsL2? maybeAmbientSphericalHarmonics, Text text) |
|||
{ |
|||
if (text != null) |
|||
{ |
|||
if (maybeAmbientSphericalHarmonics.HasValue) |
|||
{ |
|||
m_SphericalHarmonicsStringBuilder.Clear(); |
|||
for (int i = 0; i < 3; ++i) |
|||
{ |
|||
if (i == 0) |
|||
m_SphericalHarmonicsStringBuilder.Append("R:["); |
|||
else if (i == 1) |
|||
m_SphericalHarmonicsStringBuilder.Append("G:["); |
|||
else |
|||
m_SphericalHarmonicsStringBuilder.Append("B:["); |
|||
|
|||
for (int j = 0; j < 9; ++j) |
|||
{ |
|||
m_SphericalHarmonicsStringBuilder.Append(j != 8 ? $"{maybeAmbientSphericalHarmonics.Value[i, j]}, " : $"{maybeAmbientSphericalHarmonics.Value[i, j]}]\n"); |
|||
} |
|||
} |
|||
text.text = m_SphericalHarmonicsStringBuilder.ToString(); |
|||
} |
|||
else |
|||
{ |
|||
text.text = k_UnavailableText; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void SetUIValue<T>(T? displayValue, Text text) where T : struct |
|||
{ |
|||
if (text != null) |
|||
text.text = displayValue.HasValue ? displayValue.Value.ToString(): k_UnavailableText; |
|||
} |
|||
|
|||
const string k_UnavailableText = "Unavailable"; |
|||
|
|||
LightEstimation m_LightEstimation; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a683fd6dcd1b846678402aaa9d564d0a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue