unity ugui Button多状态处理(委托)

 unity ugui Button多状态处理(委托)

当需要处理ugui button多情况处理时  可以在button下挂载此脚本 从界面层直接获取对应脚本组件实现所需委托即可

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class ButtonExt : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler, IPointerEnterHandler
{
    public Action OnPointerDownEvent;
    public Action OnPointerUpEvent;
    public Action OnPointerEnterEvent;
    public Action OnPointerExitEvent;

    public void OnPointerDown(PointerEventData eventData)
    {
        if (OnPointerDownEvent != null)
            OnPointerDownEvent();
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        if (OnPointerUpEvent != null)
            OnPointerUpEvent();
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        if (OnPointerEnterEvent != null)
            OnPointerEnterEvent();
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        if (OnPointerExitEvent != null)
            OnPointerExitEvent();
    }


}

你可能感兴趣的:(Unity3D,unity,游戏引擎,c#)