Help us understand the problem. What is going on with this article?

[Unity] uGUIのイベントを他のオブジェクトに流す

More than 5 years have passed since last update.

昨日書いた記事の更新

昨日の記事:[Unity] uGUIのボタンイベントを他のボタンに流す
↑これはボタンのイベントだけ投げたけど、もう全部投げようよと思った。

インスペクタ

b446f9a1a991c17725d5d85e24845ac6.png

コード

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;

public class BypassEvent : MonoBehaviour,
        IPointerEnterHandler,
        IPointerExitHandler,
        IPointerDownHandler,
        IPointerUpHandler,
        IPointerClickHandler,
        IInitializePotentialDragHandler,
        IBeginDragHandler,
        IDragHandler,
        IEndDragHandler,
        IDropHandler,
        IScrollHandler,
        IUpdateSelectedHandler,
        ISelectHandler,
        IDeselectHandler,
        IMoveHandler,
        ISubmitHandler,
        ICancelHandler
{
    public GameObject target;
    private UnityEngine.EventSystems.EventTrigger et;
    private UnityEngine.UI.Button bt;

    void Awake()
    {
        et = target.GetComponent<UnityEngine.EventSystems.EventTrigger>();
        bt = target.GetComponent<Button>();
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnPointerClick(eventData);
        if (bt != null) bt.OnPointerClick(eventData);
    }
    public void OnSubmit(BaseEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnSubmit(eventData);
        if (bt != null) bt.OnSubmit(eventData);
    }
    public void OnPointerDown(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnPointerDown(eventData);
        if (bt != null) bt.OnPointerDown(eventData);
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnPointerEnter(eventData);
        if (bt != null) bt.OnPointerEnter(eventData);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnPointerExit(eventData);
        if (bt != null) bt.OnPointerExit(eventData);
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnPointerUp(eventData);
        if (bt != null) bt.OnPointerUp(eventData);
    }

    public void OnSelect(BaseEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnSelect(eventData);
        if (bt != null) bt.OnSelect(eventData);
    }

    public void OnInitializePotentialDrag(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnInitializePotentialDrag(eventData);
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnBeginDrag(eventData);
    }

    public void OnDrag(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnDrag(eventData);
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnEndDrag(eventData);
    }

    public void OnDrop(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnDrop(eventData);
    }

    public void OnScroll(PointerEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnScroll(eventData);
    }

    public void OnUpdateSelected(BaseEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnUpdateSelected(eventData);
    }

    public void OnCancel(BaseEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnCancel(eventData);
    }

    public void OnDeselect(BaseEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnDeselect(eventData);
        if (bt != null) bt.OnDeselect(eventData);
    }

    public void OnMove(AxisEventData eventData)
    {
        if (!target.activeInHierarchy) return;
        if (et != null) et.OnMove(eventData);
        if (bt != null) bt.OnMove(eventData);
    }
}

備考

EventTriggerとButton書いた。
他のイベントはまだ使わないからいいや。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away