Perfromance tweaks for H & V scroll snaps.

Updated create option
Matched Size options from HSS update in to VSS

--HG--
branch : develop_5.3
pull/413/head
Simon Jackson 2016-11-15 14:52:34 +00:00
parent cb535507a4
commit 2de76cf7a3
3 changed files with 1651 additions and 1649 deletions

View File

@ -322,7 +322,7 @@ namespace UnityEditor.UI
rectTransformPage01.anchoredPosition = new Vector2(-rectTransformPage01.sizeDelta.x / 2, rectTransformPage01.sizeDelta.y / 2); rectTransformPage01.anchoredPosition = new Vector2(-rectTransformPage01.sizeDelta.x / 2, rectTransformPage01.sizeDelta.y / 2);
//rectTransformPage01.anchoredPosition = Vector2.zero; //rectTransformPage01.anchoredPosition = Vector2.zero;
//rectTransformPage01.sizeDelta = Vector2.zero; //rectTransformPage01.sizeDelta = Vector2.zero;
rectTransformPage01.pivot = new Vector2(0f, 0.5f); rectTransformPage01.pivot = new Vector2(0.5f, 0f);
//Setup Text on Page01 //Setup Text on Page01
Text text = childText.AddComponent<Text>(); Text text = childText.AddComponent<Text>();

View File

@ -49,9 +49,10 @@ namespace UnityEngine.UI.Extensions
[SerializeField] [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 based on page height, by default 3 times the width of the control")]
[SerializeField] [SerializeField]
public int PageStep = 0; [Range(0, 8)]
public float PageStep = 0;
public int CurrentPage public int CurrentPage
{ {
@ -74,10 +75,7 @@ namespace UnityEngine.UI.Extensions
} }
_screensContainer = _scroll_rect.content; _screensContainer = _scroll_rect.content;
if (PageStep == 0)
{
PageStep = (int)_scroll_rect.GetComponent<RectTransform>().rect.width * PageStep;
}
DistributePages(); DistributePages();
_lerp = false; _lerp = false;
@ -229,14 +227,16 @@ namespace UnityEngine.UI.Extensions
private void DistributePages() private void DistributePages()
{ {
int _offset = 0; int _offset = 0;
int _dimension = 0; float _dimension = 0;
Rect panelDimensions = gameObject.GetComponent<RectTransform>().rect; Rect panelDimensions = gameObject.GetComponent<RectTransform>().rect;
int currentXPosition = 0; float currentXPosition = 0;
var pageStepValue = (int)panelDimensions.width * ((PageStep == 0) ? 3 : PageStep);
for (int i = 0; i < _screensContainer.transform.childCount; i++) for (int i = 0; i < _screensContainer.transform.childCount; i++)
{ {
RectTransform child = _screensContainer.transform.GetChild(i).gameObject.GetComponent<RectTransform>(); RectTransform child = _screensContainer.transform.GetChild(i).gameObject.GetComponent<RectTransform>();
currentXPosition = _offset + (int)(i * PageStep); currentXPosition = _offset + (int)(i * pageStepValue);
child.sizeDelta = new Vector2(panelDimensions.width, panelDimensions.height); child.sizeDelta = new Vector2(panelDimensions.width, panelDimensions.height);
child.anchoredPosition = new Vector2(currentXPosition, 0f); child.anchoredPosition = new Vector2(currentXPosition, 0f);
child.anchorMin = new Vector2(0f, child.anchorMin.y); child.anchorMin = new Vector2(0f, child.anchorMin.y);

View File

@ -48,9 +48,10 @@ namespace UnityEngine.UI.Extensions
[SerializeField] [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 based on page height, by default 3 times the width of the control")]
[SerializeField] [SerializeField]
public int PageStep = 0; [Range(0, 8)]
public float PageStep = 0;
public int CurrentPage public int CurrentPage
{ {
@ -71,10 +72,7 @@ namespace UnityEngine.UI.Extensions
} }
_screensContainer = _scroll_rect.content; _screensContainer = _scroll_rect.content;
if (PageStep == 0)
{
PageStep = (int)_scroll_rect.GetComponent<RectTransform>().rect.height * 3;
}
DistributePages(); DistributePages();
_lerp = false; _lerp = false;
@ -228,15 +226,19 @@ namespace UnityEngine.UI.Extensions
{ {
float _offset = 0; float _offset = 0;
float _dimension = 0; float _dimension = 0;
Vector2 panelDimensions = gameObject.GetComponent<RectTransform>().sizeDelta; Rect panelDimensions = gameObject.GetComponent<RectTransform>().rect;
float currentYPosition = 0; float currentYPosition = 0;
var pageStepValue = (int)panelDimensions.height * ((PageStep == 0) ? 3 : PageStep);
for (int i = 0; i < _screensContainer.transform.childCount; i++) for (int i = 0; i < _screensContainer.transform.childCount; i++)
{ {
RectTransform child = _screensContainer.transform.GetChild(i).gameObject.GetComponent<RectTransform>(); RectTransform child = _screensContainer.transform.GetChild(i).gameObject.GetComponent<RectTransform>();
currentYPosition = _offset + i * PageStep; currentYPosition = _offset + i * pageStepValue;
child.sizeDelta = new Vector2(panelDimensions.x, panelDimensions.y); child.sizeDelta = new Vector2(panelDimensions.width, panelDimensions.height);
child.anchoredPosition = new Vector2(0f - panelDimensions.x / 2, currentYPosition + panelDimensions.y / 2); child.anchoredPosition = new Vector2(0f, currentYPosition);
child.anchorMin = new Vector2(child.anchorMin.x, 0f);
child.anchorMax = new Vector2(child.anchorMax.x, 0f);
child.pivot = new Vector2(child.pivot.x, 0f);
} }
_dimension = currentYPosition + _offset * -1; _dimension = currentYPosition + _offset * -1;