This commit is contained in:
Caiyanpeng committed 2021-03-29 09:19:48 +08:00
1 parent e7044b3cde
commit cbc79df8a2
72 files changed
+15352 -444

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.UI;
public class ScrollTest : MonoBehaviour
{
// Start is called before the first frame update
private ScrollRect scroll;
void Start()
{
scroll = gameObject.GetComponent<ScrollRect>();
}
private bool dir = true;
// Update is called once per frame
void Update()
{
if (dir)
{
scroll.horizontalNormalizedPosition += 0.01f;
if (scroll.horizontalNormalizedPosition >= 1)
{
dir = false;
}
}
else
{
scroll.horizontalNormalizedPosition -= 0.01f;
if (scroll.horizontalNormalizedPosition <= 0)
{
dir = true;
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6adf1f0c1d929374aac00f3a6a2445bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+65
View File
@@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.UI;
public class ScrollTest2 : MonoBehaviour
{
// Start is called before the first frame update
private ScrollRect scroll;
private Transform content;
private float contentSize;
[SerializeField] Button L, R;
void Start()
{
scroll = gameObject.GetComponent<ScrollRect>();
content = gameObject.transform.Find("Viewport").Find("Content");
contentSize = 1f/(content.childCount-2);
scroll.horizontalNormalizedPosition = contentSize / 2;
if (L != null)
{
L.onClick.AddListener(goLeft);
}
if (R != null)
{
R.onClick.AddListener(goRight);
}
}
void goLeft()
{
if (scroll.horizontalNormalizedPosition <= contentSize) return;
start = true;
scrollValue = -1 * contentSize / 30;
}
void goRight()
{
if ((scroll.horizontalNormalizedPosition + contentSize)>=1) return;
start = true;
scrollValue = contentSize / 30;
}
private bool start = false, _lock = false;
private float scrollValue = 0,totalScrollValue = 0;
// Update is called once per frame
void Update()
{
if (start)
{
if (_lock) return;
_lock = true;
totalScrollValue += scrollValue;
if (System.Math.Abs(totalScrollValue) >= contentSize)
{
scrollValue = 0;
start = false;
totalScrollValue = 0;
}
else
{
scroll.horizontalNormalizedPosition += scrollValue;
}
_lock = false;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a77e784c857a15f4593d004821ce2757
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: