From f49c8564ac8bddcdd2be9d3152ef7283a2f7f7f4 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 2 Jul 2017 14:33:57 +0100 Subject: [PATCH] Resolves #137 WorldPositionStays argument added to: * RemoveChild * RemoveAllChildren For HSS/VSS ScrollSnaps --- Scripts/Layout/HorizontalScrollSnap.cs | 32 +++++++++++++++++++++---- Scripts/Layout/VerticalScrollSnap.cs | 33 ++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/Scripts/Layout/HorizontalScrollSnap.cs b/Scripts/Layout/HorizontalScrollSnap.cs index 5300d33..a63900e 100644 --- a/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Scripts/Layout/HorizontalScrollSnap.cs @@ -118,9 +118,21 @@ namespace UnityEngine.UI.Extensions /// Remove a new child to this Scroll Snap and recalculate it's children /// *Note, this is an index address (0-x) /// - /// - /// + /// Index element of child to remove + /// Resulting removed GO public void RemoveChild(int index, out GameObject ChildRemoved) + { + RemoveChild(index, false, out ChildRemoved); + } + + /// + /// Remove a new child to this Scroll Snap and recalculate it's children + /// *Note, this is an index address (0-x) + /// + /// Index element of child to remove + /// 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 + /// Resulting removed GO + public void RemoveChild(int index, bool WorldPositionStays, out GameObject ChildRemoved) { ChildRemoved = null; if (index < 0 || index > _screensContainer.childCount) @@ -130,7 +142,7 @@ namespace UnityEngine.UI.Extensions _scroll_rect.horizontalNormalizedPosition = 0; Transform child = _screensContainer.transform.GetChild(index); - child.SetParent(null); + child.SetParent(null, WorldPositionStays); ChildRemoved = child.gameObject; DistributePages(); @@ -147,8 +159,18 @@ namespace UnityEngine.UI.Extensions /// /// Remove all children from this ScrollSnap /// - /// + /// Array of child GO's removed public void RemoveAllChildren(out GameObject[] ChildrenRemoved) + { + RemoveAllChildren(false, out ChildrenRemoved); + } + + /// + /// Remove all children from this ScrollSnap + /// + /// 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 + /// Array of child GO's removed + public void RemoveAllChildren(bool WorldPositionStays, out GameObject[] ChildrenRemoved) { var _screenCount = _screensContainer.childCount; ChildrenRemoved = new GameObject[_screenCount]; @@ -156,7 +178,7 @@ namespace UnityEngine.UI.Extensions for (int i = _screenCount - 1; i >= 0; i--) { ChildrenRemoved[i] = _screensContainer.GetChild(i).gameObject; - ChildrenRemoved[i].transform.SetParent(null); + ChildrenRemoved[i].transform.SetParent(null, WorldPositionStays); } _scroll_rect.horizontalNormalizedPosition = 0; diff --git a/Scripts/Layout/VerticalScrollSnap.cs b/Scripts/Layout/VerticalScrollSnap.cs index 06623f0..ee8e206 100644 --- a/Scripts/Layout/VerticalScrollSnap.cs +++ b/Scripts/Layout/VerticalScrollSnap.cs @@ -119,9 +119,21 @@ namespace UnityEngine.UI.Extensions /// Remove a new child to this Scroll Snap and recalculate it's children /// *Note, this is an index address (0-x) /// - /// - /// + /// Index element of child to remove + /// >Resulting removed GO public void RemoveChild(int index, out GameObject ChildRemoved) + { + RemoveChild(index, false, out ChildRemoved); + } + + /// + /// Remove a new child to this Scroll Snap and recalculate it's children + /// *Note, this is an index address (0-x) + /// + /// Index element of child to remove + /// 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 + /// Resulting removed GO + public void RemoveChild(int index, bool WorldPositionStays, out GameObject ChildRemoved) { ChildRemoved = null; if (index < 0 || index > _screensContainer.childCount) @@ -131,7 +143,7 @@ namespace UnityEngine.UI.Extensions _scroll_rect.verticalNormalizedPosition = 0; Transform child = _screensContainer.transform.GetChild(index); - child.SetParent(null); + child.SetParent(null, WorldPositionStays); ChildRemoved = child.gameObject; InitialiseChildObjectsFromScene(); DistributePages(); @@ -145,11 +157,22 @@ namespace UnityEngine.UI.Extensions SetScrollContainerPosition(); } + /// /// Remove all children from this ScrollSnap /// - /// + /// Array of child GO's removed public void RemoveAllChildren(out GameObject[] ChildrenRemoved) + { + RemoveAllChildren(false, out ChildrenRemoved); + } + + /// + /// Remove all children from this ScrollSnap + /// + /// 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 + /// Array of child GO's removed + public void RemoveAllChildren(bool WorldPositionStays, out GameObject[] ChildrenRemoved) { var _screenCount = _screensContainer.childCount; ChildrenRemoved = new GameObject[_screenCount]; @@ -157,7 +180,7 @@ namespace UnityEngine.UI.Extensions for (int i = _screenCount - 1; i >= 0; i--) { ChildrenRemoved[i] = _screensContainer.GetChild(i).gameObject; - ChildrenRemoved[i].transform.SetParent(null); + ChildrenRemoved[i].transform.SetParent(null, WorldPositionStays); } _scroll_rect.verticalNormalizedPosition = 0;