WindowPartsEffectGlobalFog.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class WindowPartsEffectGlobalFog : WindowPartsEffectBase
  6. {
  7. public override void Awake()
  8. {
  9. base.Awake();
  10. this.fog_ = GameMain.Instance.MainCamera.GetComponent<GlobalFog>();
  11. if (this.fog_ == null)
  12. {
  13. this.fog_ = GameMain.Instance.MainCamera.gameObject.AddComponent<GlobalFog>();
  14. if (this.fog_.fogShader == null)
  15. {
  16. this.fog_.fogShader = Shader.Find("Hidden/GlobalFog");
  17. }
  18. this.fog_.enabled = false;
  19. }
  20. this.fog_.startDistance = 5f;
  21. this.fog_.globalDensity = 1f;
  22. this.fog_.heightScale = 1f;
  23. this.fog_.globalFogColor = Color.white;
  24. this.backup_value_data_.startDistance = this.fog_.startDistance;
  25. this.backup_value_data_.globalDensity = this.fog_.globalDensity;
  26. this.backup_value_data_.heightScale = this.fog_.heightScale;
  27. this.backup_value_data_.height = this.fog_.height;
  28. this.backup_value_data_.globalFogColor = this.fog_.globalFogColor;
  29. string[] array = new string[]
  30. {
  31. "startDistance",
  32. "globalDensity",
  33. "heightScale",
  34. "height",
  35. "r",
  36. "g",
  37. "b"
  38. };
  39. for (int i = 0; i < array.Length; i++)
  40. {
  41. PhotoSliderAndInput sliderAndInput = this.SettingInput.GetSliderAndInput(array[i]);
  42. if (sliderAndInput != null)
  43. {
  44. this.slider_dic_.Add(array[i], sliderAndInput);
  45. }
  46. }
  47. this.SettingInput.onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetValue));
  48. this.ColorPaletteInput.onChangeValue.Add(new Action<WindowPartsInputColorrPalette, Color>(this.OnChangetValue2));
  49. this.OnChangeEffectEnabled(false);
  50. }
  51. public override void OnDestroy()
  52. {
  53. if (GameMain.Instance == null || GameMain.Instance.MainCamera == null || this.effect_object == null)
  54. {
  55. return;
  56. }
  57. UnityEngine.Object.Destroy(this.fog_);
  58. this.fog_ = null;
  59. }
  60. public override void OnChangeEffectEnabled(bool enabled)
  61. {
  62. WindowPartsInputSliderSet settingInput = this.SettingInput;
  63. this.ColorPaletteInput.enabled = enabled;
  64. settingInput.enabled = enabled;
  65. }
  66. public override void Init()
  67. {
  68. this.value_data_ = this.backup_value_data_;
  69. this.slider_dic_["startDistance"].ResetNum = this.backup_value_data_.startDistance;
  70. this.slider_dic_["globalDensity"].ResetNum = this.backup_value_data_.globalDensity;
  71. this.slider_dic_["heightScale"].ResetNum = this.backup_value_data_.heightScale;
  72. this.slider_dic_["height"].ResetNum = this.backup_value_data_.height;
  73. this.ColorPaletteInput.ResetNum = this.backup_value_data_.globalFogColor;
  74. this.EnabledCheckBox.check = false;
  75. this.UpdateGui();
  76. }
  77. public void OnChangetValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
  78. {
  79. if (input_object.Name == "startDistance")
  80. {
  81. this.value_data_.startDistance = val;
  82. }
  83. else if (input_object.Name == "globalDensity")
  84. {
  85. this.value_data_.globalDensity = val;
  86. }
  87. else if (input_object.Name == "heightScale")
  88. {
  89. this.value_data_.heightScale = val;
  90. }
  91. else if (input_object.Name == "height")
  92. {
  93. this.value_data_.height = val;
  94. }
  95. this.ApplyValue();
  96. }
  97. public void OnChangetValue2(WindowPartsInputColorrPalette palette, Color color)
  98. {
  99. this.value_data_.globalFogColor = color;
  100. this.ApplyValue();
  101. }
  102. public override void OnSerializeEvent()
  103. {
  104. Dictionary<string, Dictionary<string, string>> woldStoreData = this.effect_window_.GetWoldStoreData();
  105. woldStoreData["GlobalFog"] = new Dictionary<string, string>();
  106. Dictionary<string, string> dictionary = woldStoreData["GlobalFog"];
  107. this.value_data_.OnSerializeEvent(dictionary);
  108. dictionary.Add("enabled", base.effect_enabled.ToString());
  109. }
  110. public override void OnDeserializeEvent()
  111. {
  112. Dictionary<string, Dictionary<string, string>> woldStoreData = this.effect_window_.GetWoldStoreData();
  113. if (!woldStoreData.ContainsKey("GlobalFog"))
  114. {
  115. this.ResetValue();
  116. this.value_data_ = this.backup_value_data_;
  117. this.EnabledCheckBox.check = base.effect_enabled;
  118. }
  119. else
  120. {
  121. Dictionary<string, string> dictionary = woldStoreData["GlobalFog"];
  122. this.value_data_.OnDeserializeEvent(dictionary);
  123. base.effect_enabled = bool.Parse(dictionary["enabled"]);
  124. this.ApplyValue();
  125. }
  126. this.UpdateGui();
  127. }
  128. private void ApplyValue()
  129. {
  130. this.fog_.startDistance = this.value_data_.startDistance;
  131. this.fog_.globalDensity = this.value_data_.globalDensity;
  132. this.fog_.heightScale = this.value_data_.heightScale;
  133. this.fog_.height = this.value_data_.height;
  134. this.fog_.globalFogColor = this.value_data_.globalFogColor;
  135. }
  136. public void ResetValue()
  137. {
  138. this.fog_.startDistance = this.backup_value_data_.startDistance;
  139. this.fog_.globalDensity = this.backup_value_data_.globalDensity;
  140. this.fog_.heightScale = this.backup_value_data_.heightScale;
  141. this.fog_.height = this.backup_value_data_.height;
  142. this.fog_.globalFogColor = this.backup_value_data_.globalFogColor;
  143. base.effect_enabled = false;
  144. }
  145. public void UpdateGui()
  146. {
  147. this.slider_dic_["startDistance"].value = this.value_data_.startDistance;
  148. this.slider_dic_["globalDensity"].value = this.value_data_.globalDensity;
  149. this.slider_dic_["heightScale"].value = this.value_data_.heightScale;
  150. this.slider_dic_["height"].value = this.value_data_.height;
  151. this.ColorPaletteInput.value = this.value_data_.globalFogColor;
  152. this.EnabledCheckBox.check = base.effect_enabled;
  153. this.OnChangeEffectEnabled(this.EnabledCheckBox.check);
  154. }
  155. protected override MonoBehaviour effect_object
  156. {
  157. get
  158. {
  159. return this.fog_;
  160. }
  161. }
  162. private const string kStoreName = "GlobalFog";
  163. public WindowPartsInputSliderSet SettingInput;
  164. public WindowPartsInputColorrPalette ColorPaletteInput;
  165. private Dictionary<string, PhotoSliderAndInput> slider_dic_ = new Dictionary<string, PhotoSliderAndInput>();
  166. private GlobalFog fog_;
  167. private WindowPartsEffectGlobalFog.Data backup_value_data_;
  168. private WindowPartsEffectGlobalFog.Data value_data_;
  169. private struct Data
  170. {
  171. public void OnSerializeEvent(Dictionary<string, string> effect_store_data)
  172. {
  173. effect_store_data.Add("startDistance", this.startDistance.ToString("G9"));
  174. effect_store_data.Add("globalDensity", this.globalDensity.ToString("G9"));
  175. effect_store_data.Add("heightScale", this.heightScale.ToString("G9"));
  176. effect_store_data.Add("height", this.height.ToString("G9"));
  177. effect_store_data.Add("globalFogColor", this.globalFogColor.ToString("G9"));
  178. }
  179. public void OnDeserializeEvent(Dictionary<string, string> effect_restore_data)
  180. {
  181. this.startDistance = float.Parse(effect_restore_data["startDistance"]);
  182. this.globalDensity = float.Parse(effect_restore_data["globalDensity"]);
  183. this.heightScale = float.Parse(effect_restore_data["heightScale"]);
  184. this.height = float.Parse(effect_restore_data["height"]);
  185. this.globalFogColor = Parse.Color(effect_restore_data["globalFogColor"]);
  186. }
  187. public float startDistance;
  188. public float globalDensity;
  189. public float heightScale;
  190. public float height;
  191. public Color globalFogColor;
  192. }
  193. }