Updated Scroll Snap Base to resolve #119
parent
48e162ebde
commit
cc7c66f9f5
|
@ -40,7 +40,7 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
[Tooltip("The distance between two pages based on page height, by default pages are next to each other")]
|
||||
[SerializeField]
|
||||
[Range(1, 8)]
|
||||
[Range(0, 8)]
|
||||
public float PageStep = 1;
|
||||
|
||||
[Tooltip("The gameobject that contains toggles which suggest pagination. (optional)")]
|
||||
|
@ -76,6 +76,7 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
return _currentPage;
|
||||
}
|
||||
|
||||
internal set
|
||||
{
|
||||
if ((value != _currentPage && value >= 0 && value < _screensContainer.childCount) || (value == 0 && _screensContainer.childCount == 0))
|
||||
|
@ -110,7 +111,6 @@ namespace UnityEngine.UI.Extensions
|
|||
private SelectionChangeEndEvent m_OnSelectionChangeEndEvent = new SelectionChangeEndEvent();
|
||||
public SelectionChangeEndEvent OnSelectionChangeEndEvent { get { return m_OnSelectionChangeEndEvent; } set { m_OnSelectionChangeEndEvent = value; } }
|
||||
|
||||
|
||||
// Use this for initialization
|
||||
void Awake()
|
||||
{
|
||||
|
@ -134,6 +134,7 @@ namespace UnityEngine.UI.Extensions
|
|||
Debug.LogError("ScrollRect Content has children, this is not supported when using managed Child Objects\n Either remove the ScrollRect Content children or clear the ChildObjects array");
|
||||
return;
|
||||
}
|
||||
|
||||
InitialiseChildObjectsFromArray();
|
||||
}
|
||||
else
|
||||
|
@ -178,6 +179,7 @@ namespace UnityEngine.UI.Extensions
|
|||
childRect.localScale = _screensContainer.localScale;
|
||||
childRect.position = _screensContainer.position;
|
||||
}
|
||||
|
||||
child.transform.SetParent(_screensContainer.transform);
|
||||
ChildObjects[i] = child;
|
||||
if (MaskArea && ChildObjects[i].activeSelf)
|
||||
|
@ -199,17 +201,19 @@ namespace UnityEngine.UI.Extensions
|
|||
_halfNoVisibleItems = (int)Math.Round(_maskSize / (_childSize * MaskBuffer), MidpointRounding.AwayFromZero) / 2;
|
||||
_bottomItem = _topItem = 0;
|
||||
//work out how many items below the current page can be visible
|
||||
for (int i = _halfNoVisibleItems + 1; i > 0 ; i--)
|
||||
for (int i = _halfNoVisibleItems + 1; i > 0; i--)
|
||||
{
|
||||
_bottomItem = _currentPage - i < 0 ? 0 : i;
|
||||
if (_bottomItem > 0) break;
|
||||
}
|
||||
|
||||
//work out how many items above the current page can be visible
|
||||
for (int i = _halfNoVisibleItems + 1; i > 0; i--)
|
||||
{
|
||||
_topItem = _screensContainer.childCount - _currentPage - i < 0 ? 0 : i;
|
||||
if (_topItem > 0) break;
|
||||
}
|
||||
|
||||
//Set the active items active
|
||||
for (int i = CurrentPage - _bottomItem; i < CurrentPage + _topItem; i++)
|
||||
{
|
||||
|
@ -229,7 +233,6 @@ namespace UnityEngine.UI.Extensions
|
|||
if (_screensContainer.childCount - _currentPage > _topItem) ChildObjects[CurrentPage + _topItem].SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
//Function for switching screens with buttons
|
||||
public void NextScreen()
|
||||
{
|
||||
|
@ -361,6 +364,7 @@ namespace UnityEngine.UI.Extensions
|
|||
if (PrevButton) {
|
||||
PrevButton.GetComponent<Button>().interactable = targetScreen > 0;
|
||||
}
|
||||
|
||||
if (NextButton) {
|
||||
NextButton.GetComponent<Button>().interactable = targetScreen < _screensContainer.transform.childCount - 1;
|
||||
}
|
||||
|
@ -376,19 +380,23 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
StartingScreen = childCount - 1;
|
||||
}
|
||||
|
||||
if (StartingScreen < 0)
|
||||
{
|
||||
StartingScreen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (MaskBuffer <= 0)
|
||||
{
|
||||
MaskBuffer = 1;
|
||||
}
|
||||
|
||||
if (PageStep < 0)
|
||||
{
|
||||
PageStep = 0;
|
||||
}
|
||||
|
||||
if (PageStep > 8)
|
||||
{
|
||||
PageStep = 9;
|
||||
|
@ -443,5 +451,5 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue