先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
97 lines
2.6 KiB
C#
97 lines
2.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class SubScrollRect : ScrollRect
|
|
{
|
|
//父ScrollRect对象
|
|
private ScrollRect m_Parent;
|
|
|
|
public enum Direction
|
|
{
|
|
Horizontal,
|
|
Vertical
|
|
}
|
|
|
|
//滑动方向
|
|
private Direction m_Direction = Direction.Horizontal;
|
|
|
|
//当前操作方向
|
|
private Direction m_BeginDragDirection = Direction.Horizontal;
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
//找到父对象
|
|
Transform parent = transform.parent;
|
|
m_Parent = parent.GetComponentInParent<ScrollRect>();
|
|
|
|
m_Direction = this.horizontal ? Direction.Horizontal : Direction.Vertical;
|
|
}
|
|
|
|
|
|
public override void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
if (m_Parent)
|
|
{
|
|
m_BeginDragDirection = Mathf.Abs(eventData.delta.x) > Mathf.Abs(eventData.delta.y)
|
|
? Direction.Horizontal
|
|
: Direction.Vertical;
|
|
if (m_BeginDragDirection != m_Direction)
|
|
{
|
|
//当前操作方向不等于滑动方向,将事件传给父对象
|
|
ExecuteEvents.Execute(m_Parent.gameObject, eventData, ExecuteEvents.beginDragHandler);
|
|
return;
|
|
}
|
|
}
|
|
|
|
base.OnBeginDrag(eventData);
|
|
}
|
|
|
|
public override void OnDrag(PointerEventData eventData)
|
|
{
|
|
if (m_Parent)
|
|
{
|
|
if (m_BeginDragDirection != m_Direction)
|
|
{
|
|
//当前操作方向不等于滑动方向,将事件传给父对象
|
|
ExecuteEvents.Execute(m_Parent.gameObject, eventData, ExecuteEvents.dragHandler);
|
|
return;
|
|
}
|
|
}
|
|
|
|
base.OnDrag(eventData);
|
|
}
|
|
|
|
public override void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
if (m_Parent)
|
|
{
|
|
if (m_BeginDragDirection != m_Direction)
|
|
{
|
|
//当前操作方向不等于滑动方向,将事件传给父对象
|
|
ExecuteEvents.Execute(m_Parent.gameObject, eventData, ExecuteEvents.endDragHandler);
|
|
return;
|
|
}
|
|
}
|
|
|
|
base.OnEndDrag(eventData);
|
|
}
|
|
|
|
public override void OnScroll(PointerEventData data)
|
|
{
|
|
if (m_Parent)
|
|
{
|
|
if (m_BeginDragDirection != m_Direction)
|
|
{
|
|
//当前操作方向不等于滑动方向,将事件传给父对象
|
|
ExecuteEvents.Execute(m_Parent.gameObject, data, ExecuteEvents.scrollHandler);
|
|
return;
|
|
}
|
|
}
|
|
|
|
base.OnScroll(data);
|
|
}
|
|
} |