H & V Scroll snap fixes to resolve #91

--HG--
branch : develop_5.3
pull/413/head
Simon Jackson 2016-07-21 17:25:34 +01:00
parent ee300b4079
commit 006ad7311f
2 changed files with 12 additions and 10 deletions

View File

@ -43,13 +43,14 @@ namespace UnityEngine.UI.Extensions
private Vector3 _startPosition = new Vector3(); private Vector3 _startPosition = new Vector3();
[Tooltip("The currently active page")] [Tooltip("The currently active page")]
[SerializeField]
private int _currentScreen; private int _currentScreen;
[Tooltip("The screen / page to start the control on")] [Tooltip("The screen / page to start the control on")]
[SerializeField]
public int StartingScreen = 1; public int StartingScreen = 1;
[Tooltip("The distance between two pages, by default 3 times the height of the control")] [Tooltip("The distance between two pages, by default 3 times the height of the control")]
[SerializeField]
public int PageStep = 0; public int PageStep = 0;
public int CurrentPage public int CurrentPage
@ -268,13 +269,13 @@ namespace UnityEngine.UI.Extensions
void OnValidate() void OnValidate()
{ {
var childCount = gameObject.GetComponent<ScrollRect>().content.childCount; var childCount = gameObject.GetComponent<ScrollRect>().content.childCount;
if (StartingScreen > childCount) if (StartingScreen > childCount - 1)
{ {
StartingScreen = childCount; StartingScreen = childCount - 1;
} }
if (StartingScreen < 1) if (StartingScreen < 0)
{ {
StartingScreen = 1; StartingScreen = 0;
} }
} }

View File

@ -42,13 +42,14 @@ namespace UnityEngine.UI.Extensions
private Vector3 _startPosition = new Vector3(); private Vector3 _startPosition = new Vector3();
[Tooltip("The currently active page")] [Tooltip("The currently active page")]
[SerializeField]
private int _currentScreen; private int _currentScreen;
[Tooltip("The screen / page to start the control on")] [Tooltip("The screen / page to start the control on")]
[SerializeField]
public int StartingScreen = 1; public int StartingScreen = 1;
[Tooltip("The distance between two pages, by default 3 times the width of the control")] [Tooltip("The distance between two pages, by default 3 times the width of the control")]
[SerializeField]
public int PageStep = 0; public int PageStep = 0;
public int CurrentPage public int CurrentPage
@ -266,13 +267,13 @@ namespace UnityEngine.UI.Extensions
void OnValidate() void OnValidate()
{ {
var childCount = gameObject.GetComponent<ScrollRect>().content.childCount; var childCount = gameObject.GetComponent<ScrollRect>().content.childCount;
if (StartingScreen > childCount) if (StartingScreen > childCount - 1)
{ {
StartingScreen = childCount; StartingScreen = childCount - 1;
} }
if (StartingScreen < 1) if (StartingScreen < 0)
{ {
StartingScreen = 1; StartingScreen = 0;
} }
} }