132 lines
4.3 KiB
C#
132 lines
4.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
|
|
namespace BF
|
|
{
|
|
[DisallowMultipleComponent]
|
|
public class HorizontalScrollRectOld : ScrollRectBaseOld
|
|
{
|
|
protected override float GetSize(RectTransform item)
|
|
{
|
|
float size = ContentSpacing;
|
|
if (gridLayout != null)
|
|
{
|
|
size += gridLayout.cellSize.x;
|
|
}
|
|
else
|
|
{
|
|
size += LayoutUtility.GetPreferredWidth(item);
|
|
}
|
|
return size;
|
|
}
|
|
|
|
protected override float GetDimension(Vector2 vector)
|
|
{
|
|
return -vector.x;
|
|
}
|
|
|
|
protected override Vector2 GetVector(float value)
|
|
{
|
|
return new Vector2(-value, 0);
|
|
}
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
directionSign = 1;
|
|
|
|
GridLayoutGroup layout = content.GetComponent<GridLayoutGroup>();
|
|
if (layout != null && layout.constraint != GridLayoutGroup.Constraint.FixedRowCount)
|
|
{
|
|
Debug.LogError("[HorizontalScrollRect] unsupported GridLayoutGroup constraint");
|
|
}
|
|
}
|
|
|
|
protected override bool UpdateItems(Bounds viewBounds, Bounds contentBounds)
|
|
{
|
|
bool changed = false;
|
|
if (viewBounds.max.x > contentBounds.max.x)
|
|
{
|
|
float size = NewItemAtEnd(), totalSize = size;
|
|
while (size > 0 && viewBounds.max.x > contentBounds.max.x + totalSize)
|
|
{
|
|
size = NewItemAtEnd();
|
|
totalSize += size;
|
|
}
|
|
if (totalSize > 0)
|
|
changed = true;
|
|
}
|
|
else if (viewBounds.max.x < contentBounds.max.x - endThreshold)
|
|
{
|
|
float size = DeleteItemAtEnd(), totalSize = size;
|
|
while (size > 0 && viewBounds.max.x < contentBounds.max.x - endThreshold - totalSize)
|
|
{
|
|
size = DeleteItemAtEnd();
|
|
totalSize += size;
|
|
}
|
|
if (totalSize > 0)
|
|
changed = true;
|
|
}
|
|
|
|
if (viewBounds.min.x < contentBounds.min.x)
|
|
{
|
|
float size = NewItemAtStart(), totalSize = size;
|
|
while (size > 0 && viewBounds.min.x < contentBounds.min.x - totalSize)
|
|
{
|
|
size = NewItemAtStart();
|
|
totalSize += size;
|
|
}
|
|
if (totalSize > 0)
|
|
changed = true;
|
|
}
|
|
else if (viewBounds.min.x > contentBounds.min.x + startThreshold)
|
|
{
|
|
float size = DeleteItemAtStart(), totalSize = size;
|
|
while (size > 0 && viewBounds.min.x > contentBounds.min.x + startThreshold + totalSize)
|
|
{
|
|
size = DeleteItemAtStart();
|
|
totalSize += size;
|
|
}
|
|
if (totalSize > 0)
|
|
changed = true;
|
|
}
|
|
return changed;
|
|
}
|
|
|
|
public override void RefreshRealShowIndex()
|
|
{
|
|
base.RefreshRealShowIndex();
|
|
Bounds viewBounds = new Bounds(viewport.rect.center, viewport.rect.size);
|
|
for (int i = content.childCount - 1; i >= 0; i--)
|
|
{
|
|
var gameObject = content.GetChild(i).gameObject;
|
|
if (!gameObject.activeSelf)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
Bounds bounds = GetCellBounds(i);
|
|
if (bounds.min.x > viewBounds.max.x)
|
|
{
|
|
CellObj cell = GetCell(gameObject);
|
|
int index = cell.index;
|
|
if (index > curBottomIndex)
|
|
curBottomIndex = index;
|
|
}
|
|
if (bounds.max.x < viewBounds.min.x)
|
|
{
|
|
CellObj cell = GetCell(gameObject);
|
|
int index = cell.index;
|
|
if (index < curTopIndex)
|
|
curTopIndex = index;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool IsNotFull()
|
|
{
|
|
return content.rect.width < viewport.rect.width || (cellEndIndex - cellStartIndex) % ContentConstraintCount > 0;
|
|
}
|
|
}
|
|
} |