浏览代码

Merge pull request #29 from Unity-Technologies/LightEstimation

Added light estimation script and scene with UI to display values
/1.5-preview
GitHub 6 年前
当前提交
a8dafb08
共有 6 个文件被更改,包括 1129 次插入0 次删除
  1. 1001
      Assets/Scenes/LightEstimation.unity
  2. 7
      Assets/Scenes/LightEstimation.unity.meta
  3. 50
      Assets/Scripts/LightEstimation.cs
  4. 11
      Assets/Scripts/LightEstimation.cs.meta
  5. 49
      Assets/Scripts/LightEstimationUI.cs
  6. 11
      Assets/Scripts/LightEstimationUI.cs.meta

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

7
Assets/Scenes/LightEstimation.unity.meta


fileFormatVersion: 2
guid: 2f0cbc82480584c258f99f0d9e4ba302
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

50
Assets/Scripts/LightEstimation.cs


using UnityEngine;
using UnityEngine.XR.ARFoundation;
[RequireComponent(typeof(Light))]
public class LightEstimation : MonoBehaviour
{
Light m_Light;
public float? brightness { get; private set; }
public float? colorTemperature { get; private set; }
public Color? colorCorrection { get; private set; }
void Awake ()
{
m_Light = GetComponent<Light>();
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;
}
}
}

11
Assets/Scripts/LightEstimation.cs.meta


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

49
Assets/Scripts/LightEstimationUI.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(LightEstimation))]
public class LightEstimationUI : MonoBehaviour
{
[SerializeField]
Text m_BrightnessVal;
[SerializeField]
Text m_ColorTempVal;
[SerializeField]
Text m_ColorCorrectVal;
LightEstimation m_LightEstimation;
const string k_UnavailableText = "Unavailable";
void Awake()
{
m_LightEstimation = GetComponent<LightEstimation>();
}
void Update()
{
SetUIValue(m_LightEstimation.brightness.HasValue, m_BrightnessVal, m_LightEstimation.brightness.Value.ToString());
SetUIValue(m_LightEstimation.colorTemperature.HasValue, m_ColorTempVal, m_LightEstimation.colorTemperature.Value.ToString());
SetUIValue(m_LightEstimation.colorCorrection.HasValue, m_ColorCorrectVal, m_LightEstimation.colorTemperature.Value.ToString());
}
void SetUIValue(bool ContainsValue, Text UIText, string DisplayValue)
{
if (UIText)
{
if (ContainsValue)
{
UIText.text = DisplayValue;
}
else
{
UIText.text = k_UnavailableText;
}
}
}
}

11
Assets/Scripts/LightEstimationUI.cs.meta


fileFormatVersion: 2
guid: 079fa7fb0f02c4bd28860dd22bf8f5a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存