105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Rendering.HighDefinition;
|
|
|
|
public class NaturalLightMovement : MonoBehaviour
|
|
{
|
|
public GameObject directionalLightGO;
|
|
private HDAdditionalLightData directionalLight;
|
|
|
|
//Default values:
|
|
private float intensityDefaultValue;
|
|
private float elevationDefaultValue;
|
|
private float rotationDefaultValue;
|
|
private float ambientLightDefaultValue;
|
|
private float ambientLightVolumetricDimmerDefaultValue;
|
|
//---------------------------------------------------
|
|
|
|
[Header("UI")]
|
|
public Slider _intensity;
|
|
public Slider _elevation;
|
|
public Slider _rotation;
|
|
public Slider _ambientLight;
|
|
|
|
private float directionalLightRotZDefaultValue;
|
|
|
|
private bool _setDefaultValues = true;
|
|
|
|
private static NaturalLightMovement _instance;
|
|
public static NaturalLightMovement GetInstance() { return _instance; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (!_instance)
|
|
{
|
|
_instance = this;
|
|
}
|
|
|
|
if (directionalLightGO == null)
|
|
{
|
|
directionalLightGO = GameObject.FindGameObjectWithTag("MainDirectionalLight");
|
|
}
|
|
directionalLight = directionalLightGO.transform.GetComponent<HDAdditionalLightData>();
|
|
SetDefaultValues();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
intensityDefaultValue = _intensity.value;
|
|
elevationDefaultValue = _elevation.value;
|
|
rotationDefaultValue = _rotation.value;
|
|
ambientLightDefaultValue = _ambientLight.value;
|
|
ambientLightVolumetricDimmerDefaultValue = directionalLight.volumetricDimmer;
|
|
|
|
directionalLightRotZDefaultValue = directionalLightGO.transform.localEulerAngles.z;
|
|
print("natural light Default values Updated");
|
|
}
|
|
|
|
public void RestoreDirectionalLightDefaultValues()
|
|
{
|
|
directionalLight.intensity = intensityDefaultValue;
|
|
directionalLightGO.transform.localEulerAngles = new Vector3(elevationDefaultValue, rotationDefaultValue, directionalLightRotZDefaultValue);
|
|
//directionalLight.SetLightDimmer(ambientLightDefaultValue, ambientLightVolumetricDimmerDefaultValue);
|
|
directionalLight.lightDimmer = ambientLightDefaultValue;
|
|
directionalLight.enabled = false;
|
|
directionalLight.enabled = true;
|
|
_setDefaultValues = true;
|
|
SetDefaultValues();
|
|
}
|
|
|
|
public void SetDefaultValues()
|
|
{
|
|
if (_setDefaultValues)
|
|
{
|
|
_intensity.value = directionalLight.intensity;
|
|
_elevation.value = directionalLightGO.transform.localEulerAngles.x;
|
|
_rotation.value = directionalLightGO.transform.localEulerAngles.y;
|
|
_ambientLight.value = directionalLight.lightDimmer;
|
|
directionalLightRotZDefaultValue = directionalLightGO.transform.localEulerAngles.z;
|
|
_setDefaultValues = false;
|
|
}
|
|
}
|
|
|
|
//public void SaveDefaultDirectionalLightRotation()
|
|
//{
|
|
// directionalLightDefaultRotation = directionalLight.transform.rotation;
|
|
//}
|
|
|
|
//public void LoadDefaultDirectionalLightRotation()
|
|
//{
|
|
// directionalLight.transform.rotation = directionalLightDefaultRotation;
|
|
//}
|
|
|
|
public void UpdateNaturalLightValues()
|
|
{
|
|
directionalLight.intensity = _intensity.value;
|
|
directionalLightGO.transform.localEulerAngles = new Vector3(_elevation.value, _rotation.value, directionalLightRotZDefaultValue); //Elevation & rotation sliders.
|
|
//directionalLight.SetLightDimmer(_ambientLight.value, ambientLightVolumetricDimmerDefaultValue);
|
|
directionalLight.lightDimmer = _ambientLight.value;
|
|
directionalLight.UpdateAllLightValues();
|
|
}
|
|
|
|
}
|