登录页一些特效,路书列表详情框架
This commit is contained in:
1 parent
326b74bd03
commit
996f924719
50 files changed
+19916
-6804
No files matched your search
@@ -10,15 +10,17 @@ public class ScrollTest2 : MonoBehaviour
|
||||
private ScrollRect scroll;
|
||||
private Transform content;
|
||||
private float contentSize;
|
||||
private int count;
|
||||
[SerializeField] Button L, R;
|
||||
void Start()
|
||||
{
|
||||
scroll = gameObject.GetComponent<ScrollRect>();
|
||||
content = gameObject.transform.Find("Viewport").Find("Content");
|
||||
|
||||
contentSize = 1f/(content.childCount-2);
|
||||
count = content.childCount;
|
||||
contentSize = 1f / (content.childCount - 2);
|
||||
scroll.horizontalNormalizedPosition = contentSize / 2;
|
||||
if (L != null)
|
||||
SetColor();
|
||||
if (L != null)
|
||||
{
|
||||
L.onClick.AddListener(goLeft);
|
||||
}
|
||||
@@ -30,36 +32,55 @@ public class ScrollTest2 : MonoBehaviour
|
||||
void goLeft()
|
||||
{
|
||||
if (scroll.horizontalNormalizedPosition <= contentSize) return;
|
||||
if (!start) startPosition = scroll.horizontalNormalizedPosition;
|
||||
start = true;
|
||||
scrollValue = -1 * contentSize / 30;
|
||||
}
|
||||
void goRight()
|
||||
{
|
||||
if ((scroll.horizontalNormalizedPosition + contentSize)>=1) return;
|
||||
if ((scroll.horizontalNormalizedPosition + contentSize) >= 1) return;
|
||||
if (!start) startPosition = scroll.horizontalNormalizedPosition;
|
||||
start = true;
|
||||
scrollValue = contentSize / 30;
|
||||
}
|
||||
private bool start = false, _lock = false;
|
||||
private float scrollValue = 0,totalScrollValue = 0;
|
||||
private float scrollValue = 0, totalScrollValue = 0, startPosition = 0;
|
||||
void SetColor()
|
||||
{
|
||||
int index = (int)System.Math.Round(
|
||||
(scroll.horizontalNormalizedPosition + (contentSize / 2)) / contentSize,
|
||||
0);
|
||||
for (int i = 1; i < content.childCount-1; i++)
|
||||
{
|
||||
string c = "#FFF";
|
||||
if (i == index)
|
||||
{
|
||||
c = "#FF2742";
|
||||
}
|
||||
ColorUtility.TryParseHtmlString(c, out Color color);
|
||||
content.GetChild(i).Find("Image").GetComponent<Image>().color = color;
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
scroll.horizontalNormalizedPosition = startPosition + totalScrollValue;
|
||||
//Debug.Log();
|
||||
|
||||
SetColor();
|
||||
totalScrollValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
scroll.horizontalNormalizedPosition += scrollValue;
|
||||
}
|
||||
_lock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user