| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.UI; |
| | 3 | |
|
| | 4 | | public class ColorToggle : UIButton |
| | 5 | | { |
| 0 | 6 | | public Color color { get; private set; } |
| | 7 | |
|
| | 8 | | [SerializeField] |
| | 9 | | private Image colorPicker; |
| | 10 | |
|
| | 11 | | [SerializeField] |
| | 12 | | private Image selectionHighlight; |
| | 13 | |
|
| | 14 | | private bool selectedValue; |
| | 15 | |
|
| | 16 | | public bool selected |
| | 17 | | { |
| 0 | 18 | | get { return selectedValue; } |
| | 19 | | set |
| | 20 | | { |
| 1555 | 21 | | selectedValue = value; |
| 1555 | 22 | | selectionHighlight.enabled = selectedValue; |
| 1555 | 23 | | } |
| | 24 | | } |
| | 25 | |
|
| | 26 | | public event System.Action<ColorToggle> OnClicked; |
| | 27 | |
|
| | 28 | | private new void Awake() |
| | 29 | | { |
| 910 | 30 | | base.Awake(); |
| 910 | 31 | | Application.quitting += () => |
| | 32 | | { |
| 0 | 33 | | OnClicked = null; |
| 0 | 34 | | }; |
| 910 | 35 | | } |
| | 36 | |
|
| | 37 | | public void Initialize(Color c, bool on) |
| | 38 | | { |
| 1380 | 39 | | color = c; |
| 1380 | 40 | | colorPicker.color = color; |
| 1380 | 41 | | selected = on; |
| 1380 | 42 | | } |
| | 43 | |
|
| 0 | 44 | | protected override void OnClick() { OnClicked?.Invoke(this); } |
| | 45 | | } |