From 855607ab678bb88178d2eea69032fe57a74270c8 Mon Sep 17 00:00:00 2001 From: action Date: Sun, 26 Nov 2023 18:28:50 +0000 Subject: [PATCH 1/2] Auto increment pre-release version to 2.3.2 [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eba3275..591a682 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.uiextensions", "displayName": "Unity UI Extensions", - "version": "2.3.2-pre.5", + "version": "2.3.2", "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", "author": "Simon darkside Jackson <@SimonDarksideJ>", "contributors": [ From dde9764fed32edde7395ef670afd469f28911ca4 Mon Sep 17 00:00:00 2001 From: bluefallsky Date: Mon, 29 Jan 2024 00:57:26 +0900 Subject: [PATCH 2/2] Optimize 'Gradient2' 'when 'ModifyMesh' called --- Runtime/Scripts/Effects/Gradient2.cs | 76 ++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/Runtime/Scripts/Effects/Gradient2.cs b/Runtime/Scripts/Effects/Gradient2.cs index 624326a..b0060df 100644 --- a/Runtime/Scripts/Effects/Gradient2.cs +++ b/Runtime/Scripts/Effects/Gradient2.cs @@ -9,6 +9,12 @@ /// using System; using System.Collections.Generic; +#if UNITY_2021_2_OR_NEWER +using System.Buffers; +#endif +#if UNITY_2021_1_OR_NEWER +using UnityEngine.Pool; +#endif namespace UnityEngine.UI.Extensions { @@ -36,6 +42,9 @@ namespace UnityEngine.UI.Extensions [SerializeField] UnityEngine.Gradient _effectGradient = new UnityEngine.Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(Color.black, 0), new GradientColorKey(Color.white, 1) } }; + private GradientColorKey[] _colorKeys; + private GradientAlphaKey[] _alphaKeys; + #region Properties public Blend BlendMode { @@ -103,7 +112,11 @@ namespace UnityEngine.UI.Extensions if (!IsActive() || helper.currentVertCount == 0) return; +#if UNITY_2021_1_OR_NEWER + List _vertexList = ListPool.Get(); +#else List _vertexList = new List(); +#endif helper.GetUIVertexStream(_vertexList); @@ -238,6 +251,10 @@ namespace UnityEngine.UI.Extensions } break; } + +#if UNITY_2021_1_OR_NEWER + ListPool.Release(_vertexList); +#endif } Rect GetBounds(List vertices) @@ -264,7 +281,11 @@ namespace UnityEngine.UI.Extensions void SplitTrianglesAtGradientStops(List _vertexList, Rect bounds, float zoomOffset, VertexHelper helper) { - List stops = FindStops(zoomOffset, bounds); +#if UNITY_2021_1_OR_NEWER + List stops = FindStops(zoomOffset, bounds, ListPool.Get()); +#else + List stops = FindStops(zoomOffset, bounds, new List()); +#endif if (stops.Count > 0) { helper.Clear(); @@ -272,10 +293,23 @@ namespace UnityEngine.UI.Extensions int nCount = _vertexList.Count; for (int i = 0; i < nCount; i += 3) { - float[] positions = GetPositions(_vertexList, i); +#if UNITY_2021_2_OR_NEWER + var positions = ArrayPool.Shared.Rent(3); +#else + var positions = new float[3]; +#endif + + GetPositions(_vertexList, i, ref positions); + +#if UNITY_2021_1_OR_NEWER + List originIndices = ListPool.Get(); + List starts = ListPool.Get(); + List ends = ListPool.Get(); +#else List originIndices = new List(3); List starts = new List(3); List ends = new List(2); +#endif for (int s = 0; s < stops.Count; s++) { @@ -403,13 +437,24 @@ namespace UnityEngine.UI.Extensions int vertexCount = helper.currentVertCount; helper.AddTriangle(vertexCount - 3, vertexCount - 2, vertexCount - 1); } + +#if UNITY_2021_2_OR_NEWER + ArrayPool.Shared.Return(positions); +#endif +#if UNITY_2021_1_OR_NEWER + ListPool.Release(originIndices); + ListPool.Release(starts); + ListPool.Release(ends); +#endif } } +#if UNITY_2021_1_OR_NEWER + ListPool.Release(stops); +#endif } - float[] GetPositions(List _vertexList, int index) + void GetPositions(List _vertexList, int index, ref float[] positions) { - float[] positions = new float[3]; if (GradientType == Type.Horizontal) { positions[0] = _vertexList[index].position.x; @@ -422,24 +467,27 @@ namespace UnityEngine.UI.Extensions positions[1] = _vertexList[index + 1].position.y; positions[2] = _vertexList[index + 2].position.y; } - return positions; } - - List FindStops(float zoomOffset, Rect bounds) + + List FindStops(float zoomOffset, Rect bounds, List stops) { - List stops = new List(); var offset = Offset * (1 - zoomOffset); var startBoundary = zoomOffset - offset; var endBoundary = (1 - zoomOffset) - offset; - foreach (var color in EffectGradient.colorKeys) + if (_colorKeys == null) _colorKeys = EffectGradient.colorKeys; + + foreach (var color in _colorKeys) { if (color.time >= endBoundary) break; if (color.time > startBoundary) stops.Add((color.time - startBoundary) * Zoom); } - foreach (var alpha in EffectGradient.alphaKeys) + + if (_alphaKeys == null) _alphaKeys = _effectGradient.alphaKeys; + + foreach (var alpha in _alphaKeys) { if (alpha.time >= endBoundary) break; @@ -455,7 +503,13 @@ namespace UnityEngine.UI.Extensions size = bounds.height; } - stops.Sort(); + stops.Sort((x, y) => + { + if (x > y) return 1; + if (x == y) return 0; + return -1; + }); + for (int i = 0; i < stops.Count; i++) { stops[i] = (stops[i] * size) + min;