WindowPartsEffectDepthBlur.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class WindowPartsEffectDepthBlur : WindowPartsEffectBase
  6. {
  7. public override void Awake()
  8. {
  9. base.Awake();
  10. this.depth_field_ = GameMain.Instance.MainCamera.gameObject.AddComponent<DepthOfFieldScatter>();
  11. if (this.depth_field_.dofHdrShader == null)
  12. {
  13. this.depth_field_.dofHdrShader = Shader.Find("Hidden/Dof/DepthOfFieldHdr");
  14. }
  15. if (this.depth_field_.dx11BokehShader == null)
  16. {
  17. this.depth_field_.dx11BokehShader = Shader.Find("Hidden/Dof/DX11Dof");
  18. }
  19. if (this.depth_field_.dx11BokehTexture == null)
  20. {
  21. this.depth_field_.dx11BokehTexture = (Resources.Load("Textures/hexShape") as Texture2D);
  22. }
  23. this.depth_field_.enabled = false;
  24. this.backup_value_vector_ = new Vector4(this.depth_field_.focalLength, this.depth_field_.focalSize, this.depth_field_.aperture, this.depth_field_.maxBlurSize);
  25. this.SettingInput.onChangeValue.Add(new Action<WindowPartsInputSliderSet.SliderAndInputSet, float>(this.OnChangetValue));
  26. this.DebugDrawCheckBox.onClick.Add(new Action<WFCheckBox>(this.OnClickCheckBox));
  27. }
  28. public override void OnDestroy()
  29. {
  30. if (GameMain.Instance == null || GameMain.Instance.MainCamera == null || this.depth_field_ == null)
  31. {
  32. return;
  33. }
  34. UnityEngine.Object.DestroyImmediate(this.depth_field_);
  35. this.depth_field_ = null;
  36. }
  37. public override void OnChangeEffectEnabled(bool enabled)
  38. {
  39. WFCheckBox debugDrawCheckBox = this.DebugDrawCheckBox;
  40. this.SettingInput.enabled = enabled;
  41. debugDrawCheckBox.enabled = enabled;
  42. }
  43. public override void Init()
  44. {
  45. this.value_vector_ = this.backup_value_vector_;
  46. this.SettingInput.GetSliderAndInput("focalLength").ResetNum = this.backup_value_vector_.x;
  47. this.SettingInput.GetSliderAndInput("focalSize").ResetNum = this.backup_value_vector_.y;
  48. this.SettingInput.GetSliderAndInput("aperture").ResetNum = this.backup_value_vector_.z;
  49. this.SettingInput.GetSliderAndInput("maxBlurSize").ResetNum = this.backup_value_vector_.w;
  50. WFCheckBox enabledCheckBox = this.EnabledCheckBox;
  51. bool check = false;
  52. this.DebugDrawCheckBox.check = check;
  53. enabledCheckBox.check = check;
  54. this.UpdateGui();
  55. }
  56. public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
  57. {
  58. if (!maid.boMAN || is_deserialize_load || !base.effect_enabled || !this.depth_field_.visualizeFocus)
  59. {
  60. return;
  61. }
  62. this.DebugDrawCheckBox.check = false;
  63. this.OnClickCheckBox(this.DebugDrawCheckBox);
  64. }
  65. public override void OnClickEnabledCheckBox(WFCheckBox check_box)
  66. {
  67. base.OnClickEnabledCheckBox(check_box);
  68. this.CheckManPartVisible();
  69. }
  70. public void OnChangetValue(WindowPartsInputSliderSet.SliderAndInputSet input_object, float val)
  71. {
  72. if (input_object.Name == "focalLength")
  73. {
  74. this.value_vector_.x = val;
  75. }
  76. else if (input_object.Name == "focalSize")
  77. {
  78. this.value_vector_.y = val;
  79. }
  80. else if (input_object.Name == "aperture")
  81. {
  82. this.value_vector_.z = val;
  83. }
  84. else if (input_object.Name == "maxBlurSize")
  85. {
  86. this.value_vector_.w = val;
  87. }
  88. this.depth_field_.focalLength = this.value_vector_.x;
  89. this.depth_field_.focalSize = this.value_vector_.y;
  90. this.depth_field_.aperture = this.value_vector_.z;
  91. this.depth_field_.maxBlurSize = this.value_vector_.w;
  92. }
  93. public void OnClickCheckBox(WFCheckBox check_box)
  94. {
  95. this.depth_field_.visualizeFocus = check_box.check;
  96. this.CheckManPartVisible();
  97. }
  98. private void CheckManPartVisible()
  99. {
  100. CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
  101. FaceWindow faceWindow = this.effect_window_.mgr.GetWindow(PhotoWindowManager.WindowType.Face) as FaceWindow;
  102. for (int i = 0; i < characterMgr.GetStockManCount(); i++)
  103. {
  104. Maid stockMan = characterMgr.GetStockMan(i);
  105. if (stockMan.Visible)
  106. {
  107. if (base.effect_enabled && this.depth_field_.visualizeFocus)
  108. {
  109. stockMan.body0.SetChinkoVisible(false);
  110. faceWindow.PartVisibleCheckBox.enabled = false;
  111. }
  112. else
  113. {
  114. Dictionary<string, string> maidStoreData = faceWindow.GetMaidStoreData(stockMan);
  115. stockMan.body0.SetChinkoVisible(bool.Parse(maidStoreData["parts_visible"]));
  116. faceWindow.PartVisibleCheckBox.enabled = true;
  117. }
  118. }
  119. }
  120. }
  121. public override void OnSerializeEvent()
  122. {
  123. Dictionary<string, Dictionary<string, string>> woldStoreData = this.effect_window_.GetWoldStoreData();
  124. woldStoreData["DepthBlur"] = new Dictionary<string, string>();
  125. Dictionary<string, string> dictionary = woldStoreData["DepthBlur"];
  126. dictionary.Add("value_vector", this.value_vector_.ToString("G9"));
  127. dictionary.Add("enabled", base.effect_enabled.ToString());
  128. }
  129. public override void OnDeserializeEvent()
  130. {
  131. Dictionary<string, Dictionary<string, string>> woldStoreData = this.effect_window_.GetWoldStoreData();
  132. if (!woldStoreData.ContainsKey("DepthBlur"))
  133. {
  134. this.ResetValue();
  135. this.value_vector_ = this.backup_value_vector_;
  136. this.EnabledCheckBox.check = base.effect_enabled;
  137. this.DebugDrawCheckBox.check = false;
  138. }
  139. else
  140. {
  141. Dictionary<string, string> dictionary = woldStoreData["DepthBlur"];
  142. this.value_vector_ = Parse.Vector4(dictionary["value_vector"]);
  143. base.effect_enabled = bool.Parse(dictionary["enabled"]);
  144. this.depth_field_.focalLength = this.value_vector_.x;
  145. this.depth_field_.focalSize = this.value_vector_.y;
  146. this.depth_field_.aperture = this.value_vector_.z;
  147. this.depth_field_.maxBlurSize = this.value_vector_.w;
  148. }
  149. this.depth_field_.visualizeFocus = false;
  150. this.UpdateGui();
  151. }
  152. public void ResetValue()
  153. {
  154. this.depth_field_.focalLength = this.backup_value_vector_.x;
  155. this.depth_field_.focalSize = this.backup_value_vector_.y;
  156. this.depth_field_.aperture = this.backup_value_vector_.z;
  157. this.depth_field_.maxBlurSize = this.backup_value_vector_.w;
  158. this.depth_field_.visualizeFocus = false;
  159. base.effect_enabled = false;
  160. }
  161. public void UpdateGui()
  162. {
  163. this.SettingInput.GetSliderAndInput("focalLength").value = this.value_vector_.x;
  164. this.SettingInput.GetSliderAndInput("focalSize").value = this.value_vector_.y;
  165. this.SettingInput.GetSliderAndInput("aperture").value = this.value_vector_.z;
  166. this.SettingInput.GetSliderAndInput("maxBlurSize").value = this.value_vector_.w;
  167. this.EnabledCheckBox.check = base.effect_enabled;
  168. this.DebugDrawCheckBox.check = this.depth_field_.visualizeFocus;
  169. this.OnChangeEffectEnabled(this.EnabledCheckBox.check);
  170. if (!this.EnabledCheckBox.check || !this.DebugDrawCheckBox.check)
  171. {
  172. FaceWindow faceWindow = this.effect_window_.mgr.GetWindow(PhotoWindowManager.WindowType.Face) as FaceWindow;
  173. faceWindow.PartVisibleCheckBox.enabled = true;
  174. }
  175. }
  176. protected override MonoBehaviour effect_object
  177. {
  178. get
  179. {
  180. return this.depth_field_;
  181. }
  182. }
  183. public WindowPartsInputSliderSet SettingInput;
  184. public WFCheckBox DebugDrawCheckBox;
  185. private DepthOfFieldScatter depth_field_;
  186. private Vector4 backup_value_vector_;
  187. private Vector4 value_vector_;
  188. }