-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopVerticalScrollRect.cs
More file actions
98 lines (91 loc) · 3.24 KB
/
LoopVerticalScrollRect.cs
File metadata and controls
98 lines (91 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
namespace UnityEngine.UI
{
[AddComponentMenu("UI/Loop Vertical Scroll Rect", 51)]
[DisallowMultipleComponent]
public class LoopVerticalScrollRect : LoopScrollRect
{
protected override float GetSize(RectTransform item)
{
float size = contentSpacing;
if (m_GridLayout != null)
{
size += m_GridLayout.cellSize.y;
}
else
{
size += LayoutUtility.GetPreferredHeight(item);
}
return size;
}
protected override float GetDimension(Vector2 vector)
{
return vector.y;
}
protected override Vector2 GetVector(float value)
{
return new Vector2(0, value);
}
protected override void Awake()
{
base.Awake();
directionSign = -1;
GridLayoutGroup layout = content.GetComponent<GridLayoutGroup>();
if (layout != null && layout.constraint != GridLayoutGroup.Constraint.FixedColumnCount)
{
Debug.LogError("[LoopHorizontalScrollRect] unsupported GridLayoutGroup constraint");
}
}
protected override bool UpdateItems(Bounds viewBounds, Bounds contentBounds)
{
bool changed = false;
if (viewBounds.min.y < contentBounds.min.y)
{
float size = NewItemAtEnd(), totalSize = size;
while(size > 0 && viewBounds.min.y < contentBounds.min.y - totalSize)
{
size = NewItemAtEnd();
totalSize += size;
}
if (totalSize > 0)
changed = true;
}
else if (viewBounds.min.y > contentBounds.min.y + threshold)
{
float size = DeleteItemAtEnd(), totalSize = size;
while (size > 0 && viewBounds.min.y > contentBounds.min.y + threshold + totalSize)
{
size = DeleteItemAtEnd();
totalSize += size;
}
if (totalSize > 0)
changed = true;
}
if (viewBounds.max.y > contentBounds.max.y)
{
float size = NewItemAtStart(), totalSize = size;
while (size > 0 && viewBounds.max.y > contentBounds.max.y + totalSize)
{
size = NewItemAtStart();
totalSize += size;
}
if (totalSize > 0)
changed = true;
}
else if (viewBounds.max.y < contentBounds.max.y - threshold)
{
float size = DeleteItemAtStart(), totalSize = size;
while (size > 0 && viewBounds.max.y < contentBounds.max.y - threshold - totalSize)
{
size = DeleteItemAtStart();
totalSize += size;
}
if (totalSize > 0)
changed = true;
}
return changed;
}
}
}