From fc6ea6089d4c494b1c1c62334b51db75f0519410 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 21:01:37 +0100 Subject: [PATCH 1/5] Fixes issue #398 where the Next / Previous buttons filed to work if the ScrollSnap was previously scrolling. Also renamed the Extension Methods scripts and added a new function. Resolves: #398 --- Runtime/Scripts/Layout/ScrollSnapBase.cs | 14 +++++------- ...xtentionMethods.cs => ExtensionMethods.cs} | 22 +++++++++++++++++++ ...thods.cs.meta => ExtensionMethods.cs.meta} | 0 3 files changed, 28 insertions(+), 8 deletions(-) rename Runtime/Scripts/Utilities/{ExtentionMethods.cs => ExtensionMethods.cs} (57%) rename Runtime/Scripts/Utilities/{ExtentionMethods.cs.meta => ExtensionMethods.cs.meta} (100%) diff --git a/Runtime/Scripts/Layout/ScrollSnapBase.cs b/Runtime/Scripts/Layout/ScrollSnapBase.cs index abee12c..3d570c7 100644 --- a/Runtime/Scripts/Layout/ScrollSnapBase.cs +++ b/Runtime/Scripts/Layout/ScrollSnapBase.cs @@ -5,6 +5,7 @@ using System; using UnityEngine.Events; using UnityEngine.EventSystems; +using UnityEngine.UI.Extensions; namespace UnityEngine.UI.Extensions { @@ -314,6 +315,8 @@ namespace UnityEngine.UI.Extensions //Function for switching screens with buttons public void NextScreen() { + _scroll_rect.velocity = Vector2.zero; + if (_currentPage < _screens - 1 || _isInfinite) { if (!_lerp) StartScreenChange(); @@ -336,6 +339,8 @@ namespace UnityEngine.UI.Extensions //Function for switching screens with buttons public void PreviousScreen() { + _scroll_rect.velocity = Vector2.zero; + if (_currentPage > 0 || _isInfinite) { if (!_lerp) StartScreenChange(); @@ -515,15 +520,8 @@ namespace UnityEngine.UI.Extensions MaskBuffer = 1; } - if (PageStep < 0) - { - PageStep = 0; - } + PageStep.Clamp(0, 9); - if (PageStep > 8) - { - PageStep = 9; - } var infiniteScroll = GetComponent(); if (ChildObjects != null && ChildObjects.Length > 0 && infiniteScroll != null && !infiniteScroll.InitByUser) { diff --git a/Runtime/Scripts/Utilities/ExtentionMethods.cs b/Runtime/Scripts/Utilities/ExtensionMethods.cs similarity index 57% rename from Runtime/Scripts/Utilities/ExtentionMethods.cs rename to Runtime/Scripts/Utilities/ExtensionMethods.cs index 07da566..4193c3c 100644 --- a/Runtime/Scripts/Utilities/ExtentionMethods.cs +++ b/Runtime/Scripts/Utilities/ExtensionMethods.cs @@ -29,5 +29,27 @@ namespace UnityEngine.UI.Extensions !gameObject.hideFlags.HasFlag(HideFlags.HideInHierarchy); // I don't care about GameObjects *inside* prefabs, just the overall prefab. } + + /// + /// Generic clamp method to limt a value between a range of values + /// + /// data type + /// Value to clamp + /// Minimum value + /// Maximum value + /// + public static T Clamp(this T value, T min, T max) where T : IComparable + { + if (value.CompareTo(min) < 0) + { + value = min; + } + if (value.CompareTo(max) > 0) + { + value = max; + } + + return value; + } } } diff --git a/Runtime/Scripts/Utilities/ExtentionMethods.cs.meta b/Runtime/Scripts/Utilities/ExtensionMethods.cs.meta similarity index 100% rename from Runtime/Scripts/Utilities/ExtentionMethods.cs.meta rename to Runtime/Scripts/Utilities/ExtensionMethods.cs.meta From d0fbb28b055c1ba6a4a9e4e86055f4176782d83e Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 21:24:18 +0100 Subject: [PATCH 2/5] Resolves #397 Moved OnValidate checks which redraw the component to the RectTransformDimensionsCHanged event --- Runtime/Scripts/Controls/Stepper.cs | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/Runtime/Scripts/Controls/Stepper.cs b/Runtime/Scripts/Controls/Stepper.cs index 6d920d8..99f6cb6 100644 --- a/Runtime/Scripts/Controls/Stepper.cs +++ b/Runtime/Scripts/Controls/Stepper.cs @@ -9,6 +9,7 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { // Stepper control + [ExecuteInEditMode] [AddComponentMenu("UI/Extensions/Stepper")] [RequireComponent(typeof(RectTransform))] public class Stepper : UIBehaviour @@ -89,28 +90,6 @@ namespace UnityEngine.UI.Extensions protected Stepper() { } -#if UNITY_EDITOR - protected override void OnValidate() - { - base.OnValidate(); - - RecreateSprites(sides); - if (separator) - LayoutSides(); - - if (!wrap) - { - DisableAtExtremes(sides); - } - } -#endif - - protected override void Start() - { - if (isActiveAndEnabled) - StartCoroutine(DelayedInit()); - } - protected override void OnEnable() { StartCoroutine(DelayedInit()); From c059e2338a417acdc6a944acb15d03338969be2b Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 23:12:42 +0100 Subject: [PATCH 3/5] Updated UIParticleSystem access to Particles array to ensure it is more stable. Updated some #if statements to be better future proofed Resolves #360 --- Runtime/Scripts/Effects/UIParticleSystem.cs | 52 ++++++++++++--------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/Runtime/Scripts/Effects/UIParticleSystem.cs b/Runtime/Scripts/Effects/UIParticleSystem.cs index b9c4981..0dd99a6 100644 --- a/Runtime/Scripts/Effects/UIParticleSystem.cs +++ b/Runtime/Scripts/Effects/UIParticleSystem.cs @@ -43,6 +43,22 @@ namespace UnityEngine.UI.Extensions } } + public ParticleSystem.Particle[] Particles + { + get + { + if (particles == null) + { +#if UNITY_5_5_OR_NEWER + particles = new ParticleSystem.Particle[pSystem.main.maxParticles]; +#else + particles = new ParticleSystem.Particle[pSystem.maxParticles]; +#endif + } + return particles; + } + } + protected bool Initialize() { // initialize members @@ -66,8 +82,10 @@ namespace UnityEngine.UI.Extensions mainModule.maxParticles = 14000; } #else - if (pSystem.maxParticles > 14000) - pSystem.maxParticles = 14000; + if (pSystem.maxParticles > 14000) + { + pSystem.maxParticles = 14000; + } #endif pRenderer = pSystem.GetComponent(); @@ -95,18 +113,9 @@ namespace UnityEngine.UI.Extensions #if UNITY_5_5_OR_NEWER mainModule.scalingMode = ParticleSystemScalingMode.Hierarchy; #else - pSystem.scalingMode = ParticleSystemScalingMode.Hierarchy; + pSystem.scalingMode = ParticleSystemScalingMode.Hierarchy; #endif - - particles = null; } -#if UNITY_5_5_OR_NEWER - if (particles == null) - particles = new ParticleSystem.Particle[pSystem.main.maxParticles]; -#else - if (particles == null) - particles = new ParticleSystem.Particle[pSystem.maxParticles]; -#endif imageUV = new Vector4(0, 0, 1, 1); @@ -127,7 +136,9 @@ namespace UnityEngine.UI.Extensions { base.Awake(); if (!Initialize()) + { enabled = false; + } } @@ -160,17 +171,17 @@ namespace UnityEngine.UI.Extensions Vector2 corner1 = Vector2.zero; Vector2 corner2 = Vector2.zero; // iterate through current particles - int count = pSystem.GetParticles(particles); + int count = pSystem.GetParticles(Particles); for (int i = 0; i < count; ++i) { - ParticleSystem.Particle particle = particles[i]; + ParticleSystem.Particle particle = Particles[i]; // get particle properties #if UNITY_5_5_OR_NEWER Vector2 position = (mainModule.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position)); #else - Vector2 position = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position)); + Vector2 position = (pSystem.simulationSpace == ParticleSystemSimulationSpace.Local ? particle.position : _transform.InverseTransformPoint(particle.position)); #endif float rotation = -particle.rotation * Mathf.Deg2Rad; float rotation90 = rotation + Mathf.PI / 2; @@ -182,8 +193,8 @@ namespace UnityEngine.UI.Extensions if (mainModule.scalingMode == ParticleSystemScalingMode.Shape) position /= canvas.scaleFactor; #else - if (pSystem.scalingMode == ParticleSystemScalingMode.Shape) - position /= canvas.scaleFactor; + if (pSystem.scalingMode == ParticleSystemScalingMode.Shape) + position /= canvas.scaleFactor; #endif // apply texture sheet animation @@ -223,7 +234,7 @@ namespace UnityEngine.UI.Extensions frame = Mathf.FloorToInt(frameProgress * textureSheetAnimation.numTilesX); int row = textureSheetAnimation.rowIndex; -#if UNITY_2020 || UNITY_2019 +#if UNITY_2019_1_OR_NEWER if (textureSheetAnimation.rowMode == ParticleSystemAnimationRowMode.Random) #else if (textureSheetAnimation.useRandomRow) @@ -378,8 +389,7 @@ namespace UnityEngine.UI.Extensions } } } - if (material == currentMaterial) - return; + if (material == currentMaterial) { return; } pSystem = null; Initialize(); } @@ -407,4 +417,4 @@ namespace UnityEngine.UI.Extensions } } #endif - } \ No newline at end of file +} \ No newline at end of file From 5db15808e232767ee8913a9cb4726fbce3a7e7ad Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 23:25:31 +0100 Subject: [PATCH 4/5] Fixed the UIConnector to safely handle when no parent canvas can be found. Resolves #392 --- Runtime/Scripts/Utilities/UIExtensionMethods.cs | 4 ++++ Runtime/Scripts/Utilities/UILineConnector.cs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Runtime/Scripts/Utilities/UIExtensionMethods.cs b/Runtime/Scripts/Utilities/UIExtensionMethods.cs index 2b2f10a..3472139 100644 --- a/Runtime/Scripts/Utilities/UIExtensionMethods.cs +++ b/Runtime/Scripts/Utilities/UIExtensionMethods.cs @@ -15,6 +15,10 @@ namespace UnityEngine.UI.Extensions parentCanvas = rt.GetComponentInParent(); if (parentCanvas == null) { + if (parent.parent == null) + { + return null; + } parent = parent.parent.GetComponent(); SearchIndex++; } diff --git a/Runtime/Scripts/Utilities/UILineConnector.cs b/Runtime/Scripts/Utilities/UILineConnector.cs index 6b18000..487dec5 100644 --- a/Runtime/Scripts/Utilities/UILineConnector.cs +++ b/Runtime/Scripts/Utilities/UILineConnector.cs @@ -18,7 +18,11 @@ namespace UnityEngine.UI.Extensions private void Awake() { - canvas = GetComponentInParent().GetParentCanvas().GetComponent(); + var canvasParent = GetComponentInParent().GetParentCanvas(); + if (canvasParent != null) + { + canvas = canvasParent.GetComponent(); + } rt = GetComponent(); lr = GetComponent(); } From 10e5273b3107d4d69f13cb8845f0c230ae1fda30 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 23:36:50 +0100 Subject: [PATCH 5/5] Fixed issue which allowed an item marked as NOT transferable to actually be transferred between lists Resolves #382 --- .../Scripts/Controls/ReorderableList/ReorderableListElement.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs index 8cba2f9..45d6753 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs @@ -179,7 +179,7 @@ namespace UnityEngine.UI.Extensions //If nothing found or the list is not dropable, put the fake element outside if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false -// || (_oldReorderableListRaycasted != _reorderableList && !IsTransferable) + || (_oldReorderableListRaycasted != _reorderableList && !IsTransferable) || ((_fakeElement.parent == _currentReorderableListRaycasted.Content ? _currentReorderableListRaycasted.Content.childCount - 1 : _currentReorderableListRaycasted.Content.childCount) >= _currentReorderableListRaycasted.maxItems && !_currentReorderableListRaycasted.IsDisplacable)