You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

74 line
1.5 KiB

  1. using System;
  2. using CIG.Translation;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class ToggleButton : MonoBehaviour
  6. {
  7. public void SetState(bool isEnabled)
  8. {
  9. this.SetState(isEnabled, null);
  10. }
  11. public void SetState(bool isEnabled, ILocalizedString text)
  12. {
  13. if (this._text != null)
  14. {
  15. this._text.LocalizedString = text;
  16. }
  17. if (isEnabled)
  18. {
  19. this._buttonImage.sprite = this._enabledButtonSprite;
  20. if (this._text != null)
  21. {
  22. this._text.TextField.color = this._enabledTextColor;
  23. }
  24. if (this._textShadow != null)
  25. {
  26. this._textShadow.effectColor = this._enabledShadowColor;
  27. }
  28. }
  29. else
  30. {
  31. this._buttonImage.sprite = this._disabledButtonSprite;
  32. if (this._text != null)
  33. {
  34. this._text.TextField.color = this._disabledTextColor;
  35. }
  36. if (this._textShadow != null)
  37. {
  38. this._textShadow.effectColor = this._disabledShadowColor;
  39. }
  40. }
  41. }
  42. [SerializeField]
  43. private Image _buttonImage;
  44. [SerializeField]
  45. private Sprite _enabledButtonSprite;
  46. [SerializeField]
  47. private Sprite _disabledButtonSprite;
  48. [SerializeField]
  49. [Tooltip("(Optional)")]
  50. private LocalizedText _text;
  51. [SerializeField]
  52. private Color _enabledTextColor;
  53. [SerializeField]
  54. private Color _disabledTextColor;
  55. [SerializeField]
  56. [Tooltip("(Optional)")]
  57. private Shadow _textShadow;
  58. [SerializeField]
  59. private Color _enabledShadowColor;
  60. [SerializeField]
  61. private Color _disabledShadowColor;
  62. }