This commit is contained in:
Caiyanpeng committed 2021-08-27 10:12:50 +08:00
1 parent f21b83697b
commit 428a7c5507
24 files changed
+751 -26

No files matched your search

@@ -14,9 +14,27 @@ public class QuickLoginScroll : MonoBehaviour
private float contentSize;
private int count;
[SerializeField] Button L, R;
float startPos, endPos;
void Start()
{
scroll = gameObject.GetComponent<ScrollRect>();
UIManager.AddEvent(scroll.gameObject, UnityEngine.EventSystems.EventTriggerType.BeginDrag, b =>
{
startPos = scroll.horizontalNormalizedPosition;
Debug.Log(startPos);
});
UIManager.AddEvent(scroll.gameObject, UnityEngine.EventSystems.EventTriggerType.EndDrag, b =>
{
endPos = scroll.horizontalNormalizedPosition;
if (startPos > endPos)
{
goLeft();
}
else if (startPos < endPos)
{
goRight();
}
});
//scroll.onValueChanged.AddListener((a) =>
//{
// Debug.Log(a);
@@ -28,6 +46,7 @@ public class QuickLoginScroll : MonoBehaviour
{
UIManager.AddEvent(L.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick,(b)=>
{
startPos = scroll.horizontalNormalizedPosition;
goLeft();
});
//L.onClick.AddListener(goLeft);
@@ -36,6 +55,7 @@ public class QuickLoginScroll : MonoBehaviour
{
UIManager.AddEvent(R.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
startPos = scroll.horizontalNormalizedPosition;
goRight();
});
//R.onClick.AddListener(goRight);
@@ -67,6 +87,7 @@ public class QuickLoginScroll : MonoBehaviour
if (content.childCount - 3 > 0)
{
contentSize = 1f / (content.childCount - 3);
Debug.Log(contentSize);
}
else
{
@@ -82,32 +103,39 @@ public class QuickLoginScroll : MonoBehaviour
scroll.horizontalNormalizedPosition = contentSize/2+i*contentSize;
#else
scroll.horizontalNormalizedPosition = i * contentSize;
Debug.Log(scroll.horizontalNormalizedPosition);
#endif
SetColor();
}
void goLeft()
{
Debug.Log($"{scroll.horizontalNormalizedPosition},{contentSize}");
if (scroll.horizontalNormalizedPosition+0.0001 <= contentSize) return;
if (scroll.horizontalNormalizedPosition <= 0 + 0.0001) return;
goMove(-1);
}
void goRight()
{
Debug.Log(scroll.horizontalNormalizedPosition);
if (scroll.horizontalNormalizedPosition+0.0001 >= 1) return;
goMove();
}
void goMove(int i = 1)
{
doAni();
//#if !(UNITY_ANDROID || UNITY_IOS)
// if (!start) startPosition = scroll.horizontalNormalizedPosition;
//#else
// int ind = GetIndex(startPos);
// if (!start) startPosition = ind*contentSize;
//#endif
if (!start) startPosition = scroll.horizontalNormalizedPosition;
start = true;
scrollValue = i*contentSize / 10;
#if !(UNITY_ANDROID || UNITY_IOS)
scrollValue = i * contentSize / 10;
#else
scrollValue = ((GetIndex(startPos) + i) * contentSize - startPos) / 10;
#endif
}
private bool start = false;
private float scrollValue = 0, totalScrollValue = 0, startPosition = 0;
int GetIndex()
int GetIndex(float? startPos = null)
{
#if !(UNITY_ANDROID || UNITY_IOS)
return (int)System.Math.Round(
@@ -118,9 +146,8 @@ public class QuickLoginScroll : MonoBehaviour
{
return 1;
}
return (int)System.Math.Round(
(scroll.horizontalNormalizedPosition+ contentSize) / contentSize,
0);
return (int)System.Math.Round
((startPos ?? scroll.horizontalNormalizedPosition + contentSize) / contentSize, 0);
#endif
}
void SetColor()
@@ -156,7 +183,11 @@ public class QuickLoginScroll : MonoBehaviour
{
scrollValue = 0;
start = false;
#if !(UNITY_ANDROID || UNITY_IOS)
scroll.horizontalNormalizedPosition = startPosition + (totalScrollValue<0?-1:1)*contentSize;
#else
scroll.horizontalNormalizedPosition = (GetIndex(startPos) + (totalScrollValue < 0 ? -1 : 1)) * contentSize;
#endif
//Debug.Log();
SetColor();
totalScrollValue = 0;
@@ -23,10 +23,14 @@ public class QuickLoginUser : MonoBehaviour
{
if (user == null) return;
this.top = top;
#if !(UNITY_ANDROID || UNITY_IOS)
UIManager.AddEvent(gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) =>
{
goMain();
});
#else
gameObject.GetComponent<Button>().onClick.AddListener(() => { goMain(); });
#endif
//transform.GetComponent<Button>().onClick.AddListener();
this.user = user;
Utils.DisplayHead(transform.Find("Avatar").GetComponent<RawImage>(), user.Avatar);