111 lines
2.8 KiB
C#
111 lines
2.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Coolape;
|
|
|
|
public class CLUIScrollViewWithEvent : UIScrollView
|
|
{
|
|
public CLUILoopGrid loopGrid;
|
|
public Vector2 thresholDelta = new Vector2(0, -100);
|
|
bool isShowHead = false;
|
|
bool isPress = false;
|
|
Vector2 totalDelta = Vector2.zero;
|
|
|
|
public object showRefreshFlag;
|
|
public object hideRefreshFlag;
|
|
public object doRefresh;
|
|
|
|
public void init(object onShowRefreshFlag, object onHideRefreshFlag, object onDoRefresh)
|
|
{
|
|
showRefreshFlag = onShowRefreshFlag;
|
|
hideRefreshFlag = onHideRefreshFlag;
|
|
doRefresh = onDoRefresh;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
disableDragIfFits = false;
|
|
|
|
if (loopGrid == null)
|
|
{
|
|
loopGrid = GetComponent<CLUILoopGrid>();
|
|
if (loopGrid == null)
|
|
{
|
|
loopGrid = GetComponentInChildren<CLUILoopGrid>();
|
|
}
|
|
}
|
|
|
|
if (loopGrid != null && Application.isPlaying)
|
|
{
|
|
EventDelegate ed = new EventDelegate();
|
|
ed.target = this;
|
|
ed.methodName = "onShowHeadList";
|
|
loopGrid.OnShowHeadListCallbacks.Add(ed);
|
|
|
|
ed = new EventDelegate();
|
|
ed.target = this;
|
|
ed.methodName = "onHideHeadList";
|
|
loopGrid.OnHideHeadListCallbacks.Add(ed);
|
|
}
|
|
}
|
|
|
|
public void onShowHeadList(GameObject go)
|
|
{
|
|
isShowHead = true;
|
|
if (isPress)
|
|
{
|
|
Utl.doCallback(showRefreshFlag);
|
|
}
|
|
}
|
|
public void onHideHeadList(GameObject go)
|
|
{
|
|
isShowHead = false;
|
|
}
|
|
|
|
public override void Drag(Vector2 delta)
|
|
{
|
|
base.Drag(delta);
|
|
if (isPress && isShowHead)
|
|
{
|
|
totalDelta += delta;
|
|
}
|
|
}
|
|
|
|
public override void Press(bool pressed)
|
|
{
|
|
base.Press(pressed);
|
|
isPress = pressed;
|
|
if (isPress)
|
|
{
|
|
totalDelta = Vector2.zero;
|
|
if (isShowHead)
|
|
{
|
|
Utl.doCallback(showRefreshFlag);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (isShowHead)
|
|
{
|
|
Debug.Log(totalDelta);
|
|
if ((movement == Movement.Vertical && totalDelta.y <= thresholDelta.y) || (movement == Movement.Horizontal && totalDelta.x >= thresholDelta.x))
|
|
{
|
|
Utl.doCallback(doRefresh);
|
|
}
|
|
else
|
|
{
|
|
Utl.doCallback(hideRefreshFlag);
|
|
ResetPosition();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Utl.doCallback(hideRefreshFlag);
|
|
MoveRelative(Vector3.zero);
|
|
}
|
|
}
|
|
}
|
|
}
|