using System; using System.Collections.Generic; using UnityEngine; using wf; public class WindowPartsDirectionalLight : MonoBehaviour { public void Awake() { if (this.execAwake) { return; } this.execAwake = true; this.light_ = GameMain.Instance.MainLight; this.RotateInput.onChangeValue.Add(new Action(this.OnChangetRotateValue)); this.IntensityInput.onChangeValue.Add(new Action(this.OnChangetIntensityValue)); this.ShadowInput.onChangeValue.Add(new Action(this.OnChangetShadowValue)); this.ColorInput.onChangeValue.Add(new Action(this.OnChangetColorValue)); } public void Init(Action updateButtonFunction) { this.Awake(); this.updateButtonFunction = updateButtonFunction; Vector3 eulerAngles = this.light_.transform.localRotation.eulerAngles; this.intensity_ = this.light_.GetIntensity(); this.shadow_ = this.light_.GetShadowStrength(); this.euler_angles_ = eulerAngles; this.color_ = this.light_.GetColor(); PhotoSliderAndInput sliderAndInput = this.RotateInput.GetSliderAndInput("x"); PhotoSliderAndInput sliderAndInput2 = this.RotateInput.GetSliderAndInput("y"); PhotoSliderAndInput sliderAndInput3 = this.IntensityInput.GetSliderAndInput("str"); PhotoSliderAndInput sliderAndInput4 = this.ShadowInput.GetSliderAndInput("str"); sliderAndInput.ResetNum = this.euler_angles_.x; sliderAndInput2.ResetNum = this.euler_angles_.y; sliderAndInput3.ResetNum = this.intensity_; sliderAndInput4.ResetNum = this.shadow_; this.ColorInput.ResetNum = this.color_; this.UpdateGui(); } public void SetLightWindow(LightWindow light_window) { this.light_window_ = light_window; } public void OnDestroy() { if (GameMain.Instance != null && GameMain.Instance.MainLight != null) { this.light_.Reset(); } } public void OnChangetRotateValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val) { if (this.light_ == null) { return; } if (input_object.Name == "x") { this.euler_angles_.x = val; } else if (input_object.Name == "y") { this.euler_angles_.y = val; } this.light_.SetRotation(this.euler_angles_); } public void OnChangetIntensityValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val) { if (this.light_ == null) { return; } this.intensity_ = val; this.light_.SetIntensity(this.intensity_); } public void OnChangetShadowValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val) { if (this.light_ == null) { return; } this.shadow_ = val; this.light_.SetShadowStrength(this.shadow_); } public void OnChangetColorValue(WindowPartsInputColorrPalette input_object, Color color) { if (this.light_ == null) { return; } this.color_ = color; this.light_.SetColor(this.color_); if (this.updateButtonFunction != null) { this.updateButtonFunction(); } } public void UpdateGui() { PhotoSliderAndInput sliderAndInput = this.RotateInput.GetSliderAndInput("x"); PhotoSliderAndInput sliderAndInput2 = this.RotateInput.GetSliderAndInput("y"); PhotoSliderAndInput sliderAndInput3 = this.IntensityInput.GetSliderAndInput("str"); PhotoSliderAndInput sliderAndInput4 = this.ShadowInput.GetSliderAndInput("str"); sliderAndInput.value = this.euler_angles_.x; sliderAndInput2.value = this.euler_angles_.y; sliderAndInput3.value = this.intensity_; sliderAndInput4.value = this.shadow_; this.ColorInput.value = this.color_; } public void OnSerializeEvent() { Dictionary> woldStoreData = this.light_window_.GetWoldStoreData(); woldStoreData["DirectionalLight"] = new Dictionary(); Dictionary dictionary = woldStoreData["DirectionalLight"]; dictionary.Add("intensity", this.intensity_.ToString("G9")); dictionary.Add("euler_angles", this.euler_angles_.ToString("G9")); dictionary.Add("shadow", this.shadow_.ToString("G9")); dictionary.Add("color", this.color_.ToString("G9")); } public void OnDeserializeEvent() { Dictionary> woldStoreData = this.light_window_.GetWoldStoreData(); if (!woldStoreData.ContainsKey("DirectionalLight")) { this.light_.Reset(); this.intensity_ = this.light_.GetIntensity(); this.shadow_ = this.light_.GetShadowStrength(); this.euler_angles_ = this.light_.transform.localRotation.eulerAngles; this.color_ = this.light_.GetColor(); } else { Dictionary dictionary = woldStoreData["DirectionalLight"]; this.intensity_ = float.Parse(dictionary["intensity"]); this.euler_angles_ = Parse.Vector3(dictionary["euler_angles"]); this.shadow_ = float.Parse(dictionary["shadow"]); this.color_ = Parse.Color(dictionary["color"]); } this.UpdateGui(); } public bool visible { get { return base.gameObject.activeSelf; } set { base.gameObject.SetActive(true); } } public WindowPartsInputSliderSet RotateInput; public WindowPartsInputSliderSet IntensityInput; public WindowPartsInputSliderSet ShadowInput; public WindowPartsInputColorrPalette ColorInput; private Action updateButtonFunction; private bool execAwake; private LightMain light_; private Vector3 euler_angles_; private float intensity_; private float shadow_; private Color color_; private LightWindow light_window_; }