Remaining issues resolved.

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

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

View File

@ -109,7 +109,6 @@ namespace UnityEngine.UI.Extensions
} }
_screensContainer = _scroll_rect.content; _screensContainer = _scroll_rect.content;
int childCount;
if (ChildObjects != null && ChildObjects.Length > 0) if (ChildObjects != null && ChildObjects.Length > 0)
{ {
if (_screensContainer.transform.childCount > 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"); 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; return;
} }
childCount = ChildObjects.Length; InitialiseChildObjectsFromArray();
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);
}
}
} }
else else
{ {
childCount = ChildObjects.Length; InitialiseChildObjectsFromScene();
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);
}
}
} }
if (NextButton) if (NextButton)
@ -149,6 +130,34 @@ namespace UnityEngine.UI.Extensions
PrevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); }); 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() internal void CalculateVisible()
{ {
float MaskSize = isVertical ? MaskArea.rect.height : MaskArea.rect.width; 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 BottomItem = _currentPage - HalfNoVisibleItems < 0 ? 0 : HalfNoVisibleItems;
int TopItem = _screensContainer.childCount - _currentPage < HalfNoVisibleItems ? _screensContainer.childCount - _currentPage : HalfNoVisibleItems; int TopItem = _screensContainer.childCount - _currentPage < HalfNoVisibleItems ? _screensContainer.childCount - _currentPage : HalfNoVisibleItems;

View File

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