SwitchButtonComp.cs 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UI.Hall;
  5. using Unity.VisualScripting;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class SwitchButtonComp : MonoBehaviour
  9. {
  10. // public GameObject OnDisplay;
  11. public Sprite onSprite;
  12. public Sprite offSprite;
  13. public int Flag;
  14. private bool _on;
  15. private void Start()
  16. {
  17. if (Flag == 0)
  18. {
  19. throw new NotImplementedException();
  20. }
  21. _on = SettingManager.Instance.isSettingOpen(Flag);
  22. show();
  23. }
  24. private void show()
  25. {
  26. if (_on)
  27. {
  28. this.GetComponent<Image>().sprite = onSprite;
  29. }
  30. else
  31. {
  32. this.GetComponent<Image>().sprite = offSprite;
  33. }
  34. }
  35. public void A__ClickSwitch()
  36. {
  37. _on = !_on;
  38. show();
  39. SettingManager.Instance.changSetting(Flag, _on);
  40. }
  41. }