From 10b90c4fb01d425e45015e274fca708c99afcd3e Mon Sep 17 00:00:00 2001 From: JavierMonton Date: Mon, 19 Aug 2024 11:56:07 +0200 Subject: [PATCH] Keep Item Rotation configuration. --- .../ReorderableList/ReorderableList.cs | 3 +++ .../ReorderableList/ReorderableListElement.cs | 20 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs index 5ef840c..8063906 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs @@ -32,6 +32,9 @@ namespace UnityEngine.UI.Extensions [Tooltip("Should items being dragged over this list have their sizes equalized?")] public bool EqualizeSizesOnDrag = false; + [Tooltip("Should items keep the original rotation?")] + public bool KeepItemRotation = false; + [Tooltip("Maximum number of items this container can hold")] public int maxItems = int.MaxValue; diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs index eb1484c..8a09c32 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs @@ -266,7 +266,10 @@ namespace UnityEngine.UI.Extensions _displacedObjectLE.preferredWidth = _draggingObjectOriginalSize.x; _displacedObjectLE.preferredHeight = _draggingObjectOriginalSize.y; _displacedObject.SetParent(_reorderableList.Content, false); - _displacedObject.rotation = _reorderableList.transform.rotation; + if (!_reorderableList.KeepItemRotation) + { + _displacedObject.rotation = _reorderableList.transform.rotation; + } _displacedObject.SetSiblingIndex(_fromIndex); // Force refreshing both lists because otherwise we get inappropriate FromList in ReorderableListEventStruct _reorderableList.Refresh(); @@ -310,7 +313,10 @@ namespace UnityEngine.UI.Extensions _displacedObjectLE.preferredWidth = _displacedObjectOriginalSize.x; _displacedObjectLE.preferredHeight = _displacedObjectOriginalSize.y; _displacedObject.SetParent(_displacedObjectOriginList.Content, false); - _displacedObject.rotation = _displacedObjectOriginList.transform.rotation; + if (!_reorderableList.KeepItemRotation) + { + _displacedObject.rotation = _displacedObjectOriginList.transform.rotation; + } _displacedObject.SetSiblingIndex(_displacedFromIndex); _displacedObject.gameObject.SetActive(true); @@ -382,7 +388,10 @@ namespace UnityEngine.UI.Extensions RefreshSizes(); _draggingObject.SetParent(_currentReorderableListRaycasted.Content, false); - _draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation; + if (!_reorderableList.KeepItemRotation) + { + _draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation; + } _draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex()); //If the item is transferable, it can be dragged out again @@ -474,7 +483,10 @@ namespace UnityEngine.UI.Extensions { RefreshSizes(); _draggingObject.SetParent(_reorderableList.Content, false); - _draggingObject.rotation = _reorderableList.Content.transform.rotation; + if (!_reorderableList.KeepItemRotation) + { + _draggingObject.rotation = _reorderableList.Content.transform.rotation; + } _draggingObject.SetSiblingIndex(_fromIndex);