您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

65 行
1.9 KiB

using UnityEngine;
using UnityEngine.XR.ARFoundation;
/// <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 LightEstimation : MonoBehaviour
{
/// <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()
{
ARSubsystemManager.cameraFrameReceived += FrameChanged;
}
void OnDisable()
{
ARSubsystemManager.cameraFrameReceived -= 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;
}