Skip to content

Commit 0747258

Browse files
Merge branch 'development' into uilineconnector
2 parents 0886131 + e5c329f commit 0747258

File tree

4 files changed

+86
-17
lines changed

4 files changed

+86
-17
lines changed

Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class ReorderableList : MonoBehaviour
3232
[Tooltip("Should items being dragged over this list have their sizes equalized?")]
3333
public bool EqualizeSizesOnDrag = false;
3434

35+
[Tooltip("Should items keep the original rotation?")]
36+
public bool KeepItemRotation = false;
37+
3538
[Tooltip("Maximum number of items this container can hold")]
3639
public int maxItems = int.MaxValue;
3740

Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ private void displaceElement(int targetIndex, Transform displaced)
266266
_displacedObjectLE.preferredWidth = _draggingObjectOriginalSize.x;
267267
_displacedObjectLE.preferredHeight = _draggingObjectOriginalSize.y;
268268
_displacedObject.SetParent(_reorderableList.Content, false);
269-
_displacedObject.rotation = _reorderableList.transform.rotation;
269+
if (!_reorderableList.KeepItemRotation)
270+
{
271+
_displacedObject.rotation = _reorderableList.transform.rotation;
272+
}
270273
_displacedObject.SetSiblingIndex(_fromIndex);
271274
// Force refreshing both lists because otherwise we get inappropriate FromList in ReorderableListEventStruct
272275
_reorderableList.Refresh();
@@ -310,7 +313,10 @@ private void revertDisplacedElement()
310313
_displacedObjectLE.preferredWidth = _displacedObjectOriginalSize.x;
311314
_displacedObjectLE.preferredHeight = _displacedObjectOriginalSize.y;
312315
_displacedObject.SetParent(_displacedObjectOriginList.Content, false);
313-
_displacedObject.rotation = _displacedObjectOriginList.transform.rotation;
316+
if (!_reorderableList.KeepItemRotation)
317+
{
318+
_displacedObject.rotation = _displacedObjectOriginList.transform.rotation;
319+
}
314320
_displacedObject.SetSiblingIndex(_displacedFromIndex);
315321
_displacedObject.gameObject.SetActive(true);
316322

@@ -382,7 +388,10 @@ public void OnEndDrag(PointerEventData eventData)
382388

383389
RefreshSizes();
384390
_draggingObject.SetParent(_currentReorderableListRaycasted.Content, false);
385-
_draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation;
391+
if (!_reorderableList.KeepItemRotation)
392+
{
393+
_draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation;
394+
}
386395
_draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex());
387396

388397
//If the item is transferable, it can be dragged out again
@@ -474,7 +483,10 @@ private void CancelDrag()
474483
{
475484
RefreshSizes();
476485
_draggingObject.SetParent(_reorderableList.Content, false);
477-
_draggingObject.rotation = _reorderableList.Content.transform.rotation;
486+
if (!_reorderableList.KeepItemRotation)
487+
{
488+
_draggingObject.rotation = _reorderableList.Content.transform.rotation;
489+
}
478490
_draggingObject.SetSiblingIndex(_fromIndex);
479491

480492

Runtime/Scripts/Effects/Gradient2.cs

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
/// </summary>
1010
using System;
1111
using System.Collections.Generic;
12+
#if UNITY_2021_2_OR_NEWER
13+
using System.Buffers;
14+
#endif
15+
#if UNITY_2021_1_OR_NEWER
16+
using UnityEngine.Pool;
17+
#endif
1218

1319
namespace UnityEngine.UI.Extensions
1420
{
@@ -36,6 +42,9 @@ public class Gradient2 : BaseMeshEffect
3642
[SerializeField]
3743
UnityEngine.Gradient _effectGradient = new UnityEngine.Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(Color.black, 0), new GradientColorKey(Color.white, 1) } };
3844

45+
private GradientColorKey[] _colorKeys;
46+
private GradientAlphaKey[] _alphaKeys;
47+
3948
#region Properties
4049
public Blend BlendMode
4150
{
@@ -103,7 +112,11 @@ public override void ModifyMesh(VertexHelper helper)
103112
if (!IsActive() || helper.currentVertCount == 0)
104113
return;
105114

115+
#if UNITY_2021_1_OR_NEWER
116+
List<UIVertex> _vertexList = ListPool<UIVertex>.Get();
117+
#else
106118
List<UIVertex> _vertexList = new List<UIVertex>();
119+
#endif
107120

108121
helper.GetUIVertexStream(_vertexList);
109122

@@ -218,7 +231,7 @@ public override void ModifyMesh(VertexHelper helper)
218231

219232
helper.AddVert(centralVertex);
220233

221-
for (int i = 1; i < steps; i++) helper.AddTriangle(i - 1, i, steps);
234+
for (int i = 1; i < steps; i++) helper.AddTriangle(i, i-1, steps);
222235
helper.AddTriangle(0, steps - 1, steps);
223236
}
224237

@@ -238,6 +251,10 @@ public override void ModifyMesh(VertexHelper helper)
238251
}
239252
break;
240253
}
254+
255+
#if UNITY_2021_1_OR_NEWER
256+
ListPool<UIVertex>.Release(_vertexList);
257+
#endif
241258
}
242259

