ソースコード
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Kogane.Internal
{
<summary>
</summary>
[DisallowMultipleComponent]
internal sealed class NestedScrollRect : ScrollRect
{
private ScrollRect m_parentScrollRect;
private bool m_sendToParent;
private ScrollRect ParentScrollRect =>
m_parentScrollRect ??=
GetComponentsInParent<ScrollRect>()
.First( x => x != this );
<summary>
</summary>
public override void OnBeginDrag( PointerEventData eventData )
{
var delta = eventData.delta;
var x = delta.x;
var y = delta.y;
m_sendToParent =
horizontal && Math.Abs( x ) < Math.Abs( y ) ||
vertical && Math.Abs( y ) < Math.Abs( x );
if ( m_sendToParent )
{
ParentScrollRect.OnBeginDrag( eventData );
}
else
{
ParentScrollRect.velocity = Vector2.zero;
base.OnBeginDrag( eventData );
}
}
<summary>
</summary>
public override void OnDrag( PointerEventData eventData )
{
if ( m_sendToParent )
{
ParentScrollRect.OnDrag( eventData );
}
else
{
base.OnDrag( eventData );
}
}
<summary>
</summary>
public override void OnEndDrag( PointerEventData eventData )
{
if ( m_sendToParent )
{
ParentScrollRect.OnEndDrag( eventData );
}
else
{
base.OnEndDrag( eventData );
}
m_sendToParent = false;
}
}
}