WindowPartsDirectionalLight.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class WindowPartsDirectionalLight : MonoBehaviour
  6. {
  7. public void Awake()
  8. {
  9. if (this.execAwake)
  10. {
  11. return;
  12. }
  13. this.execAwake = true;
  14. this.light_ = GameMain.Instance.MainLight;
  15. this.RotateInput.onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetRotateValue));
  16. this.IntensityInput.onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetIntensityValue));
  17. this.ShadowInput.onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetShadowValue));
  18. this.ColorInput.onChangeValue.Add(new Action<WindowPartsInputColorrPalette, Color>(this.OnChangetColorValue));
  19. }
  20. public void Init(Action updateButtonFunction)
  21. {
  22. this.Awake();
  23. this.updateButtonFunction = updateButtonFunction;
  24. Vector3 eulerAngles = this.light_.transform.localRotation.eulerAngles;
  25. this.intensity_ = this.light_.GetIntensity();
  26. this.shadow_ = this.light_.GetShadowStrength();
  27. this.euler_angles_ = eulerAngles;
  28. this.color_ = this.light_.GetColor();
  29. PhotoSliderAndInput sliderAndInput = this.RotateInput.GetSliderAndInput("x");
  30. PhotoSliderAndInput sliderAndInput2 = this.RotateInput.GetSliderAndInput("y");
  31. PhotoSliderAndInput sliderAndInput3 = this.IntensityInput.GetSliderAndInput("str");
  32. PhotoSliderAndInput sliderAndInput4 = this.ShadowInput.GetSliderAndInput("str");
  33. sliderAndInput.ResetNum = this.euler_angles_.x;
  34. sliderAndInput2.ResetNum = this.euler_angles_.y;
  35. sliderAndInput3.ResetNum = this.intensity_;
  36. sliderAndInput4.ResetNum = this.shadow_;
  37. this.ColorInput.ResetNum = this.color_;
  38. this.UpdateGui();
  39. }
  40. public void SetLightWindow(LightWindow light_window)
  41. {
  42. this.light_window_ = light_window;
  43. }
  44. public void OnDestroy()
  45. {
  46. if (GameMain.Instance != null && GameMain.Instance.MainLight != null)
  47. {
  48. this.light_.Reset();
  49. }
  50. }
  51. public void OnChangetRotateValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
  52. {
  53. if (this.light_ == null)
  54. {
  55. return;
  56. }
  57. if (input_object.Name == "x")
  58. {
  59. this.euler_angles_.x = val;
  60. }
  61. else if (input_object.Name == "y")
  62. {
  63. this.euler_angles_.y = val;
  64. }
  65. this.light_.SetRotation(this.euler_angles_);
  66. }
  67. public void OnChangetIntensityValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
  68. {
  69. if (this.light_ == null)
  70. {
  71. return;
  72. }
  73. this.intensity_ = val;
  74. this.light_.SetIntensity(this.intensity_);
  75. }
  76. public void OnChangetShadowValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
  77. {
  78. if (this.light_ == null)
  79. {
  80. return;
  81. }
  82. this.shadow_ = val;
  83. this.light_.SetShadowStrength(this.shadow_);
  84. }
  85. public void OnChangetColorValue(WindowPartsInputColorrPalette input_object, Color color)
  86. {
  87. if (this.light_ == null)
  88. {
  89. return;
  90. }
  91. this.color_ = color;
  92. this.light_.SetColor(this.color_);
  93. if (this.updateButtonFunction != null)
  94. {
  95. this.updateButtonFunction();
  96. }
  97. }
  98. public void UpdateGui()
  99. {
  100. PhotoSliderAndInput sliderAndInput = this.RotateInput.GetSliderAndInput("x");
  101. PhotoSliderAndInput sliderAndInput2 = this.RotateInput.GetSliderAndInput("y");
  102. PhotoSliderAndInput sliderAndInput3 = this.IntensityInput.GetSliderAndInput("str");
  103. PhotoSliderAndInput sliderAndInput4 = this.ShadowInput.GetSliderAndInput("str");
  104. sliderAndInput.value = this.euler_angles_.x;
  105. sliderAndInput2.value = this.euler_angles_.y;
  106. sliderAndInput3.value = this.intensity_;
  107. sliderAndInput4.value = this.shadow_;
  108. this.ColorInput.value = this.color_;
  109. }
  110. public void OnSerializeEvent()
  111. {
  112. Dictionary<string, Dictionary<string, string>> woldStoreData = this.light_window_.GetWoldStoreData();
  113. woldStoreData["DirectionalLight"] = new Dictionary<string, string>();
  114. Dictionary<string, string> dictionary = woldStoreData["DirectionalLight"];
  115. dictionary.Add("intensity", this.intensity_.ToString("G9"));
  116. dictionary.Add("euler_angles", this.euler_angles_.ToString("G9"));
  117. dictionary.Add("shadow", this.shadow_.ToString("G9"));
  118. dictionary.Add("color", this.color_.ToString("G9"));
  119. }
  120. public void OnDeserializeEvent()
  121. {
  122. Dictionary<string, Dictionary<string, string>> woldStoreData = this.light_window_.GetWoldStoreData();
  123. if (!woldStoreData.ContainsKey("DirectionalLight"))
  124. {
  125. this.light_.Reset();
  126. this.intensity_ = this.light_.GetIntensity();
  127. this.shadow_ = this.light_.GetShadowStrength();
  128. this.euler_angles_ = this.light_.transform.localRotation.eulerAngles;
  129. this.color_ = this.light_.GetColor();
  130. }
  131. else
  132. {
  133. Dictionary<string, string> dictionary = woldStoreData["DirectionalLight"];
  134. this.intensity_ = float.Parse(dictionary["intensity"]);
  135. this.euler_angles_ = Parse.Vector3(dictionary["euler_angles"]);
  136. this.shadow_ = float.Parse(dictionary["shadow"]);
  137. this.color_ = Parse.Color(dictionary["color"]);
  138. }
  139. this.UpdateGui();
  140. }
  141. public bool visible
  142. {
  143. get
  144. {
  145. return base.gameObject.activeSelf;
  146. }
  147. set
  148. {
  149. base.gameObject.SetActive(true);
  150. }
  151. }
  152. public WindowPartsInputSliderSet RotateInput;
  153. public WindowPartsInputSliderSet IntensityInput;
  154. public WindowPartsInputSliderSet ShadowInput;
  155. public WindowPartsInputColorrPalette ColorInput;
  156. private Action updateButtonFunction;
  157. private bool execAwake;
  158. private LightMain light_;
  159. private Vector3 euler_angles_;
  160. private float intensity_;
  161. private float shadow_;
  162. private Color color_;
  163. private LightWindow light_window_;
  164. }