Change ActionButton input source

Hi,

Is it possible to set ActionButton to react by right click instead of left in another way than override OnPointerClick?
The same question is for ItemViewSlot
 
Thank you for making the post, here are the changes I made to the Item Actions button:
Code:
/// <summary>
/// A action button class, used when the default Button is not flexible enough.
/// </summary>
public class ActionButton : Selectable, IPointerClickHandler, ISubmitHandler, ICancelHandler, IBeginDragHandler, IEndDragHandler, IDragHandler, IDropHandler
{
    [Flags]
    [Serializable]
    public enum InputButton {
        Left = 0x1,
        Right = 0x2,
        Middle = 0x4
    }
    
    public event Action OnSubmitE;
    public event Action OnSelectE;
    public event Action OnDeselectE;
    public event Action OnCancelE;
    public event Action<AxisEventData, bool> OnMoveE;
    public event Action<PointerEventData> OnPointerDownE;
    public event Action<PointerEventData> OnPointerUpE;
    public event Action<PointerEventData> OnPointerEnterE;
    public event Action<PointerEventData> OnPointerExitE;
    public event Action<PointerEventData> OnBeginDragE;
    public event Action<PointerEventData> OnEndDragE;
    public event Action<PointerEventData> OnDragE;
    public event Action<PointerEventData> OnDropE;
    [Tooltip("Disable and selected sprite, an extension for the selectable sprite transitions.")]
    [SerializeField] protected Sprite m_DisabledAndSelectedSprite;
    [Tooltip("Disable and selected color, an extension for the selectable color transitions.")]
    [SerializeField] protected Color m_DisabledAndSelectedColor = Color.gray;
    [Tooltip("The text that displays the action name.")]
    [SerializeField] protected Text m_Text;
    [Tooltip("The on click Unity Action.")]
    [SerializeField] internal UnityEvent m_OnClickEvent;
    [Tooltip("Choose what input button get to press button on click.")]
    [SerializeField] protected InputButton m_OnPointerClickInputButton = InputButton.Left;
    [Tooltip("Send a Select enver when the pointer enters.")]
    [SerializeField] protected bool m_SelectOnPointerEnter = true;
    [Tooltip("Send a Deselect envent when the pointer exits.")]
    [SerializeField] protected bool m_DeselectOnPointerExit = true;
    [Tooltip("If the button detects a click on while unselected should it select and stop [false] or should it select and click [true].")]
    [SerializeField] protected bool m_UnselectedPressSelectsAndPress = false;
    protected Action m_CachedHandler;
    protected bool m_Selected = false;
    /// <summary>
    /// Press the button.
    /// </summary>
    private void Press()
    {
        if (!IsActive() || !IsInteractable()) {
            return;
        }
        UISystemProfilerApi.AddMarker("Button.onClick", (UnityEngine.Object)this);
        if (!m_Selected) {
            Select();
            if (m_UnselectedPressSelectsAndPress == false) {
                return;
            }
        }
        m_OnClickEvent.Invoke();
        OnSubmitE?.Invoke();
    }
    /// <summary>
    /// Invoke OnSelect even if it was already selected.
    /// </summary>
    public override void Select()
    {
        EventSystemManager.Select(gameObject);
        OnSelect(null);
    }
    /// <summary>
    /// Get the name of the button.
    /// </summary>
    public virtual string GetButtonName()
    {
        return m_Text.text;
    }
    /// <summary>
    /// Set the name of the button.
    /// </summary>
    /// <param name="newName">The new name.</param>
    public virtual void SetButtonName(string newName)
    {
        m_Text.text = newName;
    }
    /// <summary>
    /// Set the Button action. Only one at a time.
    /// </summary>
    /// <param name="buttonAction">The new button action.</param>
    public virtual void SetButtonAction(Action buttonAction)
    {
        OnSubmitE -= m_CachedHandler;
        OnSubmitE += buttonAction;
        m_CachedHandler = buttonAction;
    }
    /// <summary>
    ///   <para>Registered IPointerClickHandler callback.</para>
    /// </summary>
    /// <param name="eventData">Data passed in (Typically by the event system).</param>
    public virtual void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Left) {
            if ((m_OnPointerClickInputButton & InputButton.Left) == 0) {
                return;
            }
        }
        if (eventData.button == PointerEventData.InputButton.Right) {
            if ((m_OnPointerClickInputButton & InputButton.Right) == 0) {
                return;
            }
        }
        if (eventData.button == PointerEventData.InputButton.Middle) {
            if ((m_OnPointerClickInputButton & InputButton.Middle) == 0) {
                return;
            }
        }
        Press();
    }

Hopefully that works the way you want.

Note: PointerEventData.InputButton was not flagged so I had to add a new enum InputButton. Since they are not equivalent the OnPointerClick function is a bit more verbose tha you would first expect
 
Top