UISettingComponentSystem.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using static ET.GameSetting;
  7. using static System.Net.Mime.MediaTypeNames;
  8. namespace ET.Client
  9. {
  10. [FriendOf(typeof(UISettingComponent))]
  11. public static class UISettingComponentSystem
  12. {
  13. [ObjectSystem]
  14. public class UISettingComponentAwakeSystem : AwakeSystem<UISettingComponent>
  15. {
  16. protected override void Awake(UISettingComponent self, params object[] param)
  17. {
  18. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  19. self.verCheckBtn = rc.Get<GameObject>("verCheckBtn");
  20. self.verCheckBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnVerCheckBtn(); });
  21. self.quitLoginBtn = rc.Get<GameObject>("quitLoginBtn");
  22. self.quitLoginBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnQuitLoginBtn(); });
  23. self.quitGameBtn = rc.Get<GameObject>("quitGameBtn");
  24. self.quitGameBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnQuitGameBtn(); });
  25. self.gameoBgVedioBtn = rc.Get<GameObject>("gameoBgVedioBtn");
  26. self.gameoBgVedioBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnGameoBgVedioBtn(); });
  27. self.gameoInVedioBtn = rc.Get<GameObject>("gameoInVedioBtn");
  28. self.gameoInVedioBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnGameoInVedioBtn(); });
  29. self.closeBtn = rc.Get<GameObject>("closeBtn");
  30. self.closeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseBtn(); });
  31. self.gameoBgVedioSlider = rc.Get<GameObject>("gameoBgVedioSlider");
  32. self.gameoBgVedioSlider.GetComponent<Slider>().onValueChanged.AddListener((val) => { self.OnGameoBgVedioSlider(val); });
  33. self.gameoInVedioSlider = rc.Get<GameObject>("gameoInVedioSlider");
  34. self.gameoInVedioSlider.GetComponent<Slider>().onValueChanged.AddListener((val) => { self.OnGameoInVedioSlider(val); });
  35. self.Init();
  36. }
  37. }
  38. private static async void Init(this UISettingComponent self)
  39. {
  40. var value = GameSetting.Instance.GetFloat(MusicSets.Mute_BG);
  41. self.gameoBgVedioSlider.GetComponent<Slider>().value = value;
  42. self.isGameBgVedio = value > 0? false : true;
  43. string abName = self.isGameBgVedio ? "setting_min_sound_sign" : "setting_max_sound_sign";
  44. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "setingatlas");
  45. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas", abName);
  46. self.gameoBgVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  47. value = GameSetting.Instance.GetFloat(MusicSets.Mute_Music);
  48. self.gameoInVedioSlider.GetComponent<Slider>().value = value;
  49. self.isGameInVedio = value > 0 ? false : true;
  50. abName = self.isGameInVedio ? "setting_min_sound_sign" : "setting_max_sound_sign";
  51. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "setingatlas");
  52. sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas", abName);
  53. self.gameoInVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  54. }
  55. public static async void OnVerCheckBtn(this UISettingComponent self)
  56. {
  57. await SoundManager.Instance.PlaySound("clickbtnsound");
  58. }
  59. public static async void OnQuitGameBtn(this UISettingComponent self)
  60. {
  61. await SoundManager.Instance.PlaySound("clickbtnsound");
  62. UnityEngine.Application.Quit();
  63. }
  64. public static async void OnQuitLoginBtn(this UISettingComponent self)
  65. {
  66. await SoundManager.Instance.PlaySound("clickbtnsound");
  67. await UIHelper.Remove(self.ClientScene(), UIType.UIMain);
  68. await UIHelper.Remove(self.ClientScene(), UIType.UISetting);
  69. await EventSystem.Instance.PublishAsync(GameUtil.Instance.GetSceneComponent(), new EventType.AppStartInitFinish());
  70. }
  71. public static async void OnGameoBgVedioBtn(this UISettingComponent self)
  72. {
  73. await SoundManager.Instance.PlaySound("clickbtnsound");
  74. self.isGameBgVedio = !self.isGameBgVedio;
  75. string abName = self.isGameBgVedio ? "setting_min_sound_sign" : "setting_max_sound_sign";
  76. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(),"setingatlas");
  77. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas",abName);
  78. self.gameoBgVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  79. SoundManager.Instance.BGMute = self.isGameBgVedio;
  80. float value = GameSetting.Instance.GetFloat(MusicSets.Mute_BG);
  81. if (self.isGameBgVedio)
  82. {
  83. value = 0;
  84. }
  85. else
  86. {
  87. value = value == 0? 1 : value;
  88. }
  89. self.gameoBgVedioSlider.GetComponent<Slider>().value = value;
  90. GameSetting.Instance.SetFloat(MusicSets.Mute_BG, value);
  91. }
  92. public static async void OnGameoInVedioBtn(this UISettingComponent self)
  93. {
  94. await SoundManager.Instance.PlaySound("clickbtnsound");
  95. self.isGameInVedio = !self.isGameInVedio;
  96. string abName = self.isGameInVedio ? "setting_min_sound_sign" : "setting_max_sound_sign";
  97. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "setingatlas");
  98. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas", abName);
  99. self.gameoInVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  100. SoundManager.Instance.MusicMute = self.isGameInVedio;
  101. float value = GameSetting.Instance.GetFloat(MusicSets.Mute_Music);
  102. if (self.isGameInVedio)
  103. {
  104. value = 0;
  105. }
  106. else
  107. {
  108. value = value == 0 ? 1 : value;
  109. }
  110. self.gameoInVedioSlider.GetComponent<Slider>().value = value;
  111. GameSetting.Instance.SetFloat(MusicSets.Mute_Music, value);
  112. }
  113. public static async void OnCloseBtn(this UISettingComponent self)
  114. {
  115. await SoundManager.Instance.PlaySound("clickbtnsound");
  116. self.OnCloseAsync();
  117. }
  118. public static async void OnGameoBgVedioSlider(this UISettingComponent self,float val)
  119. {
  120. if (val < 0)
  121. {
  122. val = 0;
  123. }
  124. self.isGameBgVedio = val == 0?true:false;
  125. string abName = self.isGameBgVedio ? "setting_min_sound_sign" : "setting_max_sound_sign";
  126. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "setingatlas");
  127. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas", abName);
  128. self.gameoBgVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  129. SoundManager.Instance.BGMute = self.isGameBgVedio;
  130. SoundManager.Instance.BGVolume = val;
  131. GameSetting.Instance.SetFloat(MusicSets.Mute_BG, val);
  132. }
  133. public static async void OnGameoInVedioSlider(this UISettingComponent self, float val)
  134. {
  135. if (val < 0)
  136. {
  137. val = 0;
  138. }
  139. self.isGameInVedio = val == 0 ? true : false;
  140. string abName = self.isGameInVedio ? "setting_min_sound_sign" : "setting_max_sound_sign";
  141. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "setingatlas");
  142. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas", abName);
  143. self.gameoInVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  144. SoundManager.Instance.MusicMute = self.isGameInVedio;
  145. SoundManager.Instance.MusicVolume = val;
  146. GameSetting.Instance.SetFloat(MusicSets.Mute_Music, val);
  147. }
  148. public static async void OnCloseAsync(this UISettingComponent self)
  149. {
  150. await UIHelper.Remove(self.ClientScene(),UIType.UISetting);
  151. }
  152. }
  153. }