• Unity中ScrollRect拖拽子物体无法拖拽


    当SrollRect下面的子物体添加了一些事件的时候,子物体的事件会阻挡ScrollRect的事件的监测,所有我们进行如下的脚本,手动调用ScrollRect事件。代码如下:


    /*******************
     *  Title:CW_FrameWark
     *  Author:CW
     *  ScriptName:  DragScrollRect
     *  Des:子物体有事件拖拽等事件监听的时候,ScrollRect可以生效
     ******************/
    using UnityEngine;
    using System.Collections;
    using UnityEngine.EventSystems;
    using UnityEngine.UI;

    namespace CW_FrameWark
    {
        public class DragScrollRect : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler
        {
            [Header("要拖动的ScrollRect")]
            public ScrollRect DragScorll;
            public void OnBeginDrag(PointerEventData eventData)
            {
               if(DragScorll!=null)
                {
                    DragScorll.OnBeginDrag(eventData);
                }
            }

            public void OnDrag(PointerEventData eventData)
            {
                if (DragScorll != null)
                {
                    DragScorll.OnDrag(eventData);
                }
            }

            public void OnEndDrag(PointerEventData eventData)
            {
                if (DragScorll != null)
                {
                    DragScorll.OnEndDrag(eventData);
                }
            }
        }
    }


  • 相关阅读:
    Bottle python
    mongodb python pymongo
    Directory常用
    File类常用
    Path类的常用方法
    winfrom的单例模式
    325工厂模式和面向对象知识点总结(有点乱凑合看)
    音乐播放器自动播放下一首歌记录
    c#分页类(转)
    c# 简历生成器
  • 原文地址:https://www.cnblogs.com/weiqiangwaideshijie/p/7700163.html
Copyright © 2020-2023  润新知