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(); 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)
{
if (i == index)
{
child.SetParent(null); child.SetParent(null);
ChildRemoved = child.gameObject; 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,20 +116,23 @@ 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();
}
if (NextButton)
NextButton.GetComponent<Button>().onClick.AddListener(() => { NextScreen(); });
if (PrevButton)
PrevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); });
}
internal void InitialiseChildObjectsFromScene()
{
int childCount = _screensContainer.childCount;
ChildObjects = new GameObject[childCount]; ChildObjects = new GameObject[childCount];
for (int i = 0; i < childCount; i++) for (int i = 0; i < childCount; i++)
{ {
@ -142,11 +144,18 @@ namespace UnityEngine.UI.Extensions
} }
} }
if (NextButton) internal void InitialiseChildObjectsFromArray()
NextButton.GetComponent<Button>().onClick.AddListener(() => { NextScreen(); }); {
int childCount = ChildObjects.Length;
if (PrevButton) for (int i = 0; i < childCount; i++)
PrevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); }); {
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()
@ -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)
{
if (i == index)
{
child.SetParent(null); child.SetParent(null);
ChildRemoved = child.gameObject; ChildRemoved = child.gameObject;
break; InitialiseChildObjectsFromScene();
}
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>