Remaining issues resolved.

Now to double check YT and BB for any remaining unresolved issues

--HG--
branch : develop_5.3
pull/413/head
Simon Jackson 2016-12-21 17:51:38 +00:00
parent a72c45e02a
commit 94f857d203
3 changed files with 61 additions and 53 deletions

View File

@ -18,8 +18,7 @@ namespace UnityEngine.UI.Extensions
if(MaskArea) CalculateVisible();
_lerp = false;
_currentPage = StartingScreen - 1;
_scrollStartPosition = _screensContainer.localPosition.x;
_scroll_rect.horizontalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
SetScrollContainerPosition();
}
void Update()
@ -89,8 +88,9 @@ namespace UnityEngine.UI.Extensions
_scroll_rect.horizontalNormalizedPosition = 0;
GO.transform.SetParent(_screensContainer);
DistributePages();
if (MaskArea) UpdateVisible();
_scroll_rect.horizontalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
SetScrollContainerPosition();
}
/// <summary>
@ -107,26 +107,25 @@ namespace UnityEngine.UI.Extensions
return;
}
_scroll_rect.horizontalNormalizedPosition = 0;
var children = _screensContainer.transform;
int i = 0;
foreach (Transform child in children)
{
if (i == index)
{
child.SetParent(null);
ChildRemoved = child.gameObject;
break;
}
i++;
}
Transform child = _screensContainer.transform.GetChild(index);
child.SetParent(null);
ChildRemoved = child.gameObject;
DistributePages();
if (MaskArea) UpdateVisible();
if (_currentPage > _screens - 1)
{
CurrentPage = _screens - 1;
}
SetScrollContainerPosition();
}
private void SetScrollContainerPosition()
{
_scrollStartPosition = _screensContainer.localPosition.x;
_scroll_rect.horizontalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
}

View File

@ -109,7 +109,6 @@ namespace UnityEngine.UI.Extensions
}
_screensContainer = _scroll_rect.content;
int childCount;
if (ChildObjects != null && ChildObjects.Length > 0)
{
if (_screensContainer.transform.childCount > 0)
@ -117,29 +116,11 @@ 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;
}
childCount = ChildObjects.Length;
for (int i = 0; i < childCount; i++)
{
ChildObjects[i] = GameObject.Instantiate(ChildObjects[i]);
ChildObjects[i].transform.SetParent(_screensContainer.transform);
if (MaskArea && ChildObjects[i].activeSelf)
{
ChildObjects[i].SetActive(false);
}
}
InitialiseChildObjectsFromArray();
}
else
{
childCount = ChildObjects.Length;
ChildObjects = new GameObject[childCount];
for (int i = 0; i < childCount; i++)
{
ChildObjects[i] = _screensContainer.transform.GetChild(i).gameObject;
if (MaskArea && ChildObjects[i].activeSelf)
{
ChildObjects[i].SetActive(false);
}
}
InitialiseChildObjectsFromScene();
}
if (NextButton)
@ -149,6 +130,34 @@ namespace UnityEngine.UI.Extensions
PrevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); });
}
internal void InitialiseChildObjectsFromScene()
{
int childCount = _screensContainer.childCount;
ChildObjects = new GameObject[childCount];
for (int i = 0; i < childCount; i++)
{
ChildObjects[i] = _screensContainer.transform.GetChild(i).gameObject;
if (MaskArea && ChildObjects[i].activeSelf)
{
ChildObjects[i].SetActive(false);
}
}
}
internal void InitialiseChildObjectsFromArray()
{
int childCount = ChildObjects.Length;
for (int i = 0; i < childCount; i++)
{
ChildObjects[i] = GameObject.Instantiate(ChildObjects[i]);
ChildObjects[i].transform.SetParent(_screensContainer.transform);
if (MaskArea && ChildObjects[i].activeSelf)
{
ChildObjects[i].SetActive(false);
}
}
}
internal void CalculateVisible()
{
float MaskSize = isVertical ? MaskArea.rect.height : MaskArea.rect.width;
@ -161,7 +170,7 @@ namespace UnityEngine.UI.Extensions
}
}
void UpdateVisible()
internal void UpdateVisible()
{
int BottomItem = _currentPage - HalfNoVisibleItems < 0 ? 0 : HalfNoVisibleItems;
int TopItem = _screensContainer.childCount - _currentPage < HalfNoVisibleItems ? _screensContainer.childCount - _currentPage : HalfNoVisibleItems;

View File

@ -18,8 +18,7 @@ namespace UnityEngine.UI.Extensions
if(MaskArea) CalculateVisible();
_lerp = false;
_currentPage = StartingScreen - 1;
_scrollStartPosition = _screensContainer.localPosition.y;
_scroll_rect.verticalNormalizedPosition = (float)(_currentPage) / (float)(_screens - 1);
SetScrollContainerPosition();
}
void Update()
@ -88,9 +87,11 @@ namespace UnityEngine.UI.Extensions
{
_scroll_rect.verticalNormalizedPosition = 0;
GO.transform.SetParent(_screensContainer);
InitialiseChildObjectsFromScene();
DistributePages();
if (MaskArea) UpdateVisible();
_scroll_rect.verticalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
SetScrollContainerPosition();
}
/// <summary>
@ -107,28 +108,27 @@ namespace UnityEngine.UI.Extensions
return;
}
_scroll_rect.verticalNormalizedPosition = 0;
var children = _screensContainer.transform;
int i = 0;
foreach (Transform child in children)
{
if (i == index)
{
child.SetParent(null);
ChildRemoved = child.gameObject;
break;
}
i++;
}
Transform child = _screensContainer.transform.GetChild(index);
child.SetParent(null);
ChildRemoved = child.gameObject;
InitialiseChildObjectsFromScene();
DistributePages();
if (MaskArea) UpdateVisible();
if (_currentPage > _screens - 1)
{
CurrentPage = _screens - 1;
}
_scroll_rect.verticalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
SetScrollContainerPosition();
}
private void SetScrollContainerPosition()
{
_scrollStartPosition = _screensContainer.localPosition.y;
_scroll_rect.verticalNormalizedPosition = (float)(_currentPage) / (_screens - 1);
}
#region Interfaces
/// <summary>