

using System.Collections.Generic;
using System.Linq;
using UnityEngine.Events;

namespace RoaringFangs.Utility
{
    public static class UI
    {
        public static void BindButtonAction(
            IEnumerable<UnityEngine.UI.Button> all_buttons,
            string button_name,
            UnityAction handler,
            bool remove_existing_handlers = false)
        {
            var buttons_matching = all_buttons
                .Where(b => b.name == button_name);
            foreach (var button in buttons_matching)
            {
                if (remove_existing_handlers)
                    button.onClick.RemoveAllListeners();
                button.onClick.RemAddListenerAuto(handler);
            }
        }
    }
}