WorldPositionStays argument added to:
* RemoveChild
* RemoveAllChildren

For HSS/VSS ScrollSnaps
pull/413/head
Simon Jackson 2017-07-02 14:33:57 +01:00
parent 439242d914
commit f49c8564ac
2 changed files with 55 additions and 10 deletions

View File

@ -118,9 +118,21 @@ namespace UnityEngine.UI.Extensions
/// Remove a new child to this Scroll Snap and recalculate it's children /// Remove a new child to this Scroll Snap and recalculate it's children
/// *Note, this is an index address (0-x) /// *Note, this is an index address (0-x)
/// </summary> /// </summary>
/// <param name="index"></param> /// <param name="index">Index element of child to remove</param>
/// <param name="ChildRemoved"></param> /// <param name="ChildRemoved">Resulting removed GO</param>
public void RemoveChild(int index, out GameObject ChildRemoved) public void RemoveChild(int index, out GameObject ChildRemoved)
{
RemoveChild(index, false, out ChildRemoved);
}
/// <summary>
/// Remove a new child to this Scroll Snap and recalculate it's children
/// *Note, this is an index address (0-x)
/// </summary>
/// <param name="index">Index element of child to remove</param>
/// <param name="WorldPositionStays">If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before</param>
/// <param name="ChildRemoved">Resulting removed GO</param>
public void RemoveChild(int index, bool WorldPositionStays, out GameObject ChildRemoved)
{ {
ChildRemoved = null; ChildRemoved = null;
if (index < 0 || index > _screensContainer.childCount) if (index < 0 || index > _screensContainer.childCount)
@ -130,7 +142,7 @@ namespace UnityEngine.UI.Extensions
_scroll_rect.horizontalNormalizedPosition = 0; _scroll_rect.horizontalNormalizedPosition = 0;
Transform child = _screensContainer.transform.GetChild(index); Transform child = _screensContainer.transform.GetChild(index);
child.SetParent(null); child.SetParent(null, WorldPositionStays);
ChildRemoved = child.gameObject; ChildRemoved = child.gameObject;
DistributePages(); DistributePages();
@ -147,8 +159,18 @@ namespace UnityEngine.UI.Extensions
/// <summary> /// <summary>
/// Remove all children from this ScrollSnap /// Remove all children from this ScrollSnap
/// </summary> /// </summary>
/// <param name="ChildrenRemoved"></param> /// <param name="ChildrenRemoved">Array of child GO's removed</param>
public void RemoveAllChildren(out GameObject[] ChildrenRemoved) public void RemoveAllChildren(out GameObject[] ChildrenRemoved)
{
RemoveAllChildren(false, out ChildrenRemoved);
}
/// <summary>
/// Remove all children from this ScrollSnap
/// </summary>
/// <param name="WorldPositionStays">If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before</param>
/// <param name="ChildrenRemoved">Array of child GO's removed</param>
public void RemoveAllChildren(bool WorldPositionStays, out GameObject[] ChildrenRemoved)
{ {
var _screenCount = _screensContainer.childCount; var _screenCount = _screensContainer.childCount;
ChildrenRemoved = new GameObject[_screenCount]; ChildrenRemoved = new GameObject[_screenCount];
@ -156,7 +178,7 @@ namespace UnityEngine.UI.Extensions
for (int i = _screenCount - 1; i >= 0; i--) for (int i = _screenCount - 1; i >= 0; i--)
{ {
ChildrenRemoved[i] = _screensContainer.GetChild(i).gameObject; ChildrenRemoved[i] = _screensContainer.GetChild(i).gameObject;
ChildrenRemoved[i].transform.SetParent(null); ChildrenRemoved[i].transform.SetParent(null, WorldPositionStays);
} }
_scroll_rect.horizontalNormalizedPosition = 0; _scroll_rect.horizontalNormalizedPosition = 0;

View File

@ -119,9 +119,21 @@ namespace UnityEngine.UI.Extensions
/// Remove a new child to this Scroll Snap and recalculate it's children /// Remove a new child to this Scroll Snap and recalculate it's children
/// *Note, this is an index address (0-x) /// *Note, this is an index address (0-x)
/// </summary> /// </summary>
/// <param name="index"></param> /// <param name="index">Index element of child to remove</param>
/// <param name="ChildRemoved"></param> /// <param name="ChildRemoved">>Resulting removed GO</param>
public void RemoveChild(int index, out GameObject ChildRemoved) public void RemoveChild(int index, out GameObject ChildRemoved)
{
RemoveChild(index, false, out ChildRemoved);
}
/// <summary>
/// Remove a new child to this Scroll Snap and recalculate it's children
/// *Note, this is an index address (0-x)
/// </summary>
/// <param name="index">Index element of child to remove</param>
/// <param name="WorldPositionStays">If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before</param>
/// <param name="ChildRemoved">Resulting removed GO</param>
public void RemoveChild(int index, bool WorldPositionStays, out GameObject ChildRemoved)
{ {
ChildRemoved = null; ChildRemoved = null;
if (index < 0 || index > _screensContainer.childCount) if (index < 0 || index > _screensContainer.childCount)
@ -131,7 +143,7 @@ namespace UnityEngine.UI.Extensions
_scroll_rect.verticalNormalizedPosition = 0; _scroll_rect.verticalNormalizedPosition = 0;
Transform child = _screensContainer.transform.GetChild(index); Transform child = _screensContainer.transform.GetChild(index);
child.SetParent(null); child.SetParent(null, WorldPositionStays);
ChildRemoved = child.gameObject; ChildRemoved = child.gameObject;
InitialiseChildObjectsFromScene(); InitialiseChildObjectsFromScene();
DistributePages(); DistributePages();
@ -145,11 +157,22 @@ namespace UnityEngine.UI.Extensions
SetScrollContainerPosition(); SetScrollContainerPosition();
} }
/// <summary> /// <summary>
/// Remove all children from this ScrollSnap /// Remove all children from this ScrollSnap
/// </summary> /// </summary>
/// <param name="ChildrenRemoved"></param> /// <param name="ChildrenRemoved">Array of child GO's removed</param>
public void RemoveAllChildren(out GameObject[] ChildrenRemoved) public void RemoveAllChildren(out GameObject[] ChildrenRemoved)
{
RemoveAllChildren(false, out ChildrenRemoved);
}
/// <summary>
/// Remove all children from this ScrollSnap
/// </summary>
/// <param name="WorldPositionStays">If true, the parent-relative position, scale and rotation are modified such that the object keeps the same world space position, rotation and scale as before</param>
/// <param name="ChildrenRemoved">Array of child GO's removed</param>
public void RemoveAllChildren(bool WorldPositionStays, out GameObject[] ChildrenRemoved)
{ {
var _screenCount = _screensContainer.childCount; var _screenCount = _screensContainer.childCount;
ChildrenRemoved = new GameObject[_screenCount]; ChildrenRemoved = new GameObject[_screenCount];
@ -157,7 +180,7 @@ namespace UnityEngine.UI.Extensions
for (int i = _screenCount - 1; i >= 0; i--) for (int i = _screenCount - 1; i >= 0; i--)
{ {
ChildrenRemoved[i] = _screensContainer.GetChild(i).gameObject; ChildrenRemoved[i] = _screensContainer.GetChild(i).gameObject;
ChildrenRemoved[i].transform.SetParent(null); ChildrenRemoved[i].transform.SetParent(null, WorldPositionStays);
} }
_scroll_rect.verticalNormalizedPosition = 0; _scroll_rect.verticalNormalizedPosition = 0;