UISettingComponentSystem.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using static System.Net.Mime.MediaTypeNames;
  7. namespace ET.Client
  8. {
  9. [FriendOf(typeof(UISettingComponent))]
  10. public static class UISettingComponentSystem
  11. {
  12. [ObjectSystem]
  13. public class UISettingComponentAwakeSystem : AwakeSystem<UISettingComponent>
  14. {
  15. protected override void Awake(UISettingComponent self)
  16. {
  17. ReferenceCollector rc = self.GetParent<UI>().GameObject.GetComponent<ReferenceCollector>();
  18. self.verCheckBtn = rc.Get<GameObject>("verCheckBtn");
  19. self.verCheckBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnVerCheckBtn(); });
  20. self.quitLoginBtn = rc.Get<GameObject>("quitLoginBtn");
  21. self.quitLoginBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnQuitLoginBtn(); });
  22. self.gameoBgVedioBtn = rc.Get<GameObject>("gameoBgVedioBtn");
  23. self.gameoBgVedioBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnGameoBgVedioBtn(); });
  24. self.gameoInVedioBtn = rc.Get<GameObject>("gameoInVedioBtn");
  25. self.gameoInVedioBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnGameoInVedioBtn(); });
  26. self.closeBtn = rc.Get<GameObject>("closeBtn");
  27. self.closeBtn.GetComponent<Button>().onClick.AddListener(() => { self.OnCloseBtn(); });
  28. self.gameoBgVedioSlider = rc.Get<GameObject>("gameoBgVedioSlider");
  29. self.gameoBgVedioSlider.GetComponent<Slider>().onValueChanged.AddListener((val) => { self.OnGameoBgVedioSlider(val); });
  30. self.gameoInVedioSlider = rc.Get<GameObject>("gameoInVedioSlider");
  31. self.gameoInVedioSlider.GetComponent<Slider>().onValueChanged.AddListener((val) => { self.OnGameoInVedioSlider(val); });
  32. self.Init();
  33. }
  34. }
  35. private static void Init(this UISettingComponent self)
  36. {
  37. }
  38. public static void OnVerCheckBtn(this UISettingComponent self)
  39. {
  40. }
  41. public static void OnQuitLoginBtn(this UISettingComponent self)
  42. {
  43. }
  44. public static async void OnGameoBgVedioBtn(this UISettingComponent self)
  45. {
  46. self.isGameBgVedio = !self.isGameBgVedio;
  47. string abName = self.isGameBgVedio ? "setting_max_sound_sign" : "setting_min_sound_sign";
  48. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(),"setingatlas");
  49. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas",abName);
  50. self.gameoBgVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  51. MusicSoundComponent.Instance.MusicMuteSwitch(!self.isGameBgVedio);
  52. self.gameoBgVedioSlider.GetComponent<Slider>().value = self.isGameBgVedio? PlayerPrefs.GetFloat(MusicSoundComponent.MusicVolumeBgPrefsName) : 0;
  53. }
  54. public static async void OnGameoInVedioBtn(this UISettingComponent self)
  55. {
  56. self.isGameInVedio = !self.isGameInVedio;
  57. string abName = self.isGameInVedio ? "setting_max_sound_sign" : "setting_min_sound_sign";
  58. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "setingatlas");
  59. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas", abName);
  60. self.gameoInVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  61. MusicSoundComponent.Instance.SoundMuteSwitch(!self.isGameInVedio);
  62. self.gameoInVedioSlider.GetComponent<Slider>().value = self.isGameInVedio ? PlayerPrefs.GetFloat(MusicSoundComponent.SoundVolumePrefsName) : 0;
  63. }
  64. public static void OnCloseBtn(this UISettingComponent self)
  65. {
  66. self.OnCloseAsync();
  67. }
  68. public static async void OnGameoBgVedioSlider(this UISettingComponent self,float val)
  69. {
  70. if (val <= 0)
  71. {
  72. return;
  73. }
  74. self.isGameBgVedio = true;
  75. string abName = self.isGameBgVedio ? "setting_max_sound_sign" : "setting_min_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. MusicSoundComponent.Instance.MusicMuteSwitch(!self.isGameBgVedio);
  80. MusicSoundComponent.Instance.MusicBgVolume = val;
  81. }
  82. public static async void OnGameoInVedioSlider(this UISettingComponent self, float val)
  83. {
  84. if (val <= 0)
  85. {
  86. return;
  87. }
  88. self.isGameInVedio = true;
  89. string abName = self.isGameInVedio ? "setting_max_sound_sign" : "setting_min_sound_sign";
  90. await ResourcesComponentHelper.Instance.LoadSprite(self.ClientScene(), "setingatlas");
  91. Sprite sprite = ResourcesComponentHelper.Instance.GetSprite("setingatlas", abName);
  92. self.gameoInVedioBtn.GetComponent<UnityEngine.UI.Image>().sprite = sprite;
  93. MusicSoundComponent.Instance.SoundMuteSwitch(!self.isGameInVedio);
  94. MusicSoundComponent.Instance.SoundVolume = val;
  95. }
  96. public static async void OnCloseAsync(this UISettingComponent self)
  97. {
  98. await UIHelper.Remove(self.ClientScene(),UIType.UISetting);
  99. }
  100. }
  101. }