This commit is contained in:
2020-07-05 15:44:30 +08:00
parent a8f02e4da5
commit e344c54d82
32 changed files with 647 additions and 209 deletions

View File

@@ -150,6 +150,32 @@ namespace Coolape
object initCellCallback;
object onEndListCallback;
object onHeadListCallback;
public List<EventDelegate> OnShowHeadListCallbacks = new List<EventDelegate>();
public List<EventDelegate> OnHideHeadListCallbacks = new List<EventDelegate>();
public List<EventDelegate> OnEndListCallbacks = new List<EventDelegate>();
protected void ExecuteOnEndList()
{
if (EventDelegate.IsValid(OnEndListCallbacks))
{
EventDelegate.Execute(OnEndListCallbacks, gameObject); // modify by chenbin
}
}
protected void ExecuteOnShowHeadList()
{
if (EventDelegate.IsValid(OnShowHeadListCallbacks))
{
EventDelegate.Execute(OnShowHeadListCallbacks, gameObject); // modify by chenbin
}
}
protected void ExecuteOnHideHeadList()
{
if (EventDelegate.IsValid(OnHideHeadListCallbacks))
{
EventDelegate.Execute(OnHideHeadListCallbacks, gameObject); // modify by chenbin
}
}
public void refreshContentOnly ()
{
@@ -469,7 +495,12 @@ namespace Coolape
// Debug.Log (int.Parse (head.name) + "=11===" + (list.Count - 1) + "===" + firstVislable);
// Debug.Log (int.Parse (tail.name) + "=22===" + (list.Count - 1) + "===" + lastVisiable);
if (firstVislable && int.Parse (head.name) > 0) {
if (firstVislable && int.Parse (head.name) > 0)
{
if (!isCanCallOnHeadList)
{
ExecuteOnHideHeadList();
}
isCanCallOnEndList = true;
isCanCallOnHeadList = true;
times--;
@@ -477,7 +508,12 @@ namespace Coolape
sourceIndex = itemList.Count - 1;
targetIndex = 0;
sign = 1;
} else if (lastVisiable && int.Parse (tail.name) < list.Count - 1) {
} else if (lastVisiable && int.Parse (tail.name) < list.Count - 1)
{
if (!isCanCallOnHeadList)
{
ExecuteOnHideHeadList();
}
isCanCallOnEndList = true;
isCanCallOnHeadList = true;
times++;
@@ -491,8 +527,13 @@ namespace Coolape
isCanCallOnHeadList = false;
Utl.doCallback (this.onHeadListCallback, head);
ExecuteOnShowHeadList();
}
} else {
if(!isCanCallOnHeadList)
{
ExecuteOnHideHeadList();
}
isCanCallOnHeadList = true;
}
if (lastVisiable && int.Parse (tail.name) == list.Count - 1) {
@@ -501,8 +542,10 @@ namespace Coolape
isCanCallOnEndList = false;
Utl.doCallback (this.onEndListCallback, tail);
ExecuteOnEndList();
}
} else {
} else
{
isCanCallOnEndList = true;
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5c85efbbc1ec4b75939e6d7f077e68c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: