upgrade
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Coolape;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
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)
|
||||
{
|
||||
Debug.LogError("onShowHeadList");
|
||||
isShowHead = true;
|
||||
if (isPress)
|
||||
{
|
||||
Utl.doCallback(showRefreshFlag);
|
||||
}
|
||||
}
|
||||
public void onHideHeadList(GameObject go)
|
||||
{
|
||||
Debug.LogError("onHideHeadList");
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user