// --------------------------------------------------------------------------------------------------------------------
//
// Part of: Photon Unity Utilities,
//
//
// Used on Buttons inside UI lists to prevent scrollRect parent to scroll when down on buttons.
//
// developer@exitgames.com
// --------------------------------------------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace ExitGames.UtilityScripts
{
///
/// Button inside scroll list will stop scrolling ability of scrollRect container, so that when pressing down on a button and draggin up and down will not affect scrolling.
/// this doesn't do anything if no scrollRect component found in Parent Hierarchy.
///
public class ButtonInsideScrollList : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
ScrollRect scrollRect;
// Use this for initialization
void Start () {
scrollRect = GetComponentInParent();
}
#region IPointerDownHandler implementation
void IPointerDownHandler.OnPointerDown (PointerEventData eventData)
{
if (scrollRect !=null)
{
scrollRect.StopMovement();
scrollRect.enabled = false;
}
}
#endregion
#region IPointerUpHandler implementation
void IPointerUpHandler.OnPointerUp (PointerEventData eventData)
{
if (scrollRect !=null && !scrollRect.enabled)
{
scrollRect.enabled = true;
}
}
#endregion
}
}