243260
Rect GetBounds(List<UIVertex> vertices)
@@ -264,18 +281,35 @@ Rect GetBounds(List<UIVertex> vertices)
264281

265282
void SplitTrianglesAtGradientStops(List<UIVertex> _vertexList, Rect bounds, float zoomOffset, VertexHelper helper)
266283
{
267-
List<float> stops = FindStops(zoomOffset, bounds);
284+
#if UNITY_2021_1_OR_NEWER
285+
List<float> stops = FindStops(zoomOffset, bounds, ListPool<float>.Get());
286+
#else
287+
List<float> stops = FindStops(zoomOffset, bounds, new List<float>());
288+
#endif
268289
if (stops.Count > 0)
269290
{
270291
helper.Clear();
271292

272293
int nCount = _vertexList.Count;
273294
for (int i = 0; i < nCount; i += 3)
274295
{
275-
float[] positions = GetPositions(_vertexList, i);
296+
#if UNITY_2021_2_OR_NEWER
297+
var positions = ArrayPool<float>.Shared.Rent(3);
298+
#else
299+
var positions = new float[3];
300+
#endif
301+
302+
GetPositions(_vertexList, i, ref positions);
303+
304+
#if UNITY_2021_1_OR_NEWER
305+
List<int> originIndices = ListPool<int>.Get();
306+
List<UIVertex> starts = ListPool<UIVertex>.Get();
307+
List<UIVertex> ends = ListPool<UIVertex>.Get();
308+
#else
276309
List<int> originIndices = new List<int>(3);
277310
List<UIVertex> starts = new List<UIVertex>(3);
278311
List<UIVertex> ends = new List<UIVertex>(2);
312+
#endif
279313

280314
for (int s = 0; s < stops.Count; s++)
281315
{
@@ -403,13 +437,24 @@ void SplitTrianglesAtGradientStops(List<UIVertex> _vertexList, Rect bounds, floa
403437
int vertexCount = helper.currentVertCount;
404438
helper.AddTriangle(vertexCount - 3, vertexCount - 2, vertexCount - 1);
405439
}
440+
441+
#if UNITY_2021_2_OR_NEWER
442+
ArrayPool<float>.Shared.Return(positions);
443+
#endif
444+
#if UNITY_2021_1_OR_NEWER
445+
ListPool<int>.Release(originIndices);
446+
ListPool<UIVertex>.Release(starts);
447+
ListPool<UIVertex>.Release(ends);
448+
#endif
406449
}
407450
}
451+
#if UNITY_2021_1_OR_NEWER
452+
ListPool<float>.Release(stops);
453+
#endif
408454
}
409455

410-
float[] GetPositions(List<UIVertex> _vertexList, int index)
456+
void GetPositions(List<UIVertex> _vertexList, int index, ref float[] positions)
411457
{
412-
float[] positions = new float[3];
413458
if (GradientType == Type.Horizontal)
414459
{
415460
positions[0] = _vertexList[index].position.x;
@@ -422,24 +467,27 @@ float[] GetPositions(List<UIVertex> _vertexList, int index)
422467
positions[1] = _vertexList[index + 1].position.y;
423468
positions[2] = _vertexList[index + 2].position.y;
424469
}
425-
return positions;
426470
}
427-
428-
List<float> FindStops(float zoomOffset, Rect bounds)
471+
472+
List<float> FindStops(float zoomOffset, Rect bounds, List<float> stops)
429473
{
430-
List<float> stops = new List<float>();
431474
var offset = Offset * (1 - zoomOffset);
432475
var startBoundary = zoomOffset - offset;
433476
var endBoundary = (1 - zoomOffset) - offset;
434477

435-
foreach (var color in EffectGradient.colorKeys)
478+
if (_colorKeys == null) _colorKeys = EffectGradient.colorKeys;
479+
480+
foreach (var color in _colorKeys)
436481
{
437482
if (color.time >= endBoundary)
438483
break;
439484
if (color.time > startBoundary)
440485
stops.Add((color.time - startBoundary) * Zoom);
441486
}
442-
foreach (var alpha in EffectGradient.alphaKeys)
487+
488+
if (_alphaKeys == null) _alphaKeys = _effectGradient.alphaKeys;
489+
490+
foreach (var alpha in _alphaKeys)
443491
{
444492
if (alpha.time >= endBoundary)
445493
break;
@@ -455,7 +503,13 @@ List<float> FindStops(float zoomOffset, Rect bounds)
455503
size = bounds.height;
456504
}
457505

458-
stops.Sort();
506+
stops.Sort((x, y) =>
507+
{
508+
if (x > y) return 1;
509+
if (x == y) return 0;
510+
return -1;
511+
});
512+
459513
for (int i = 0; i < stops.Count; i++)
460514
{
461515
stops[i] = (stops[i] * size) + min;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.unity.uiextensions",
33
"displayName": "Unity UI Extensions",
4-
"version": "2.3.2",
4+
"version": "2.3.3",
55
"description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community",
66
"author": "Simon darkside Jackson <@SimonDarksideJ>",
77
"contributors": [

0 commit comments

Comments
 (0)