2 patches for HSS/VSS
* Added new overload to AddChild, allows to set WorldPositionStays for added childen * New RemoveAllChildren function --HG-- branch : develop_5.3release
parent
21ad76580e
commit
cd3f79ef7c
|
@ -92,9 +92,19 @@ namespace UnityEngine.UI.Extensions
|
|||
/// </summary>
|
||||
/// <param name="GO">GameObject to add to the ScrollSnap</param>
|
||||
public void AddChild(GameObject GO)
|
||||
{
|
||||
AddChild(GO, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new child to this Scroll Snap and recalculate it's children
|
||||
/// </summary>
|
||||
/// <param name="GO">GameObject to add to the ScrollSnap</param>
|
||||
/// <param name="WorldPositionStays">Should the world position be updated to it's parent transform?</param>
|
||||
public void AddChild(GameObject GO, bool WorldPositionStays)
|
||||
{
|
||||
_scroll_rect.horizontalNormalizedPosition = 0;
|
||||
GO.transform.SetParent(_screensContainer);
|
||||
GO.transform.SetParent(_screensContainer, WorldPositionStays);
|
||||
DistributePages();
|
||||
if (MaskArea) UpdateVisible();
|
||||
|
||||
|
@ -131,6 +141,28 @@ namespace UnityEngine.UI.Extensions
|
|||
SetScrollContainerPosition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all children from this ScrollSnap
|
||||
/// </summary>
|
||||
/// <param name="ChildrenRemoved"></param>
|
||||
public void RemoveAllChildren(out GameObject[] ChildrenRemoved)
|
||||
{
|
||||
var _screenCount = _screensContainer.childCount;
|
||||
ChildrenRemoved = new GameObject[_screenCount];
|
||||
|
||||
for (int i = _screenCount - 1; i >= 0; i--)
|
||||
{
|
||||
ChildrenRemoved[i] = _screensContainer.GetChild(i).gameObject;
|
||||
ChildrenRemoved[i].transform.SetParent(null);
|
||||
}
|
||||
|
||||
_scroll_rect.horizontalNormalizedPosition = 0;
|
||||
CurrentPage = 0;
|
||||
InitialiseChildObjectsFromScene();
|
||||
DistributePages();
|
||||
if (MaskArea) UpdateVisible();
|
||||
}
|
||||
|
||||
private void SetScrollContainerPosition()
|
||||
{
|
||||
_scrollStartPosition = _screensContainer.localPosition.x;
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
internal set
|
||||
{
|
||||
if (value != _currentPage && value >= 0 && value < _screensContainer.childCount)
|
||||
if ((value != _currentPage && value >= 0 && value < _screensContainer.childCount) || (value == 0 && _screensContainer.childCount == 0))
|
||||
{
|
||||
_previousPage = _currentPage;
|
||||
_currentPage = value;
|
||||
|
@ -190,7 +190,10 @@ namespace UnityEngine.UI.Extensions
|
|||
internal void UpdateVisible()
|
||||
{
|
||||
//If there are no objects in the scene or a mask, exit
|
||||
if (!MaskArea && (ChildObjects == null || ChildObjects.Length < 1 || _screensContainer.childCount < 1)) return;
|
||||
if (!MaskArea || ChildObjects == null || ChildObjects.Length < 1 || _screensContainer.childCount < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_maskSize = _isVertical ? MaskArea.rect.height : MaskArea.rect.width;
|
||||
_halfNoVisibleItems = (int)Math.Round(_maskSize / (_childSize * MaskBuffer), MidpointRounding.AwayFromZero) / 2;
|
||||
|
|
|
@ -87,9 +87,19 @@ namespace UnityEngine.UI.Extensions
|
|||
/// </summary>
|
||||
/// <param name="GO">GameObject to add to the ScrollSnap</param>
|
||||
public void AddChild(GameObject GO)
|
||||
{
|
||||
AddChild(GO, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new child to this Scroll Snap and recalculate it's children
|
||||
/// </summary>
|
||||
/// <param name="GO">GameObject to add to the ScrollSnap</param>
|
||||
/// <param name="WorldPositionStays">Should the world position be updated to it's parent transform?</param>
|
||||
public void AddChild(GameObject GO, bool WorldPositionStays)
|
||||
{
|
||||
_scroll_rect.verticalNormalizedPosition = 0;
|
||||
GO.transform.SetParent(_screensContainer);
|
||||
GO.transform.SetParent(_screensContainer, WorldPositionStays);
|
||||
InitialiseChildObjectsFromScene();
|
||||
DistributePages();
|
||||
if (MaskArea) UpdateVisible();
|
||||
|
@ -127,6 +137,28 @@ namespace UnityEngine.UI.Extensions
|
|||
SetScrollContainerPosition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all children from this ScrollSnap
|
||||
/// </summary>
|
||||
/// <param name="ChildrenRemoved"></param>
|
||||
public void RemoveAllChildren(out GameObject[] ChildrenRemoved)
|
||||
{
|
||||
var _screenCount = _screensContainer.childCount;
|
||||
ChildrenRemoved = new GameObject[_screenCount];
|
||||
|
||||
for (int i = _screenCount - 1; i >= 0; i--)
|
||||
{
|
||||
ChildrenRemoved[i] = _screensContainer.GetChild(i).gameObject;
|
||||
ChildrenRemoved[i].transform.SetParent(null);
|
||||
}
|
||||
|
||||
_scroll_rect.verticalNormalizedPosition = 0;
|
||||
CurrentPage = 0;
|
||||
InitialiseChildObjectsFromScene();
|
||||
DistributePages();
|
||||
if (MaskArea) UpdateVisible();
|
||||
}
|
||||
|
||||
private void SetScrollContainerPosition()
|
||||
{
|
||||
_scrollStartPosition = _screensContainer.localPosition.y;
|
||||
|
|
Loading…
Reference in New Issue