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

@@ -109,7 +109,7 @@ public class UIDragScrollView : MonoBehaviour
public void OnDrag (Vector2 delta) // modify by chenbin
{
if (scrollView && NGUITools.GetActive(this))
scrollView.Drag();
scrollView.Drag(delta);
}
/// <summary>

View File

@@ -155,7 +155,7 @@ public class UIScrollView : MonoBehaviour
public OnDragNotification onStartCenterOnChild; // add by chenbin
// Deprecated functionality. Use 'movement' instead.
[HideInInspector][SerializeField] Vector3 scale = new Vector3(1f, 0f, 0f);
[HideInInspector][SerializeField] Vector3 scale = new Vector3(0f, 0f, 0f);
// Deprecated functionality. Use 'contentPivot' instead.
[SerializeField][HideInInspector] Vector2 relativePositionOnReset = Vector2.zero;
@@ -368,7 +368,7 @@ public class UIScrollView : MonoBehaviour
if (mStarted && Application.isPlaying) CheckScrollbars();
}
void Start ()
public virtual void Start ()
{
mStarted = true;
if (Application.isPlaying) CheckScrollbars();
@@ -721,7 +721,7 @@ public class UIScrollView : MonoBehaviour
/// Create a plane on which we will be performing the dragging.
/// </summary>
public void Press (bool pressed)
public virtual void Press (bool pressed)
{
if (UICamera.currentScheme == UICamera.ControlScheme.Controller) return;
@@ -794,7 +794,7 @@ public class UIScrollView : MonoBehaviour
/// Drag the object along the plane.
/// </summary>
public void Drag ()
public virtual void Drag (Vector2 delta)
{
if (UICamera.currentScheme == UICamera.ControlScheme.Controller) return;

View File

@@ -22,5 +22,8 @@ public class CLUILoopGridInspector : Editor
} else {
loopGrid.cellCount = EditorGUILayout.IntField("Cell Count", loopGrid.cellCount);
}
NGUIEditorTools.DrawEvents("On Show Head List", loopGrid, loopGrid.OnShowHeadListCallbacks);
NGUIEditorTools.DrawEvents("On Hide Head List", loopGrid, loopGrid.OnHideHeadListCallbacks);
NGUIEditorTools.DrawEvents("On End List", loopGrid, loopGrid.OnEndListCallbacks);
}
}

View File

@@ -0,0 +1,20 @@
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(CLUIScrollViewWithEvent))]
public class CLUIScrollViewWithEventEditor : UIScrollViewEditor
{
public override void OnInspectorGUI ()
{
base.OnInspectorGUI();
NGUIEditorTools.DrawProperty("Loop Grid", serializedObject, "loopGrid");
NGUIEditorTools.DrawProperty("Threshol Delta", serializedObject, "thresholDelta");
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 525b81439717f4a5a9050f535abe8bbe
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

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: