using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using LuaInterface; using LuaFramework; using System; using UnityEngine.EventSystems; public class VHScrollRect : ScrollRect { public ScrollRect parentScroll; public bool isVertical = false; private bool isSelf = false; public override void OnBeginDrag(PointerEventData eventData) { Vector2 touchDeltaPosition; #if (UNITY_ANDROID || UNITY_IPHONE) && !UNITY_EDITOR touchDeltaPosition = Input.GetTouch(0).deltaPosition; #else float delta_x = Input.GetAxis("Mouse X"); float delta_y = Input.GetAxis("Mouse Y"); touchDeltaPosition = new Vector2(delta_x, delta_y); #endif if (isVertical) { if (Mathf.Abs(touchDeltaPosition.x) < Mathf.Abs(touchDeltaPosition.y)) { isSelf = true; base.OnBeginDrag(eventData); } else { isSelf = false; if(parentScroll){ parentScroll.OnBeginDrag(eventData); } } } else { if (Mathf.Abs(touchDeltaPosition.x) > Mathf.Abs(touchDeltaPosition.y)) { isSelf = true; base.OnBeginDrag(eventData); } else { isSelf = false; if(parentScroll){ parentScroll.OnBeginDrag(eventData); } } } } public override void OnDrag(PointerEventData eventData) { if (isSelf) { base.OnDrag(eventData); } else { if(parentScroll){ parentScroll.OnDrag(eventData); } } } public override void OnEndDrag(PointerEventData eventData) { if (isSelf) { base.OnEndDrag(eventData); } else { if(parentScroll){ parentScroll.OnEndDrag(eventData); } } } }