public static void SetListener(this Toggle toggle, UnityAction <bool> action, IButtonSoundProvider soundProvider) { if (toggle == null) { return; } toggle.onValueChanged.RemoveAllListeners(); toggle.onValueChanged.AddListener((isOn) => { soundProvider?.PlayButton(); action?.Invoke(isOn); }); }
public static void SetListener(this Button button, UnityAction action, IButtonSoundProvider soundProvider) { if (button == null) { return; } button.onClick.RemoveAllListeners(); button.onClick.AddListener(() => { soundProvider?.PlayButton(); action?.Invoke(); }); }
public static void SetEventTriggerClick(this EventTrigger trigger, UnityAction <BaseEventData> onClick, IButtonSoundProvider soundProvider) { trigger?.triggers?.Clear(); if (onClick != null) { EventTrigger.TriggerEvent clickEvent = new EventTrigger.TriggerEvent(); clickEvent.AddListener((bed) => { soundProvider?.PlayButton(); onClick?.Invoke(bed); }); trigger?.triggers?.Add(new EventTrigger.Entry { eventID = EventTriggerType.PointerClick, callback = clickEvent }); } }