Merge branch 'development' into uilineconnector

pull/480/head
Simon (Darkside) Jackson 2024-10-02 13:19:12 +01:00 committed by GitHub
commit 0747258388
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 86 additions and 17 deletions

View File

@ -32,6 +32,9 @@ namespace UnityEngine.UI.Extensions
[Tooltip("Should items being dragged over this list have their sizes equalized?")] [Tooltip("Should items being dragged over this list have their sizes equalized?")]
public bool EqualizeSizesOnDrag = false; public bool EqualizeSizesOnDrag = false;
[Tooltip("Should items keep the original rotation?")]
public bool KeepItemRotation = false;
[Tooltip("Maximum number of items this container can hold")] [Tooltip("Maximum number of items this container can hold")]
public int maxItems = int.MaxValue; public int maxItems = int.MaxValue;

View File

@ -266,7 +266,10 @@ namespace UnityEngine.UI.Extensions
_displacedObjectLE.preferredWidth = _draggingObjectOriginalSize.x; _displacedObjectLE.preferredWidth = _draggingObjectOriginalSize.x;
_displacedObjectLE.preferredHeight = _draggingObjectOriginalSize.y; _displacedObjectLE.preferredHeight = _draggingObjectOriginalSize.y;
_displacedObject.SetParent(_reorderableList.Content, false); _displacedObject.SetParent(_reorderableList.Content, false);
_displacedObject.rotation = _reorderableList.transform.rotation; if (!_reorderableList.KeepItemRotation)
{
_displacedObject.rotation = _reorderableList.transform.rotation;
}
_displacedObject.SetSiblingIndex(_fromIndex); _displacedObject.SetSiblingIndex(_fromIndex);
// Force refreshing both lists because otherwise we get inappropriate FromList in ReorderableListEventStruct // Force refreshing both lists because otherwise we get inappropriate FromList in ReorderableListEventStruct
_reorderableList.Refresh(); _reorderableList.Refresh();
@ -310,7 +313,10 @@ namespace UnityEngine.UI.Extensions
_displacedObjectLE.preferredWidth = _displacedObjectOriginalSize.x; _displacedObjectLE.preferredWidth = _displacedObjectOriginalSize.x;
_displacedObjectLE.preferredHeight = _displacedObjectOriginalSize.y; _displacedObjectLE.preferredHeight = _displacedObjectOriginalSize.y;
_displacedObject.SetParent(_displacedObjectOriginList.Content, false); _displacedObject.SetParent(_displacedObjectOriginList.Content, false);
_displacedObject.rotation = _displacedObjectOriginList.transform.rotation; if (!_reorderableList.KeepItemRotation)
{
_displacedObject.rotation = _displacedObjectOriginList.transform.rotation;
}
_displacedObject.SetSiblingIndex(_displacedFromIndex); _displacedObject.SetSiblingIndex(_displacedFromIndex);
_displacedObject.gameObject.SetActive(true); _displacedObject.gameObject.SetActive(true);
@ -382,7 +388,10 @@ namespace UnityEngine.UI.Extensions
RefreshSizes(); RefreshSizes();
_draggingObject.SetParent(_currentReorderableListRaycasted.Content, false); _draggingObject.SetParent(_currentReorderableListRaycasted.Content, false);
_draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation; if (!_reorderableList.KeepItemRotation)
{
_draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation;
}
_draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex()); _draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex());
//If the item is transferable, it can be dragged out again //If the item is transferable, it can be dragged out again
@ -474,7 +483,10 @@ namespace UnityEngine.UI.Extensions
{ {
RefreshSizes(); RefreshSizes();
_draggingObject.SetParent(_reorderableList.Content, false); _draggingObject.SetParent(_reorderableList.Content, false);
_draggingObject.rotation = _reorderableList.Content.transform.rotation; if (!_reorderableList.KeepItemRotation)
{
_draggingObject.rotation = _reorderableList.Content.transform.rotation;
}
_draggingObject.SetSiblingIndex(_fromIndex); _draggingObject.SetSiblingIndex(_fromIndex);

View File

@ -9,6 +9,12 @@
/// </summary> /// </summary>
using System; using System;
using System.Collections.Generic; 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 namespace UnityEngine.UI.Extensions
{ {
@ -36,6 +42,9 @@ namespace UnityEngine.UI.Extensions
[SerializeField] [SerializeField]
UnityEngine.Gradient _effectGradient = new UnityEngine.Gradient() { colorKeys = new GradientColorKey[] { new GradientColorKey(Color.black, 0), new GradientColorKey(Color.white, 1) } }; 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 #region Properties
public Blend BlendMode public Blend BlendMode
{ {
@ -103,7 +112,11 @@ namespace UnityEngine.UI.Extensions
if (!IsActive() || helper.currentVertCount == 0) if (!IsActive() || helper.currentVertCount == 0)
return; return;
#if UNITY_2021_1_OR_NEWER
List<UIVertex> _vertexList = ListPool<UIVertex>.Get();
#else
List<UIVertex> _vertexList = new List<UIVertex>(); List<UIVertex> _vertexList = new List<UIVertex>();
#endif
helper.GetUIVertexStream(_vertexList); helper.GetUIVertexStream(_vertexList);
@ -218,7 +231,7 @@ namespace UnityEngine.UI.Extensions
helper.AddVert(centralVertex); helper.AddVert(centralVertex);
for (int i = 1; i < steps; i++) helper.AddTriangle(i - 1, i, steps); for (int i = 1; i < steps; i++) helper.AddTriangle(i, i-1, steps);
helper.AddTriangle(0, steps - 1, steps); helper.AddTriangle(0, steps - 1, steps);
} }
@ -238,6 +251,10 @@ namespace UnityEngine.UI.Extensions
} }
break; break;
} }
#if UNITY_2021_1_OR_NEWER
ListPool<UIVertex>.Release(_vertexList);
#endif
} }
Rect GetBounds(List<UIVertex> vertices) Rect GetBounds(List<UIVertex> vertices)
@ -264,7 +281,11 @@ namespace UnityEngine.UI.Extensions
void SplitTrianglesAtGradientStops(List<UIVertex> _vertexList, Rect bounds, float zoomOffset, VertexHelper helper) void SplitTrianglesAtGradientStops(List<UIVertex> _vertexList, Rect bounds, float zoomOffset, VertexHelper helper)
{ {
List<float> stops = FindStops(zoomOffset, bounds); #if UNITY_2021_1_OR_NEWER
List<float> stops = FindStops(zoomOffset, bounds, ListPool<float>.Get());
#else
List<float> stops = FindStops(zoomOffset, bounds, new List<float>());
#endif
if (stops.Count > 0) if (stops.Count > 0)
{ {
helper.Clear(); helper.Clear();
@ -272,10 +293,23 @@ namespace UnityEngine.UI.Extensions
int nCount = _vertexList.Count; int nCount = _vertexList.Count;
for (int i = 0; i < nCount; i += 3) for (int i = 0; i < nCount; i += 3)
{ {
float[] positions = GetPositions(_vertexList, i); #if UNITY_2021_2_OR_NEWER
var positions = ArrayPool<float>.Shared.Rent(3);
#else
var positions = new float[3];
#endif
GetPositions(_vertexList, i, ref positions);
#if UNITY_2021_1_OR_NEWER
List<int> originIndices = ListPool<int>.Get();
List<UIVertex> starts = ListPool<UIVertex>.Get();
List<UIVertex> ends = ListPool<UIVertex>.Get();
#else
List<int> originIndices = new List<int>(3); List<int> originIndices = new List<int>(3);
List<UIVertex> starts = new List<UIVertex>(3); List<UIVertex> starts = new List<UIVertex>(3);
List<UIVertex> ends = new List<UIVertex>(2); List<UIVertex> ends = new List<UIVertex>(2);
#endif
for (int s = 0; s < stops.Count; s++) for (int s = 0; s < stops.Count; s++)
{ {
@ -403,13 +437,24 @@ namespace UnityEngine.UI.Extensions
int vertexCount = helper.currentVertCount; int vertexCount = helper.currentVertCount;
helper.AddTriangle(vertexCount - 3, vertexCount - 2, vertexCount - 1); helper.AddTriangle(vertexCount - 3, vertexCount - 2, vertexCount - 1);
} }
#if UNITY_2021_2_OR_NEWER
ArrayPool<float>.Shared.Return(positions);
#endif
#if UNITY_2021_1_OR_NEWER
ListPool<int>.Release(originIndices);
ListPool<UIVertex>.Release(starts);
ListPool<UIVertex>.Release(ends);
#endif
} }
} }
#if UNITY_2021_1_OR_NEWER
ListPool<float>.Release(stops);
#endif
} }
float[] GetPositions(List<UIVertex> _vertexList, int index) void GetPositions(List<UIVertex> _vertexList, int index, ref float[] positions)
{ {
float[] positions = new float[3];
if (GradientType == Type.Horizontal) if (GradientType == Type.Horizontal)
{ {
positions[0] = _vertexList[index].position.x; positions[0] = _vertexList[index].position.x;
@ -422,24 +467,27 @@ namespace UnityEngine.UI.Extensions
positions[1] = _vertexList[index + 1].position.y; positions[1] = _vertexList[index + 1].position.y;
positions[2] = _vertexList[index + 2].position.y; positions[2] = _vertexList[index + 2].position.y;
} }
return positions;
} }
List<float> FindStops(float zoomOffset, Rect bounds) List<float> FindStops(float zoomOffset, Rect bounds, List<float> stops)
{ {
List<float> stops = new List<float>();
var offset = Offset * (1 - zoomOffset); var offset = Offset * (1 - zoomOffset);
var startBoundary = zoomOffset - offset; var startBoundary = zoomOffset - offset;
var endBoundary = (1 - 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) if (color.time >= endBoundary)
break; break;
if (color.time > startBoundary) if (color.time > startBoundary)
stops.Add((color.time - startBoundary) * Zoom); 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) if (alpha.time >= endBoundary)
break; break;
@ -455,7 +503,13 @@ namespace UnityEngine.UI.Extensions
size = bounds.height; 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++) for (int i = 0; i < stops.Count; i++)
{ {
stops[i] = (stops[i] * size) + min; stops[i] = (stops[i] * size) + min;

View File

@ -1,7 +1,7 @@
{ {
"name": "com.unity.uiextensions", "name": "com.unity.uiextensions",
"displayName": "Unity UI Extensions", "displayName": "Unity UI Extensions",
"version": "2.3.2", "version": "2.3.3",
"description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community", "description": "An extension project for the Unity3D UI system, all crafted and contributed by the awesome Unity community",
"author": "Simon darkside Jackson <@SimonDarksideJ>", "author": "Simon darkside Jackson <@SimonDarksideJ>",
"contributors": [ "contributors": [