From dff07c69529e240e47a140c091b20e86afbd15a2 Mon Sep 17 00:00:00 2001 From: "Simon (Darkside) Jackson" Date: Mon, 10 May 2021 20:42:38 +0100 Subject: [PATCH 01/82] Package upver for Development --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5194740..76726ea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.uiextensions", "displayName": "Unity UI Extensions", - "version": "2.2.7", + "version": "2.2.8-Release", "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 0de91f60fbaa8afe18e131b632150d175556b55b Mon Sep 17 00:00:00 2001 From: Robert Rioja Date: Thu, 27 May 2021 18:38:47 +0000 Subject: [PATCH 02/82] Added OnHighlightChanged and OnPressChanged events Added getters and setters for Highlighted and Pressed --- Runtime/Scripts/Utilities/UIHighlightable.cs | 93 +++++++++++++++++++- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/Runtime/Scripts/Utilities/UIHighlightable.cs b/Runtime/Scripts/Utilities/UIHighlightable.cs index 09d4798..86956ed 100644 --- a/Runtime/Scripts/Utilities/UIHighlightable.cs +++ b/Runtime/Scripts/Utilities/UIHighlightable.cs @@ -15,6 +15,10 @@ namespace UnityEngine.UI.Extensions [System.Serializable] public class InteractableChangedEvent : Events.UnityEvent { } + [System.Serializable] + public class HighlightChangedEvent : Events.UnityEvent { } + [System.Serializable] + public class PressChangedEvent : Events.UnityEvent { } [SerializeField][Tooltip("Can this panel be interacted with or is it disabled? (does not affect child components)")] private bool m_Interactable = true; @@ -29,13 +33,71 @@ namespace UnityEngine.UI.Extensions m_Interactable = value; HighlightInteractable(m_Graphic); OnInteractableChanged.Invoke(m_Interactable); + + if(!m_Interactable) + { + if(m_Highlighted) + { + m_Highlighted = false; + OnHighlightChanged.Invoke(false); + } + + if(m_Pressed) + { + m_Pressed = false; + OnPressChanged.Invoke(false); + } + } } } public bool ClickToHold { get { return m_ClickToHold; } - set { m_ClickToHold = value; } + set + { + m_ClickToHold = value; + + if(!m_ClickToHold && m_Pressed) + { + m_Pressed = false; + OnPressChanged.Invoke(false); + } + } + } + + public bool Highlighted + { + get { return m_Highlighted; } + set + { + if(m_Highlighted != value) + { + m_Highlighted = value; + HighlightInteractable(m_Graphic); + if(m_Interactable) + { + OnHighlightChanged.Invoke(m_Highlighted); + } + } + } + } + + public bool Pressed + { + get { return m_Pressed; } + set + { + if(m_Pressed != value) + { + m_Pressed = value; + m_Graphic.color = (m_Pressed ? PressedColor : NormalColor); + if(m_Interactable) + { + OnPressChanged.Invoke(m_Pressed); + } + } + } } [Tooltip("The default color for the panel")] @@ -49,6 +111,10 @@ namespace UnityEngine.UI.Extensions [Tooltip("Event for when the panel is enabled / disabled, to enable disabling / enabling of child or other gameobjects")] public InteractableChangedEvent OnInteractableChanged; + [Tooltip("Event for when the panel highlight state is activated or deactivated")] + public HighlightChangedEvent OnHighlightChanged; + [Tooltip("Event for when the panel press state is activated or deactivated")] + public PressChangedEvent OnPressChanged; void Awake() { @@ -61,6 +127,7 @@ namespace UnityEngine.UI.Extensions { m_Highlighted = true; m_Graphic.color = HighlightedColor; + OnHighlightChanged.Invoke(true); } } @@ -70,6 +137,7 @@ namespace UnityEngine.UI.Extensions { m_Highlighted = false; m_Graphic.color = NormalColor; + OnHighlightChanged.Invoke(false); } } @@ -80,14 +148,33 @@ namespace UnityEngine.UI.Extensions m_Graphic.color = PressedColor; if (ClickToHold) { - m_Pressed = !m_Pressed; + if(m_Pressed) + { + m_Pressed = false; + } + else + { + m_Pressed = true; + OnPressChanged.Invoke(true); + } + } + else + { + OnPressChanged.Invoke(true); } } } public void OnPointerUp(PointerEventData eventData) { - if(!m_Pressed) HighlightInteractable(m_Graphic); + if(!m_Pressed) + { + HighlightInteractable(m_Graphic); + if(m_Interactable) + { + OnPressChanged.Invoke(false); + } + } } private void HighlightInteractable(Graphic graphic) From 830a4466eb79b0a247dab7db33257599114154bb Mon Sep 17 00:00:00 2001 From: "Simon (Darkside) Jackson" Date: Wed, 23 Jun 2021 13:23:13 +0100 Subject: [PATCH 03/82] Patch fix for UILineRenderer --- Runtime/Scripts/Primitives/UILineRenderer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Scripts/Primitives/UILineRenderer.cs b/Runtime/Scripts/Primitives/UILineRenderer.cs index 804e3a2..590bdba 100644 --- a/Runtime/Scripts/Primitives/UILineRenderer.cs +++ b/Runtime/Scripts/Primitives/UILineRenderer.cs @@ -466,7 +466,7 @@ namespace UnityEngine.UI.Extensions protected override void OnEnable() { base.OnEnable(); - if (m_points.Length == 0) + if (m_points?.Length == 0) { m_points = new Vector2[1]; } From b0f161a4e0f716b7565175550ebe98e93a376e2d Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 5 Sep 2021 09:04:15 +0100 Subject: [PATCH 04/82] Update package preview release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 76726ea..1c875cc 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.uiextensions", "displayName": "Unity UI Extensions", - "version": "2.2.8-Release", + "version": "2.2.8-preview", "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 774f8de199ca4a6a5897c899bbe70777a7cf9792 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 5 Sep 2021 09:33:19 +0100 Subject: [PATCH 05/82] Resolves issue where the lower range value would become stuck when moved to the max value position Resolves: https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/381/cant-move-range-slider-if-low-is-moved-to --- Runtime/Scripts/Controls/RangeSlider.cs | 56 +++++++++++++++---------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/Runtime/Scripts/Controls/RangeSlider.cs b/Runtime/Scripts/Controls/RangeSlider.cs index ceeb6da..4477017 100644 --- a/Runtime/Scripts/Controls/RangeSlider.cs +++ b/Runtime/Scripts/Controls/RangeSlider.cs @@ -533,31 +533,17 @@ namespace UnityEngine.UI.Extensions //HANDLE DRAG EVENTS m_LowOffset = m_HighOffset = Vector2.zero; Vector2 localMousePos; - if (m_HighHandleRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HighHandleRect, eventData.position, eventData.enterEventCamera)) + if(m_LowHandleRect != null && LowValue == MaxValue && RectTransformUtility.RectangleContainsScreenPoint(m_LowHandleRect, eventData.position, eventData.enterEventCamera)) { - //dragging the high value handle - if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HighHandleRect, eventData.position, eventData.pressEventCamera, out localMousePos)) - { - m_HighOffset = localMousePos; - } - interactionState = InteractionState.High; - if (transition == Transition.ColorTint) - { - targetGraphic = m_HighHandleRect.GetComponent(); - } + SetToMoveLowValueHandle(m_LowHandleRect, eventData); + } + else if (m_HighHandleRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HighHandleRect, eventData.position, eventData.enterEventCamera)) + { + SetToMoveHighValueHandle(m_HighHandleRect, eventData); } else if (m_LowHandleRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_LowHandleRect, eventData.position, eventData.enterEventCamera)) { - //dragging the low value handle - if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_LowHandleRect, eventData.position, eventData.pressEventCamera, out localMousePos)) - { - m_LowOffset = localMousePos; - } - interactionState = InteractionState.Low; - if (transition == Transition.ColorTint) - { - targetGraphic = m_LowHandleRect.GetComponent(); - } + SetToMoveLowValueHandle(m_LowHandleRect, eventData); } else { @@ -575,6 +561,34 @@ namespace UnityEngine.UI.Extensions base.OnPointerDown(eventData); } + private void SetToMoveLowValueHandle(RectTransform transform, PointerEventData eventData) + { + //dragging the low value handle + if (RectTransformUtility.ScreenPointToLocalPointInRectangle(transform, eventData.position, eventData.pressEventCamera, out var localMousePos)) + { + m_LowOffset = localMousePos; + } + interactionState = InteractionState.Low; + if (transition == Transition.ColorTint) + { + targetGraphic = m_LowHandleRect.GetComponent(); + } + } + + private void SetToMoveHighValueHandle(RectTransform transform, PointerEventData eventData) + { + //dragging the low value handle + if (RectTransformUtility.ScreenPointToLocalPointInRectangle(transform, eventData.position, eventData.pressEventCamera, out var localMousePos)) + { + m_HighOffset = localMousePos; + } + interactionState = InteractionState.High; + if (transition == Transition.ColorTint) + { + targetGraphic = m_HighHandleRect.GetComponent(); + } + } + public virtual void OnDrag(PointerEventData eventData) { if (!MayDrag(eventData)) From 0410ca53d7f740145119a80eef2065d38d8636e2 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 5 Sep 2021 15:23:48 +0100 Subject: [PATCH 06/82] Updated Infinite scroll to work with content of different sizes --- .../Scripts/Utilities/UI_InfiniteScroll.cs | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/Runtime/Scripts/Utilities/UI_InfiniteScroll.cs b/Runtime/Scripts/Utilities/UI_InfiniteScroll.cs index 742788b..c4100ff 100644 --- a/Runtime/Scripts/Utilities/UI_InfiniteScroll.cs +++ b/Runtime/Scripts/Utilities/UI_InfiniteScroll.cs @@ -38,7 +38,7 @@ namespace UnityEngine.UI.Extensions protected List items = new List(); private Vector2 _newAnchoredPosition = Vector2.zero; //TO DISABLE FLICKERING OBJECT WHEN SCROLL VIEW IS IDLE IN BETWEEN OBJECTS - private float _threshold = 100f; + private Vector2 _threshold = Vector2.zero; private int _itemCount = 0; private float _recordOffsetX = 0; private float _recordOffsetY = 0; @@ -116,6 +116,7 @@ namespace UnityEngine.UI.Extensions _isHorizontal = _scrollRect.horizontal; _isVertical = _scrollRect.vertical; + _threshold = _scrollRect.GetComponent().sizeDelta * 0.5f; if (_isHorizontal && _isVertical) { @@ -175,41 +176,51 @@ namespace UnityEngine.UI.Extensions if (!_hasDisabledGridComponents) DisableGridComponents(); + var firstChild = _scrollRect.content.GetChild(0).GetComponent(); + var lastChild = _scrollRect.content.GetChild(_itemCount - 1).GetComponent(); + for (int i = 0; i < items.Count; i++) { if (_isHorizontal) { - if (_scrollRect.transform.InverseTransformPoint(items[i].gameObject.transform.position).x > _disableMarginX + _threshold) + if (_scrollRect.transform.InverseTransformPoint(items[i].gameObject.transform.position).x > items[i].sizeDelta.x + _threshold.x && items[i] == lastChild) { + //Moving before first child ( slide right) _newAnchoredPosition = items[i].anchoredPosition; - _newAnchoredPosition.x -= _itemCount * _recordOffsetX; + _newAnchoredPosition.x = firstChild.anchoredPosition.x - items[i].sizeDelta.x; items[i].anchoredPosition = _newAnchoredPosition; - _scrollRect.content.GetChild(_itemCount - 1).transform.SetAsFirstSibling(); + lastChild.transform.SetAsFirstSibling(); } - else if (_scrollRect.transform.InverseTransformPoint(items[i].gameObject.transform.position).x < -_disableMarginX) + else if (_scrollRect.transform.InverseTransformPoint(items[i].gameObject.transform.position).x < -items[i].sizeDelta.x - _threshold.x - 100 && items[i] == firstChild) { + //Moving before first child (slide left) _newAnchoredPosition = items[i].anchoredPosition; - _newAnchoredPosition.x += _itemCount * _recordOffsetX; + _newAnchoredPosition.x = lastChild.anchoredPosition.x + lastChild.sizeDelta.x; items[i].anchoredPosition = _newAnchoredPosition; - _scrollRect.content.GetChild(0).transform.SetAsLastSibling(); + firstChild.transform.SetAsLastSibling(); + } } if (_isVertical) { - if (_scrollRect.transform.InverseTransformPoint(items[i].gameObject.transform.position).y > _disableMarginY + _threshold) + if (_scrollRect.transform.InverseTransformPoint(items[i].gameObject.transform.position).y > items[i].sizeDelta.y + _threshold.y && items[i] == firstChild) { + //Moving after last child ( slide up) _newAnchoredPosition = items[i].anchoredPosition; - _newAnchoredPosition.y -= _itemCount * _recordOffsetY; + _newAnchoredPosition.y = lastChild.anchoredPosition.y - items[i].sizeDelta.y; + items[i].anchoredPosition = _newAnchoredPosition; - _scrollRect.content.GetChild(_itemCount - 1).transform.SetAsFirstSibling(); + firstChild.transform.SetAsLastSibling(); } - else if (_scrollRect.transform.InverseTransformPoint(items[i].gameObject.transform.position).y < -_disableMarginY) + else if (_scrollRect.transform.InverseTransformPoint(items[i].gameObject.transform.position).y < -items[i].sizeDelta.y - _threshold.y - 100 && items[i] == lastChild) { + //Moving before first child (slidw down) _newAnchoredPosition = items[i].anchoredPosition; - _newAnchoredPosition.y += _itemCount * _recordOffsetY; + _newAnchoredPosition.y = firstChild.anchoredPosition.y + firstChild.sizeDelta.y; + items[i].anchoredPosition = _newAnchoredPosition; - _scrollRect.content.GetChild(0).transform.SetAsLastSibling(); + lastChild.transform.SetAsFirstSibling(); } } } From 1c68432e02ec6b9e3c081783dcc5017d542eee4e Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 5 Sep 2021 15:33:24 +0100 Subject: [PATCH 07/82] Clean-up and reset pivots on scene start --- .../Scripts/Utilities/UI_InfiniteScroll.cs | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/Runtime/Scripts/Utilities/UI_InfiniteScroll.cs b/Runtime/Scripts/Utilities/UI_InfiniteScroll.cs index c4100ff..dbcdd3a 100644 --- a/Runtime/Scripts/Utilities/UI_InfiniteScroll.cs +++ b/Runtime/Scripts/Utilities/UI_InfiniteScroll.cs @@ -32,16 +32,12 @@ namespace UnityEngine.UI.Extensions private GridLayoutGroup _gridLayoutGroup; protected bool _isVertical = false; protected bool _isHorizontal = false; - private float _disableMarginX = 0; - private float _disableMarginY = 0; private bool _hasDisabledGridComponents = false; protected List items = new List(); private Vector2 _newAnchoredPosition = Vector2.zero; //TO DISABLE FLICKERING OBJECT WHEN SCROLL VIEW IS IDLE IN BETWEEN OBJECTS private Vector2 _threshold = Vector2.zero; private int _itemCount = 0; - private float _recordOffsetX = 0; - private float _recordOffsetY = 0; protected virtual void Awake() { @@ -81,6 +77,12 @@ namespace UnityEngine.UI.Extensions private void SetItems() { + //Remove Pivots from content as they mess up translation + foreach (RectTransform transform in _scrollRect.content.transform) + { + transform.pivot = Vector3.zero; + } + for (int i = 0; i < _scrollRect.content.childCount; i++) { items.Add(_scrollRect.content.GetChild(i).GetComponent()); @@ -133,25 +135,6 @@ namespace UnityEngine.UI.Extensions void DisableGridComponents() { - if (_isVertical) - { - _recordOffsetY = items[1].GetComponent().anchoredPosition.y - items[0].GetComponent().anchoredPosition.y; - if (_recordOffsetY < 0) - { - _recordOffsetY *= -1; - } - _disableMarginY = _recordOffsetY * _itemCount / 2; - } - if (_isHorizontal) - { - _recordOffsetX = items[1].GetComponent().anchoredPosition.x - items[0].GetComponent().anchoredPosition.x; - if (_recordOffsetX < 0) - { - _recordOffsetX *= -1; - } - _disableMarginX = _recordOffsetX * _itemCount / 2; - } - if (_verticalLayoutGroup) { _verticalLayoutGroup.enabled = false; From 6333967b9aee5915b95eeecfd1eaaf208c751528 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 5 Sep 2021 15:39:28 +0100 Subject: [PATCH 08/82] Patches from PR --- Runtime/Scripts/Utilities/UIHighlightable.cs | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Runtime/Scripts/Utilities/UIHighlightable.cs b/Runtime/Scripts/Utilities/UIHighlightable.cs index 86956ed..48f3ff9 100644 --- a/Runtime/Scripts/Utilities/UIHighlightable.cs +++ b/Runtime/Scripts/Utilities/UIHighlightable.cs @@ -32,20 +32,20 @@ namespace UnityEngine.UI.Extensions { m_Interactable = value; HighlightInteractable(m_Graphic); - OnInteractableChanged.Invoke(m_Interactable); + OnInteractableChanged?.Invoke(m_Interactable); if(!m_Interactable) { if(m_Highlighted) { m_Highlighted = false; - OnHighlightChanged.Invoke(false); + OnHighlightChanged?.Invoke(false); } if(m_Pressed) { m_Pressed = false; - OnPressChanged.Invoke(false); + OnPressChanged?.Invoke(false); } } } @@ -61,7 +61,7 @@ namespace UnityEngine.UI.Extensions if(!m_ClickToHold && m_Pressed) { m_Pressed = false; - OnPressChanged.Invoke(false); + OnPressChanged?.Invoke(false); } } } @@ -77,7 +77,7 @@ namespace UnityEngine.UI.Extensions HighlightInteractable(m_Graphic); if(m_Interactable) { - OnHighlightChanged.Invoke(m_Highlighted); + OnHighlightChanged?.Invoke(m_Highlighted); } } } @@ -94,7 +94,7 @@ namespace UnityEngine.UI.Extensions m_Graphic.color = (m_Pressed ? PressedColor : NormalColor); if(m_Interactable) { - OnPressChanged.Invoke(m_Pressed); + OnPressChanged?.Invoke(m_Pressed); } } } @@ -127,7 +127,7 @@ namespace UnityEngine.UI.Extensions { m_Highlighted = true; m_Graphic.color = HighlightedColor; - OnHighlightChanged.Invoke(true); + OnHighlightChanged?.Invoke(true); } } @@ -137,7 +137,7 @@ namespace UnityEngine.UI.Extensions { m_Highlighted = false; m_Graphic.color = NormalColor; - OnHighlightChanged.Invoke(false); + OnHighlightChanged?.Invoke(false); } } @@ -155,12 +155,12 @@ namespace UnityEngine.UI.Extensions else { m_Pressed = true; - OnPressChanged.Invoke(true); + OnPressChanged?.Invoke(true); } } else { - OnPressChanged.Invoke(true); + OnPressChanged?.Invoke(true); } } } @@ -172,7 +172,7 @@ namespace UnityEngine.UI.Extensions HighlightInteractable(m_Graphic); if(m_Interactable) { - OnPressChanged.Invoke(false); + OnPressChanged?.Invoke(false); } } } From f101afbb299853b3678ffccc6dc58455682b840d Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Thu, 21 Oct 2021 13:48:44 +0100 Subject: [PATCH 09/82] Clean up range slider unused variables --- Runtime/Scripts/Controls/RangeSlider.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Runtime/Scripts/Controls/RangeSlider.cs b/Runtime/Scripts/Controls/RangeSlider.cs index 4477017..b43401a 100644 --- a/Runtime/Scripts/Controls/RangeSlider.cs +++ b/Runtime/Scripts/Controls/RangeSlider.cs @@ -532,7 +532,6 @@ namespace UnityEngine.UI.Extensions //HANDLE DRAG EVENTS m_LowOffset = m_HighOffset = Vector2.zero; - Vector2 localMousePos; if(m_LowHandleRect != null && LowValue == MaxValue && RectTransformUtility.RectangleContainsScreenPoint(m_LowHandleRect, eventData.position, eventData.enterEventCamera)) { SetToMoveLowValueHandle(m_LowHandleRect, eventData); From 056419a87ba76d1c03b0f94179e4ab1586f48b41 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Thu, 21 Oct 2021 13:57:42 +0100 Subject: [PATCH 10/82] Updated Dropdown list to NOT resize text Rect on draw --- Runtime/Scripts/Controls/ComboBox/DropDownList.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs index 2e3b23a..8b33cf7 100644 --- a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs +++ b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs @@ -74,13 +74,15 @@ namespace UnityEngine.UI.Extensions [SerializeField] private bool _displayPanelAbove = false; + [SerializeField] + [Tooltip("Override the Text width for the values.")] + private bool _overrideTextWidth = true; + [System.Serializable] - public class SelectionChangedEvent : UnityEngine.Events.UnityEvent { - } + public class SelectionChangedEvent : UnityEngine.Events.UnityEvent { } // fires when item is changed; public SelectionChangedEvent OnSelectionChanged; - public void Start() { Initialize(); @@ -332,7 +334,10 @@ namespace UnityEngine.UI.Extensions _hasDrawnOnce = true; _mainButton.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x); _mainButton.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y); - _mainButton.txt.rectTransform.offsetMax = new Vector2(4, 0); + if (_overrideTextWidth) + { + _mainButton.txt.rectTransform.offsetMax = new Vector2(4, 0); + } _scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay _scrollPanelRT.anchoredPosition = _displayPanelAbove ? From 33568a6d67e6714a81955b793e0294bba381734f Mon Sep 17 00:00:00 2001 From: Ben MacKinnon Date: Mon, 21 Mar 2022 18:02:10 +0000 Subject: [PATCH 11/82] Upgraded RangeSlider to work in both Horizontal and Verticle setups, just like regular slider. Also fixed a minor issue with offset when dragging on the bar. # Conflicts: # Runtime/Scripts/Controls/RangeSlider.cs --- Editor/RangeSliderEditor.cs | 13 +- Runtime/Scripts/Controls/RangeSlider.cs | 230 +++++++++++++++++------- 2 files changed, 182 insertions(+), 61 deletions(-) diff --git a/Editor/RangeSliderEditor.cs b/Editor/RangeSliderEditor.cs index 516d5ab..df0ba53 100644 --- a/Editor/RangeSliderEditor.cs +++ b/Editor/RangeSliderEditor.cs @@ -12,6 +12,7 @@ namespace UnityEngine.UI.Extensions [CanEditMultipleObjects] public class RangeSliderEditor : SelectableEditor { + SerializedProperty m_Direction; SerializedProperty m_LowHandleRect; SerializedProperty m_HighHandleRect; SerializedProperty m_FillRect; @@ -36,6 +37,7 @@ namespace UnityEngine.UI.Extensions m_LowHandleRect = serializedObject.FindProperty("m_LowHandleRect"); m_HighHandleRect = serializedObject.FindProperty("m_HighHandleRect"); m_FillRect = serializedObject.FindProperty("m_FillRect"); + m_Direction = serializedObject.FindProperty("m_Direction"); m_MinValue = serializedObject.FindProperty("m_MinValue"); m_MaxValue = serializedObject.FindProperty("m_MaxValue"); @@ -66,6 +68,16 @@ namespace UnityEngine.UI.Extensions if (m_LowHandleRect.objectReferenceValue != null && m_HighHandleRect.objectReferenceValue != null) { EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(m_Direction); + if (EditorGUI.EndChangeCheck()) + { + RangeSlider.Direction direction = (RangeSlider.Direction)m_Direction.enumValueIndex; + foreach (var obj in serializedObject.targetObjects) + { + RangeSlider rangeSlider = obj as RangeSlider; + rangeSlider.SetDirection(direction, true); + } + } EditorGUILayout.PropertyField(m_MinValue); EditorGUILayout.PropertyField(m_MaxValue); @@ -120,4 +132,3 @@ namespace UnityEngine.UI.Extensions } } - diff --git a/Runtime/Scripts/Controls/RangeSlider.cs b/Runtime/Scripts/Controls/RangeSlider.cs index b43401a..d21d337 100644 --- a/Runtime/Scripts/Controls/RangeSlider.cs +++ b/Runtime/Scripts/Controls/RangeSlider.cs @@ -14,45 +14,124 @@ namespace UnityEngine.UI.Extensions [RequireComponent(typeof(RectTransform))] public class RangeSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement { + public enum Direction + { + Horizontal, + Vertical + } [Serializable] - public class RangeSliderEvent : UnityEvent { } + public class RangeSliderEvent : UnityEvent + { + } - [SerializeField] - private RectTransform m_FillRect; + [SerializeField] private RectTransform m_FillRect; - public RectTransform FillRect { get { return m_FillRect; } set { if (SetClass(ref m_FillRect, value)) { UpdateCachedReferences(); UpdateVisuals(); } } } + public RectTransform FillRect + { + get { return m_FillRect; } + set + { + if (SetClass(ref m_FillRect, value)) + { + UpdateCachedReferences(); + UpdateVisuals(); + } + } + } - [SerializeField] - private RectTransform m_LowHandleRect; + [SerializeField] private RectTransform m_LowHandleRect; - public RectTransform LowHandleRect { get { return m_LowHandleRect; } set { if (SetClass(ref m_LowHandleRect, value)) { UpdateCachedReferences(); UpdateVisuals(); } } } + public RectTransform LowHandleRect + { + get { return m_LowHandleRect; } + set + { + if (SetClass(ref m_LowHandleRect, value)) + { + UpdateCachedReferences(); + UpdateVisuals(); + } + } + } - [SerializeField] - private RectTransform m_HighHandleRect; + [SerializeField] private RectTransform m_HighHandleRect; - public RectTransform HighHandleRect { get { return m_HighHandleRect; } set { if (SetClass(ref m_HighHandleRect, value)) { UpdateCachedReferences(); UpdateVisuals(); } } } + public RectTransform HighHandleRect + { + get { return m_HighHandleRect; } + set + { + if (SetClass(ref m_HighHandleRect, value)) + { + UpdateCachedReferences(); + UpdateVisuals(); + } + } + } - [Space] + [Space] [SerializeField] private Direction m_Direction = Direction.Horizontal; - [SerializeField] - private float m_MinValue = 0; + public Direction direction + { + get { return m_Direction; } + set + { + if (SetPropertyUtility.SetStruct(ref m_Direction, value)) UpdateVisuals(); + } + } - public float MinValue { get { return m_MinValue; } set { if (SetStruct(ref m_MinValue, value)) { SetLow(m_LowValue); SetHigh(m_HighValue); UpdateVisuals(); } } } + [SerializeField] private float m_MinValue = 0; + + public float MinValue + { + get { return m_MinValue; } + set + { + if (SetStruct(ref m_MinValue, value)) + { + SetLow(m_LowValue); + SetHigh(m_HighValue); + UpdateVisuals(); + } + } + } - [SerializeField] - private float m_MaxValue = 1; + [SerializeField] private float m_MaxValue = 1; - public float MaxValue { get { return m_MaxValue; } set { if (SetStruct(ref m_MaxValue, value)) { SetLow(m_LowValue); SetHigh(m_HighValue); UpdateVisuals(); } } } + public float MaxValue + { + get { return m_MaxValue; } + set + { + if (SetStruct(ref m_MaxValue, value)) + { + SetLow(m_LowValue); + SetHigh(m_HighValue); + UpdateVisuals(); + } + } + } - [SerializeField] - private bool m_WholeNumbers = false; + [SerializeField] private bool m_WholeNumbers = false; - public bool WholeNumbers { get { return m_WholeNumbers; } set { if (SetStruct(ref m_WholeNumbers, value)) { SetLow(m_LowValue); SetHigh(m_HighValue); UpdateVisuals(); } } } + public bool WholeNumbers + { + get { return m_WholeNumbers; } + set + { + if (SetStruct(ref m_WholeNumbers, value)) + { + SetLow(m_LowValue); + SetHigh(m_HighValue); + UpdateVisuals(); + } + } + } + + [SerializeField] private float m_LowValue; - [SerializeField] - private float m_LowValue; public virtual float LowValue { get @@ -78,6 +157,7 @@ namespace UnityEngine.UI.Extensions { return 0; } + return Mathf.InverseLerp(MinValue, MaxValue, LowValue); } set @@ -87,8 +167,8 @@ namespace UnityEngine.UI.Extensions } - [SerializeField] - private float m_HighValue; + [SerializeField] private float m_HighValue; + public virtual float HighValue { get @@ -114,6 +194,7 @@ namespace UnityEngine.UI.Extensions { return 0; } + return Mathf.InverseLerp(MinValue, MaxValue, HighValue); } set @@ -132,10 +213,7 @@ namespace UnityEngine.UI.Extensions SetHigh(high, false); } - [Space] - - [SerializeField] - private RangeSliderEvent m_OnValueChanged = new RangeSliderEvent(); + [Space] [SerializeField] private RangeSliderEvent m_OnValueChanged = new RangeSliderEvent(); public RangeSliderEvent OnValueChanged { get { return m_OnValueChanged; } set { m_OnValueChanged = value; } } @@ -162,10 +240,8 @@ namespace UnityEngine.UI.Extensions private Transform m_LowHandleTransform; private RectTransform m_LowHandleContainerRect; - // The offset from handle position to mouse down position - private Vector2 m_LowOffset = Vector2.zero; - // The offset from handle position to mouse down position - private Vector2 m_HighOffset = Vector2.zero; + // The offset from interacted component position to mouse down position + private Vector2 m_Offset = Vector2.zero; private DrivenRectTransformTracker m_Tracker; @@ -176,7 +252,8 @@ namespace UnityEngine.UI.Extensions float StepSize { get { return WholeNumbers ? 1 : (MaxValue - MinValue) * 0.1f; } } protected RangeSlider() - { } + { + } #if UNITY_EDITOR protected override void OnValidate() @@ -219,13 +296,15 @@ namespace UnityEngine.UI.Extensions /// See ICanvasElement.LayoutComplete /// public virtual void LayoutComplete() - { } + { + } /// /// See ICanvasElement.GraphicUpdateComplete /// public virtual void GraphicUpdateComplete() - { } + { + } public static bool SetClass(ref T currentValue, T newValue) where T : class { @@ -321,7 +400,7 @@ namespace UnityEngine.UI.Extensions m_LowHandleContainerRect = null; } } - + void SetLow(float input) { SetLow(input, true); @@ -388,6 +467,13 @@ namespace UnityEngine.UI.Extensions UpdateVisuals(); } + enum Axis + { + Horizontal = 0, + Vertical = 1 + } + + Axis axis { get { return m_Direction == Direction.Horizontal ? Axis.Horizontal : Axis.Vertical; } } // Force-update the slider. Useful if you've changed the properties and want it to update visually. private void UpdateVisuals() @@ -407,8 +493,8 @@ namespace UnityEngine.UI.Extensions //this is where some new magic must happen. Slider just uses a filled image //and changes the % of fill. We must move the image anchors to be between the two handles. - anchorMin[0] = NormalizedLowValue; - anchorMax[0] = NormalizedHighValue; + anchorMin[(int)axis] = NormalizedLowValue; + anchorMax[(int)axis] = NormalizedHighValue; m_FillRect.anchorMin = anchorMin; m_FillRect.anchorMax = anchorMax; @@ -419,7 +505,7 @@ namespace UnityEngine.UI.Extensions m_Tracker.Add(this, m_LowHandleRect, DrivenTransformProperties.Anchors); Vector2 anchorMin = Vector2.zero; Vector2 anchorMax = Vector2.one; - anchorMin[0] = anchorMax[0] = NormalizedLowValue; + anchorMin[(int)axis] = anchorMax[(int)axis] = NormalizedLowValue; m_LowHandleRect.anchorMin = anchorMin; m_LowHandleRect.anchorMax = anchorMax; } @@ -429,7 +515,7 @@ namespace UnityEngine.UI.Extensions m_Tracker.Add(this, m_HighHandleRect, DrivenTransformProperties.Anchors); Vector2 anchorMin = Vector2.zero; Vector2 anchorMax = Vector2.one; - anchorMin[0] = anchorMax[0] = NormalizedHighValue; + anchorMin[(int)axis] = anchorMax[(int)axis] = NormalizedHighValue; m_HighHandleRect.anchorMin = anchorMin; m_HighHandleRect.anchorMax = anchorMax; } @@ -446,10 +532,10 @@ namespace UnityEngine.UI.Extensions switch (interactionState) { case InteractionState.Low: - NormalizedLowValue = CalculateDrag(eventData, cam, m_LowHandleContainerRect, m_LowOffset); + NormalizedLowValue = CalculateDrag(eventData, cam, m_LowHandleContainerRect); break; case InteractionState.High: - NormalizedHighValue = CalculateDrag(eventData, cam, m_HighHandleContainerRect, m_HighOffset); + NormalizedHighValue = CalculateDrag(eventData, cam, m_HighHandleContainerRect); break; case InteractionState.Bar: //special case @@ -460,35 +546,40 @@ namespace UnityEngine.UI.Extensions } } - private float CalculateDrag(PointerEventData eventData, Camera cam, RectTransform containerRect, Vector2 offset) - { + private float CalculateDrag(PointerEventData eventData, Camera cam, RectTransform containerRect) + { RectTransform clickRect = containerRect ?? m_FillContainerRect; - if (clickRect != null && clickRect.rect.size[0] > 0) + if (clickRect != null && clickRect.rect.size[(int)axis] > 0) { Vector2 localCursor; - if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, out localCursor)) + if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, + out localCursor)) { return 0f; } + localCursor -= clickRect.rect.position; - float val = Mathf.Clamp01((localCursor - offset)[0] / clickRect.rect.size[0]); + float val = Mathf.Clamp01((localCursor - m_Offset)[(int)axis] / clickRect.rect.size[(int)axis]); return val; } + return 0; } private void CalculateBarDrag(PointerEventData eventData, Camera cam) { RectTransform clickRect = m_FillContainerRect; - if (clickRect != null && clickRect.rect.size[0] > 0) + if (clickRect != null && clickRect.rect.size[(int)axis] > 0) { Vector2 localCursor; - if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, out localCursor)) + if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, + out localCursor)) { return; } + localCursor -= clickRect.rect.position; //now we need to get the delta drag on the bar @@ -497,9 +588,9 @@ namespace UnityEngine.UI.Extensions if (NormalizedLowValue >= 0 && NormalizedHighValue <= 1) { //find the mid point on the current bar - float mid = (NormalizedHighValue + NormalizedLowValue)/2; + float mid = (NormalizedHighValue + NormalizedLowValue) / 2; //find where the new mid point should be - float val = Mathf.Clamp01((localCursor)[0] / clickRect.rect.size[0]); + float val = Mathf.Clamp01((localCursor - m_Offset)[(int)axis] / clickRect.rect.size[(int)axis]); //calculate the delta float delta = val - mid; //check the clamp range @@ -529,9 +620,8 @@ namespace UnityEngine.UI.Extensions if (!MayDrag(eventData)) return; - //HANDLE DRAG EVENTS - m_LowOffset = m_HighOffset = Vector2.zero; + m_Offset = Vector2.zero; if(m_LowHandleRect != null && LowValue == MaxValue && RectTransformUtility.RectangleContainsScreenPoint(m_LowHandleRect, eventData.position, eventData.enterEventCamera)) { SetToMoveLowValueHandle(m_LowHandleRect, eventData); @@ -544,19 +634,27 @@ namespace UnityEngine.UI.Extensions { SetToMoveLowValueHandle(m_LowHandleRect, eventData); } - else + else if (m_FillRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_FillRect, eventData.position, eventData.enterEventCamera)) { - //outside the handles, move the entire slider along - UpdateDrag(eventData, eventData.pressEventCamera); - if (eventData.pointerCurrentRaycast.gameObject == m_FillRect.gameObject) + if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_FillRect, eventData.position, eventData.pressEventCamera, out var localMousePos)) { - interactionState = InteractionState.Bar; + m_Offset = localMousePos; } + + interactionState = InteractionState.Bar; + + if (transition == Transition.ColorTint) { targetGraphic = m_FillImage; } } + else + { + //outside the handles, move the entire slider along + UpdateDrag(eventData, eventData.pressEventCamera); + } + base.OnPointerDown(eventData); } @@ -565,7 +663,7 @@ namespace UnityEngine.UI.Extensions //dragging the low value handle if (RectTransformUtility.ScreenPointToLocalPointInRectangle(transform, eventData.position, eventData.pressEventCamera, out var localMousePos)) { - m_LowOffset = localMousePos; + m_Offset = localMousePos; } interactionState = InteractionState.Low; if (transition == Transition.ColorTint) @@ -579,7 +677,7 @@ namespace UnityEngine.UI.Extensions //dragging the low value handle if (RectTransformUtility.ScreenPointToLocalPointInRectangle(transform, eventData.position, eventData.pressEventCamera, out var localMousePos)) { - m_HighOffset = localMousePos; + m_Offset = localMousePos; } interactionState = InteractionState.High; if (transition == Transition.ColorTint) @@ -613,5 +711,17 @@ namespace UnityEngine.UI.Extensions { eventData.useDragThreshold = false; } + + public void SetDirection(Direction direction, bool includeRectLayouts) + { + Axis oldAxis = axis; + this.direction = direction; + + if (!includeRectLayouts) + return; + + if (axis != oldAxis) + RectTransformUtility.FlipLayoutAxes(transform as RectTransform, true, true); + } } } From 771c7776c057f8e3eac1cadb8309fbdea1d06a2f Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 11:45:32 +0100 Subject: [PATCH 12/82] Taking in fix from https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/132 --- Runtime/Scripts/Primitives/UILineRenderer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Scripts/Primitives/UILineRenderer.cs b/Runtime/Scripts/Primitives/UILineRenderer.cs index 590bdba..6f2f093 100644 --- a/Runtime/Scripts/Primitives/UILineRenderer.cs +++ b/Runtime/Scripts/Primitives/UILineRenderer.cs @@ -466,7 +466,7 @@ namespace UnityEngine.UI.Extensions protected override void OnEnable() { base.OnEnable(); - if (m_points?.Length == 0) + if (m_points == null || m_points?.Length == 0) { m_points = new Vector2[1]; } From 3582824afa3ec3d45f59e10e5de06af8a720f129 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 11:49:46 +0100 Subject: [PATCH 13/82] Applying PR manually, because Bitbucket https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/128 --- .../Controls/ReorderableList/ReorderableListElement.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs index b8768dc..8cba2f9 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs @@ -381,16 +381,19 @@ namespace UnityEngine.UI.Extensions ToList = _currentReorderableListRaycasted, ToIndex = _fakeElement.GetSiblingIndex() }; + //Send OnelementDropped Event if (_reorderableList && _reorderableList.OnElementDropped != null) { _reorderableList.OnElementDropped.Invoke(args); } - if (!isValid) + + if (!isValid || (!IsTransferable && _currentReorderableListRaycasted != _reorderableList)) { CancelDrag(); return; } + RefreshSizes(); _draggingObject.SetParent(_currentReorderableListRaycasted.Content, false); _draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation; From 30b65fb9797dc9d3ec54dc631c88bd7ef3b699b6 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 11:53:17 +0100 Subject: [PATCH 14/82] Merged in fix manually because... Bitbucket https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/130 --- Runtime/Scripts/Effects/NicerOutline.cs | 133 ++++++++++++------------ 1 file changed, 69 insertions(+), 64 deletions(-) diff --git a/Runtime/Scripts/Effects/NicerOutline.cs b/Runtime/Scripts/Effects/NicerOutline.cs index 039444e..9755c0b 100644 --- a/Runtime/Scripts/Effects/NicerOutline.cs +++ b/Runtime/Scripts/Effects/NicerOutline.cs @@ -1,5 +1,6 @@ -/// Credit Melang +/// Credit Melang, Lee Hui /// Sourced from - http://forum.unity3d.com/members/melang.593409/ +/// GC Alloc fix - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/pull-requests/130 using System.Collections.Generic; namespace UnityEngine.UI.Extensions @@ -89,42 +90,7 @@ namespace UnityEngine.UI.Extensions } } } - - protected void ApplyShadowZeroAlloc(List verts, Color32 color, int start, int end, float x, float y) - { - UIVertex vt; - - var neededCpacity = verts.Count * 2; - if (verts.Capacity < neededCpacity) - verts.Capacity = neededCpacity; - - for (int i = start; i < end; ++i) - { - vt = verts[i]; - verts.Add(vt); - - Vector3 v = vt.position; - v.x += x; - v.y += y; - vt.position = v; - var newColor = color; - if (m_UseGraphicAlpha) - newColor.a = (byte)((newColor.a * verts[i].color.a) / 255); - vt.color = newColor; - verts[i] = vt; - } - } - - protected void ApplyShadow(List verts, Color32 color, int start, int end, float x, float y) - { - var neededCpacity = verts.Count * 2; - if (verts.Capacity < neededCpacity) - verts.Capacity = neededCpacity; - - ApplyShadowZeroAlloc(verts, color, start, end, x, y); - } - - + public override void ModifyMesh(VertexHelper vh) { if (!this.IsActive ()) @@ -148,36 +114,75 @@ namespace UnityEngine.UI.Extensions float distanceX = this.effectDistance.x * best_fit_adjustment; float distanceY = this.effectDistance.y * best_fit_adjustment; + vh.Clear(); + int start = 0; - int count = m_Verts.Count; - this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, distanceY); - start = count; - count = m_Verts.Count; - this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, -distanceY); - start = count; - count = m_Verts.Count; - this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, distanceY); - start = count; - count = m_Verts.Count; - this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, -distanceY); - start = count; - count = m_Verts.Count; - this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, 0); - start = count; - count = m_Verts.Count; - this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, 0); + // Apply Outline + start += this.ApplyOutlineNoGC(m_Verts, this.effectColor, distanceX, distanceY, vh, start); + start += this.ApplyOutlineNoGC(m_Verts, this.effectColor, distanceX, -distanceY, vh, start); + start += this.ApplyOutlineNoGC(m_Verts, this.effectColor, -distanceX, distanceY, vh, start); + start += this.ApplyOutlineNoGC(m_Verts, this.effectColor, -distanceX, -distanceY, vh, start); + start += this.ApplyOutlineNoGC(m_Verts, this.effectColor, distanceX, 0, vh, start); + start += this.ApplyOutlineNoGC(m_Verts, this.effectColor, -distanceX, 0, vh, start); + start += this.ApplyOutlineNoGC(m_Verts, this.effectColor, 0, distanceY, vh, start); + start += this.ApplyOutlineNoGC(m_Verts, this.effectColor, 0, -distanceY, vh, start); - start = count; - count = m_Verts.Count; - this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, 0, distanceY); - start = count; - count = m_Verts.Count; - this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, 0, -distanceY); - - vh.Clear(); - vh.AddUIVertexTriangleStream(m_Verts); + // Apply self Text stuff + start += ApplyText(m_Verts, vh, start); } + + private int ApplyOutlineNoGC(List verts, Color color, float x, float y, VertexHelper vh, int startIndex) + { + int length = verts.Count; + for (int i = 0; i < length; ++i) + { + UIVertex vt = verts[i]; + + Vector3 v = vt.position; + v.x += x; + v.y += y; + vt.position = v; + var newColor = color; + if (m_UseGraphicAlpha) + newColor.a = (byte)((newColor.a * verts[i].color.a) / 255); + vt.color = newColor; + + // Tips: Since two triangles share same two vertices, in theory vertices can reduce to 4 / 6 + // But VertexHelper.FillMesh forbid, so leave it be. + + vh.AddVert(vt); + } + + int triangleCount = length / 3; + for(int i=0; i verts, VertexHelper vh, int startIndex) + { + int length = verts.Count; + + for (int i = 0; i < length; ++i) + { + vh.AddVert(verts[i]); + } + + int triangleCount = length / 3; + for (int i = 0; i < triangleCount; ++i) + { + int start = startIndex + 3 * i; + vh.AddTriangle(start + 0, start + 1, start + 2); + } + + return length; + } + #if UNITY_EDITOR protected override void OnValidate () @@ -187,4 +192,4 @@ namespace UnityEngine.UI.Extensions } #endif } -} +} \ No newline at end of file From 142582847b187139281edcf9288ff24b13180888 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 14:59:49 +0100 Subject: [PATCH 15/82] Remove old BitBucket Pipeline for GitHub --- bitbucket-pipelines.yml | 18 ------------------ bitbucket-pipelines.yml.meta | 7 ------- 2 files changed, 25 deletions(-) delete mode 100644 bitbucket-pipelines.yml delete mode 100644 bitbucket-pipelines.yml.meta diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml deleted file mode 100644 index 36b5dd1..0000000 --- a/bitbucket-pipelines.yml +++ /dev/null @@ -1,18 +0,0 @@ -# This is a sample build configuration for Other. -# Check our guides at https://confluence.atlassian.com/x/5Q4SMw for more examples. -# Only use spaces to indent your .yml configuration. -# ----- -# You can specify a custom docker image from Docker Hub as your build environment. -image: atlassian/default-image:2 - -pipelines: - custom: - npmpublish: - - step: - script: - - echo "Getting Submodules" - - git submodule update --init --recursive - - echo "Publishing Unity UI Extensions to NPM" - - pipe: atlassian/npm-publish:0.3.1 - variables: - NPM_TOKEN: $NPM_TOKEN \ No newline at end of file diff --git a/bitbucket-pipelines.yml.meta b/bitbucket-pipelines.yml.meta deleted file mode 100644 index 4464a74..0000000 --- a/bitbucket-pipelines.yml.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 8045f74f29fafa944b1539a3a1c6dc5c -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From fc6ea6089d4c494b1c1c62334b51db75f0519410 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 23 Apr 2022 21:01:37 +0100 Subject: [PATCH 16/82] 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 17/82] 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 18/82] 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 19/82] 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 20/82] 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) From 8004bcf39ba29e465edcb121361b6cd8fc634d57 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 27 Nov 2022 13:51:39 +0000 Subject: [PATCH 21/82] Updated #if filter inclusion to 2019_1_OR_Newer resolves: - https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/411 --- Runtime/Scripts/Effects/UIParticleSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Scripts/Effects/UIParticleSystem.cs b/Runtime/Scripts/Effects/UIParticleSystem.cs index b9c4981..3a7ddbf 100644 --- a/Runtime/Scripts/Effects/UIParticleSystem.cs +++ b/Runtime/Scripts/Effects/UIParticleSystem.cs @@ -223,7 +223,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) From c5a8af63f8e1fb778a63505f129051900dc306e8 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 27 Nov 2022 14:32:16 +0000 Subject: [PATCH 22/82] Updated UIVertical scroller to be 2022 compliant Resolves: - https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/410 --- Runtime/Scripts/Layout/UIVerticalScroller.cs | 14 +++++++++++++- Runtime/UnityUIExtensions.asmdef | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Runtime/Scripts/Layout/UIVerticalScroller.cs b/Runtime/Scripts/Layout/UIVerticalScroller.cs index cad0e86..60e3b2c 100644 --- a/Runtime/Scripts/Layout/UIVerticalScroller.cs +++ b/Runtime/Scripts/Layout/UIVerticalScroller.cs @@ -191,7 +191,19 @@ namespace UnityEngine.UI.Extensions if (minDistance == distance[i]) { focusedElementIndex = i; - result = _arrayOfElements[i].GetComponentInChildren().text; +#if UNITY_2022_1_OR_NEWER + var textComponentTxtMeshPro = _arrayOfElements[i].GetComponentInChildren(); + if (textComponentTxtMeshPro != null) + { + result = textComponentTxtMeshPro.text; + } +#else + var textComponent = _arrayOfElements[i].GetComponentInChildren(); + if (textComponent != null) + { + result = textComponent.text; + } +#endif } } if (focusedElementIndex != oldFocusedElement && OnFocusChanged != null) diff --git a/Runtime/UnityUIExtensions.asmdef b/Runtime/UnityUIExtensions.asmdef index f9b5f8a..4fa1840 100644 --- a/Runtime/UnityUIExtensions.asmdef +++ b/Runtime/UnityUIExtensions.asmdef @@ -1,8 +1,10 @@ { "name": "UnityUIExtensions", + "rootNamespace": "", "references": [ "GUID:2bafac87e7f4b9b418d9448d219b01ab", - "GUID:75469ad4d38634e559750d17036d5f7c" + "GUID:75469ad4d38634e559750d17036d5f7c", + "GUID:6055be8ebefd69e48b49212b09b47b2f" ], "includePlatforms": [], "excludePlatforms": [], From c2ada36c41bb00a242b59178fdb687e8343ad4c8 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 27 Nov 2022 15:14:52 +0000 Subject: [PATCH 23/82] Updated Curly UI to wait until end of the frame to recalculate positions Also updated Editor script to work in 2022 Resolves: - https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/409 --- Editor/CUIImageEditor.cs | 5 +++++ Runtime/Scripts/Effects/CurlyUI/CUIGraphic.cs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/Editor/CUIImageEditor.cs b/Editor/CUIImageEditor.cs index c961d07..a3eb6f1 100644 --- a/Editor/CUIImageEditor.cs +++ b/Editor/CUIImageEditor.cs @@ -68,7 +68,12 @@ namespace UnityEngine.UI.Extensions Handles.color = Color.gray; EditorGUI.BeginChangeCheck(); +#if UNITY_2022_1_OR_NEWER + Vector3 newCornerPos = Handles.FreeMoveHandle(script.transform.TransformPoint(cornerPos), HandleUtility.GetHandleSize(script.transform.TransformPoint(cornerPos)) / 7, Vector3.one, Handles.SphereHandleCap); +#else Vector3 newCornerPos = Handles.FreeMoveHandle(script.transform.TransformPoint(cornerPos), script.transform.rotation, HandleUtility.GetHandleSize(script.transform.TransformPoint(cornerPos)) / 7, Vector3.one, Handles.SphereHandleCap); +#endif + Handles.Label(newCornerPos, string.Format("Corner Mover")); newCornerPos = script.transform.InverseTransformPoint(newCornerPos); diff --git a/Runtime/Scripts/Effects/CurlyUI/CUIGraphic.cs b/Runtime/Scripts/Effects/CurlyUI/CUIGraphic.cs index dbdc39b..60cd5f4 100644 --- a/Runtime/Scripts/Effects/CurlyUI/CUIGraphic.cs +++ b/Runtime/Scripts/Effects/CurlyUI/CUIGraphic.cs @@ -1,6 +1,7 @@ /// Credit Titinious (https://github.com/Titinious) /// Sourced from - https://github.com/Titinious/CurlyUI +using System.Collections; using System.Collections.Generic; #if UNITY_EDITOR @@ -286,6 +287,13 @@ namespace UnityEngine.UI.Extensions public void Refresh() { + StartCoroutine(RefreshOnNextFrame()); + } + + public IEnumerator RefreshOnNextFrame() + { + yield return new WaitForEndOfFrame(); + ReportSet(); // we use local position as the true value. Ratio position follows it, so it should be updated when refresh From 3dbd9261cd984e567a2a2972ce63923338af871f Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 27 Nov 2022 16:28:14 +0000 Subject: [PATCH 24/82] Updated Depth Texture sampler in UI Particles Shaders Resolves: - https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/401 --- Runtime/Resources/Shaders/UI Particle Add.shader | 2 +- Runtime/Resources/Shaders/UI Particle AddMultiply.shader | 2 +- Runtime/Resources/Shaders/UI Particle AddSmooth.shader | 5 ++--- Runtime/Resources/Shaders/UI Particle Alpha Blend.shader | 5 ++--- Runtime/Resources/Shaders/UI Particle Blend.shader | 5 ++--- Runtime/Resources/Shaders/UI Particle Multiply.shader | 5 ++--- Runtime/Resources/Shaders/UI Particle MultiplyDouble.shader | 5 ++--- .../Resources/Shaders/UI Particle Premultiply Blend.shader | 5 ++--- .../Resources/Shaders/UI Particle VertexLit Blended.shader | 2 +- 9 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Runtime/Resources/Shaders/UI Particle Add.shader b/Runtime/Resources/Shaders/UI Particle Add.shader index f1017e3..1c63363 100644 --- a/Runtime/Resources/Shaders/UI Particle Add.shader +++ b/Runtime/Resources/Shaders/UI Particle Add.shader @@ -82,7 +82,7 @@ Category { return v; } - sampler2D_float _CameraDepthTexture; + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); float _InvFade; fixed4 frag (v2f IN) : SV_Target diff --git a/Runtime/Resources/Shaders/UI Particle AddMultiply.shader b/Runtime/Resources/Shaders/UI Particle AddMultiply.shader index 7cd819a..e0e0df3 100644 --- a/Runtime/Resources/Shaders/UI Particle AddMultiply.shader +++ b/Runtime/Resources/Shaders/UI Particle AddMultiply.shader @@ -82,7 +82,7 @@ Category { return v; } - sampler2D_float _CameraDepthTexture; + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); float _InvFade; fixed4 frag (v2f i) : SV_Target diff --git a/Runtime/Resources/Shaders/UI Particle AddSmooth.shader b/Runtime/Resources/Shaders/UI Particle AddSmooth.shader index b12bf2d..1d3d576 100644 --- a/Runtime/Resources/Shaders/UI Particle AddSmooth.shader +++ b/Runtime/Resources/Shaders/UI Particle AddSmooth.shader @@ -2,8 +2,7 @@ Shader "UI Extensions/Particles/Additive (Soft)" { Properties { _MainTex ("Particle Texture", 2D) = "white" {} _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0 - - _StencilComp ("Stencil Comparison", Float) = 8 + _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 @@ -81,7 +80,7 @@ Category { return v; } - sampler2D_float _CameraDepthTexture; + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); float _InvFade; fixed4 frag (v2f i) : SV_Target diff --git a/Runtime/Resources/Shaders/UI Particle Alpha Blend.shader b/Runtime/Resources/Shaders/UI Particle Alpha Blend.shader index 3b76f8e..f5b00b9 100644 --- a/Runtime/Resources/Shaders/UI Particle Alpha Blend.shader +++ b/Runtime/Resources/Shaders/UI Particle Alpha Blend.shader @@ -3,8 +3,7 @@ Properties { _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5) _MainTex ("Particle Texture", 2D) = "white" {} _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0 - - _StencilComp ("Stencil Comparison", Float) = 8 + _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 @@ -82,7 +81,7 @@ Category { return v; } - sampler2D_float _CameraDepthTexture; + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); float _InvFade; fixed4 frag (v2f i) : SV_Target diff --git a/Runtime/Resources/Shaders/UI Particle Blend.shader b/Runtime/Resources/Shaders/UI Particle Blend.shader index f6e08a6..6276bd1 100644 --- a/Runtime/Resources/Shaders/UI Particle Blend.shader +++ b/Runtime/Resources/Shaders/UI Particle Blend.shader @@ -2,8 +2,7 @@ Shader "UI Extensions/Particles/Blend" { Properties { _MainTex ("Particle Texture", 2D) = "white" {} _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0 - - _StencilComp ("Stencil Comparison", Float) = 8 + _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 @@ -81,7 +80,7 @@ Category { return v; } - sampler2D_float _CameraDepthTexture; + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); float _InvFade; fixed4 frag (v2f i) : SV_Target diff --git a/Runtime/Resources/Shaders/UI Particle Multiply.shader b/Runtime/Resources/Shaders/UI Particle Multiply.shader index 8e4770e..1d2c940 100644 --- a/Runtime/Resources/Shaders/UI Particle Multiply.shader +++ b/Runtime/Resources/Shaders/UI Particle Multiply.shader @@ -2,8 +2,7 @@ Shader "UI Extensions/Particles/Multiply" { Properties { _MainTex ("Particle Texture", 2D) = "white" {} _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0 - - _StencilComp ("Stencil Comparison", Float) = 8 + _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 @@ -80,7 +79,7 @@ Category { return v; } - sampler2D_float _CameraDepthTexture; + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); float _InvFade; fixed4 frag (v2f i) : SV_Target diff --git a/Runtime/Resources/Shaders/UI Particle MultiplyDouble.shader b/Runtime/Resources/Shaders/UI Particle MultiplyDouble.shader index c8ec832..24dae3c 100644 --- a/Runtime/Resources/Shaders/UI Particle MultiplyDouble.shader +++ b/Runtime/Resources/Shaders/UI Particle MultiplyDouble.shader @@ -2,8 +2,7 @@ Shader "UI Extensions/Particles/Multiply (Double)" { Properties { _MainTex ("Particle Texture", 2D) = "white" {} _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0 - - _StencilComp ("Stencil Comparison", Float) = 8 + _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 @@ -81,7 +80,7 @@ Category { return v; } - sampler2D_float _CameraDepthTexture; + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); float _InvFade; fixed4 frag (v2f i) : SV_Target diff --git a/Runtime/Resources/Shaders/UI Particle Premultiply Blend.shader b/Runtime/Resources/Shaders/UI Particle Premultiply Blend.shader index 10d0ff1..5672889 100644 --- a/Runtime/Resources/Shaders/UI Particle Premultiply Blend.shader +++ b/Runtime/Resources/Shaders/UI Particle Premultiply Blend.shader @@ -3,8 +3,7 @@ Properties { _MainTex ("Particle Texture", 2D) = "white" {} _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0 - - _StencilComp ("Stencil Comparison", Float) = 8 + _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 @@ -82,7 +81,7 @@ Category { return v; } - sampler2D_float _CameraDepthTexture; + UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); float _InvFade; fixed4 frag (v2f IN) : SV_Target diff --git a/Runtime/Resources/Shaders/UI Particle VertexLit Blended.shader b/Runtime/Resources/Shaders/UI Particle VertexLit Blended.shader index 4b5738e..c0f5e79 100644 --- a/Runtime/Resources/Shaders/UI Particle VertexLit Blended.shader +++ b/Runtime/Resources/Shaders/UI Particle VertexLit Blended.shader @@ -3,7 +3,7 @@ Properties { _EmisColor ("Emissive Color", Color) = (.2,.2,.2,0) _MainTex ("Particle Texture", 2D) = "white" {} - _StencilComp ("Stencil Comparison", Float) = 8 + _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 From ebbed378367236f2e43ad18328d9338400cdce2e Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 27 Nov 2022 16:42:34 +0000 Subject: [PATCH 25/82] Remove meta duplicates for HSVColour Picker --- Editor/BoxSliderEditor.cs.meta | 12 ------------ .../Controls/ColorPicker/ColorPickerTester.cs.meta | 8 -------- .../ColorPicker/Events/ColorChangedEvent.cs.meta | 8 -------- .../ColorPicker/Events/HSVChangedEvent.cs.meta | 12 ------------ Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta | 8 -------- 5 files changed, 48 deletions(-) delete mode 100644 Editor/BoxSliderEditor.cs.meta delete mode 100644 Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta delete mode 100644 Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta delete mode 100644 Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta delete mode 100644 Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta diff --git a/Editor/BoxSliderEditor.cs.meta b/Editor/BoxSliderEditor.cs.meta deleted file mode 100644 index fa47eba..0000000 --- a/Editor/BoxSliderEditor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 8701e045b26e51f4eb345f2ccb3c13f5 -timeCreated: 1426804458 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta b/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta deleted file mode 100644 index 9c93c12..0000000 --- a/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 06851a815227e5044b0e3c1bf9b3a282 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta b/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta deleted file mode 100644 index 00f3361..0000000 --- a/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: ff46fbecea7739f4690e4285c88f53c5 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta b/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta deleted file mode 100644 index ea9714b..0000000 --- a/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 3d95ce8fba3dbbf4eb14411412169b88 -timeCreated: 1442747317 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta b/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta deleted file mode 100644 index f84f89a..0000000 --- a/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 4f3189246d7fc204faba7a1e9c08e0af -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: From 7de501c42b32b08e50bff5527e810ec0fbcc5398 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 27 Nov 2022 16:44:25 +0000 Subject: [PATCH 26/82] Add newly generated HSV picker meta files --- Editor/BoxSliderEditor.cs.meta | 11 +++++++++++ .../Controls/ColorPicker/ColorPickerTester.cs.meta | 11 +++++++++++ .../ColorPicker/Events/ColorChangedEvent.cs.meta | 11 +++++++++++ .../ColorPicker/Events/HSVChangedEvent.cs.meta | 11 +++++++++++ Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta | 11 +++++++++++ 5 files changed, 55 insertions(+) create mode 100644 Editor/BoxSliderEditor.cs.meta create mode 100644 Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta create mode 100644 Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta create mode 100644 Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta create mode 100644 Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta diff --git a/Editor/BoxSliderEditor.cs.meta b/Editor/BoxSliderEditor.cs.meta new file mode 100644 index 0000000..4c82edc --- /dev/null +++ b/Editor/BoxSliderEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8701e045b26e51f4eb345f2ccb3c13f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta b/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta new file mode 100644 index 0000000..8a8f3b2 --- /dev/null +++ b/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 06851a815227e5044b0e3c1bf9b3a282 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta b/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta new file mode 100644 index 0000000..3fafa19 --- /dev/null +++ b/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ff46fbecea7739f4690e4285c88f53c5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta b/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta new file mode 100644 index 0000000..b0bdaa6 --- /dev/null +++ b/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d95ce8fba3dbbf4eb14411412169b88 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta b/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta new file mode 100644 index 0000000..fc2cc8b --- /dev/null +++ b/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f3189246d7fc204faba7a1e9c08e0af +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From c08a91f421f075bee632afe8763e489ee7e1fcde Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 27 Nov 2022 16:54:19 +0000 Subject: [PATCH 27/82] Hard reset of Colour picker guids --- Editor/BoxSliderEditor.cs.meta | 2 +- Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta | 2 +- .../Controls/ColorPicker/Events/ColorChangedEvent.cs.meta | 2 +- .../Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta | 2 +- Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Editor/BoxSliderEditor.cs.meta b/Editor/BoxSliderEditor.cs.meta index 4c82edc..9e12253 100644 --- a/Editor/BoxSliderEditor.cs.meta +++ b/Editor/BoxSliderEditor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8701e045b26e51f4eb345f2ccb3c13f5 +guid: c1047f9974e7ee1478bbf5490a7a62d8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta b/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta index 8a8f3b2..d624319 100644 --- a/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta +++ b/Runtime/Scripts/Controls/ColorPicker/ColorPickerTester.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 06851a815227e5044b0e3c1bf9b3a282 +guid: dea5b3bc15f78d04d8dcae27500f784e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta b/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta index 3fafa19..4a37c38 100644 --- a/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta +++ b/Runtime/Scripts/Controls/ColorPicker/Events/ColorChangedEvent.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ff46fbecea7739f4690e4285c88f53c5 +guid: 9d3cae3318559ae449731a7db00c9bdd MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta b/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta index b0bdaa6..9b71656 100644 --- a/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta +++ b/Runtime/Scripts/Controls/ColorPicker/Events/HSVChangedEvent.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3d95ce8fba3dbbf4eb14411412169b88 +guid: 97950dcfb7ac51c4c95431d68ad7bea5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta b/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta index fc2cc8b..1113ee8 100644 --- a/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta +++ b/Runtime/Scripts/Controls/ColorPicker/HSVUtil.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4f3189246d7fc204faba7a1e9c08e0af +guid: 0e93d154602ed7e4787f2a7b9d3101b0 MonoImporter: externalObjects: {} serializedVersion: 2 From 00b67b70464096bdee58109da83e2c4ca0e75fb6 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 18 Dec 2022 18:09:58 +0000 Subject: [PATCH 28/82] Updated Points to always be an array of 1 when set to nothing. Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/295 --- Runtime/Scripts/Primitives/UILineRenderer.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Runtime/Scripts/Primitives/UILineRenderer.cs b/Runtime/Scripts/Primitives/UILineRenderer.cs index 6f2f093..d3b5d3d 100644 --- a/Runtime/Scripts/Primitives/UILineRenderer.cs +++ b/Runtime/Scripts/Primitives/UILineRenderer.cs @@ -111,10 +111,18 @@ namespace UnityEngine.UI.Extensions set { - if (m_points == value) - return; - m_points = value; - SetAllDirty(); + if (m_points == value) return; + + if (value == null || value.Length == 0) + { + m_points = new Vector2[1]; + } + else + { + m_points = value; + } + + SetAllDirty(); } } From 85ee380ee97f7bc15cc05202264f57378f9c9735 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sun, 18 Dec 2022 19:29:40 +0000 Subject: [PATCH 29/82] Updated Cooldown button to work with Keyboard input Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/171 --- Runtime/Scripts/Controls/CooldownButton.cs | 39 +++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/Runtime/Scripts/Controls/CooldownButton.cs b/Runtime/Scripts/Controls/CooldownButton.cs index 502362b..0d9e8b6 100644 --- a/Runtime/Scripts/Controls/CooldownButton.cs +++ b/Runtime/Scripts/Controls/CooldownButton.cs @@ -7,15 +7,14 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { [AddComponentMenu("UI/Extensions/Cooldown Button")] - public class CooldownButton : MonoBehaviour, IPointerDownHandler + public class CooldownButton : MonoBehaviour, IPointerDownHandler, ISubmitHandler { #region Sub-Classes [System.Serializable] - public class CooldownButtonEvent : UnityEvent { } + public class CooldownButtonEvent : UnityEvent { } #endregion #region Private variables - [SerializeField] private float cooldownTimeout; [SerializeField] @@ -33,7 +32,7 @@ namespace UnityEngine.UI.Extensions [SerializeField][ReadOnly] private int cooldownPercentComplete; - PointerEventData buttonSource; + BaseEventData buttonSource; #endregion #region Public Properties @@ -116,7 +115,6 @@ namespace UnityEngine.UI.Extensions #endregion #region Public Methods - /// /// Pause Cooldown without resetting values, allows Restarting of cooldown /// @@ -144,9 +142,9 @@ namespace UnityEngine.UI.Extensions /// public void StartCooldown() { - PointerEventData emptySource = new PointerEventData(EventSystem.current); + BaseEventData emptySource = new BaseEventData(EventSystem.current); buttonSource = emptySource; - OnCooldownStart.Invoke(emptySource.button); + OnCooldownStart.Invoke(emptySource.selectedObject); cooldownTimeRemaining = cooldownTimeout; CooldownActive = cooldownInEffect = true; } @@ -161,7 +159,7 @@ namespace UnityEngine.UI.Extensions cooldownPercentRemaining = 0; cooldownPercentComplete = 100; cooldownActive = cooldownInEffect = false; - if (OnCoolDownFinish != null) OnCoolDownFinish.Invoke(buttonSource.button); + OnCoolDownFinish?.Invoke(buttonSource.selectedObject); } /// @@ -171,27 +169,38 @@ namespace UnityEngine.UI.Extensions { cooldownActive = cooldownInEffect = false; } - #endregion #region IPointerDownHandler - void IPointerDownHandler.OnPointerDown(PointerEventData eventData) + { + HandleButtonClick(eventData); + } + #endregion + + #region ISubmitHandler + public void OnSubmit(BaseEventData eventData) + { + HandleButtonClick(eventData); + } + #endregion ISubmitHandler + + #region Private Methods + public void HandleButtonClick(BaseEventData eventData) { buttonSource = eventData; + if (CooldownInEffect) { - if (OnButtonClickDuringCooldown != null) OnButtonClickDuringCooldown.Invoke(eventData.button); + OnButtonClickDuringCooldown?.Invoke(buttonSource.selectedObject); } if (!CooldownInEffect) { - if(OnCooldownStart != null) OnCooldownStart.Invoke(eventData.button); + OnCooldownStart?.Invoke(buttonSource.selectedObject); cooldownTimeRemaining = cooldownTimeout; cooldownActive = cooldownInEffect = true; } } - - #endregion - + #endregion Private Methods } } \ No newline at end of file From a31766326821a8b0d78f7b7f49d1a7288003f49f Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 12:44:23 +0000 Subject: [PATCH 30/82] Added error handling around setting Unity UI Components for Vertical/Horizontal scrolling Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/296 --- Runtime/Scripts/Layout/HorizontalScrollSnap.cs | 10 +++++++++- Runtime/Scripts/Layout/VerticalScrollSnap.cs | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs index f6de775..365c1a9 100644 --- a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs @@ -114,12 +114,20 @@ namespace UnityEngine.UI.Extensions /// Should the world position be updated to it's parent transform? public void AddChild(GameObject GO, bool WorldPositionStays) { - _scroll_rect.horizontalNormalizedPosition = 0; + try + { + // Rare instances of Unity bug cause error, adding try to manage it. + _scroll_rect.horizontalNormalizedPosition = 0; + } + catch { } + GO.transform.SetParent(_screensContainer, WorldPositionStays); InitialiseChildObjectsFromScene(); DistributePages(); if (MaskArea) + { UpdateVisible(); + } SetScrollContainerPosition(); } diff --git a/Runtime/Scripts/Layout/VerticalScrollSnap.cs b/Runtime/Scripts/Layout/VerticalScrollSnap.cs index 58bde93..4493d8b 100644 --- a/Runtime/Scripts/Layout/VerticalScrollSnap.cs +++ b/Runtime/Scripts/Layout/VerticalScrollSnap.cs @@ -114,7 +114,13 @@ namespace UnityEngine.UI.Extensions /// Should the world position be updated to it's parent transform? public void AddChild(GameObject GO, bool WorldPositionStays) { - _scroll_rect.verticalNormalizedPosition = 0; + try + { + // Rare instances of Unity bug cause error, adding try to manage it. + _scroll_rect.verticalNormalizedPosition = 0; + } + catch { } + GO.transform.SetParent(_screensContainer, WorldPositionStays); InitialiseChildObjectsFromScene(); DistributePages(); From 35c778f5f7bf0f5836a31b32564fec837380cba3 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 12:45:31 +0000 Subject: [PATCH 31/82] Protecting Remove too --- Runtime/Scripts/Layout/HorizontalScrollSnap.cs | 7 ++++++- Runtime/Scripts/Layout/VerticalScrollSnap.cs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs index 365c1a9..9fc2a4c 100644 --- a/Runtime/Scripts/Layout/HorizontalScrollSnap.cs +++ b/Runtime/Scripts/Layout/HorizontalScrollSnap.cs @@ -157,7 +157,12 @@ namespace UnityEngine.UI.Extensions { return; } - _scroll_rect.horizontalNormalizedPosition = 0; + try + { + // Rare instances of Unity bug cause error, adding try to manage it. + _scroll_rect.horizontalNormalizedPosition = 0; + } + catch { } Transform child = _screensContainer.transform.GetChild(index); child.SetParent(null, WorldPositionStays); diff --git a/Runtime/Scripts/Layout/VerticalScrollSnap.cs b/Runtime/Scripts/Layout/VerticalScrollSnap.cs index 4493d8b..2b4fe70 100644 --- a/Runtime/Scripts/Layout/VerticalScrollSnap.cs +++ b/Runtime/Scripts/Layout/VerticalScrollSnap.cs @@ -154,7 +154,12 @@ namespace UnityEngine.UI.Extensions { return; } - _scroll_rect.verticalNormalizedPosition = 0; + try + { + // Rare instances of Unity bug cause error, adding try to manage it. + _scroll_rect.verticalNormalizedPosition = 0; + } + catch { } Transform child = _screensContainer.transform.GetChild(index); child.SetParent(null, WorldPositionStays); From 2a37530aeab2594884711d7cc8b3db91f39fea35 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 12:49:39 +0000 Subject: [PATCH 32/82] Added SetArc method to UICircle as requested Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/280 --- Runtime/Scripts/Primitives/UICircle.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Runtime/Scripts/Primitives/UICircle.cs b/Runtime/Scripts/Primitives/UICircle.cs index 8ebd609..3f5fdb4 100644 --- a/Runtime/Scripts/Primitives/UICircle.cs +++ b/Runtime/Scripts/Primitives/UICircle.cs @@ -155,6 +155,12 @@ namespace UnityEngine.UI.Extensions SetVerticesDirty(); } + public void SetArc(float arc) + { + Arc = arc; + SetVerticesDirty(); + } + public void SetArcSteps(int steps) { ArcSteps = steps; From b4d9f08dc4c6ff3be364c2beb14c339f6064db9a Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 12:54:57 +0000 Subject: [PATCH 33/82] Marked ScrollPositionController as Obsolete, users should use the newer Scroller component instead, will be removed in a future release. Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/305 --- Runtime/Scripts/Layout/ScrollPositionController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Scripts/Layout/ScrollPositionController.cs b/Runtime/Scripts/Layout/ScrollPositionController.cs index eb9c4ef..a918bb9 100644 --- a/Runtime/Scripts/Layout/ScrollPositionController.cs +++ b/Runtime/Scripts/Layout/ScrollPositionController.cs @@ -2,11 +2,11 @@ /// Sourced from - https://github.com/setchi/FancyScrollView using System; -using UnityEngine.Events; using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { + [Obsolete("ScrollPositionController has been replaced by the Scroller component", true)] public class ScrollPositionController : UIBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler { [SerializeField] From dced045001d085de6c434ba3d143376f64b9fe07 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 13:02:50 +0000 Subject: [PATCH 34/82] Updated ScrollPositionControllerEditor as obsolete too --- Editor/ScrollPositionControllerEditor.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Editor/ScrollPositionControllerEditor.cs b/Editor/ScrollPositionControllerEditor.cs index e4ae2cc..f56c735 100644 --- a/Editor/ScrollPositionControllerEditor.cs +++ b/Editor/ScrollPositionControllerEditor.cs @@ -3,10 +3,12 @@ // For maintenance, every new [SerializeField] variable in ScrollPositionController must be declared here +using System; using UnityEditor; namespace UnityEngine.UI.Extensions { + [Obsolete("ScrollPositionController has been replaced by the Scroller component", true)] [CustomEditor(typeof(ScrollPositionController))] [CanEditMultipleObjects] public class ScrollPositionControllerEditor : Editor From 18ebf8121d3942e34c92ec7105d5ce1441818f39 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 13:09:26 +0000 Subject: [PATCH 35/82] Removed unneeded size calculation which caused some issues with mixed height/width children. Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/380 --- Runtime/Scripts/Layout/FlowLayoutGroup.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Runtime/Scripts/Layout/FlowLayoutGroup.cs b/Runtime/Scripts/Layout/FlowLayoutGroup.cs index bea7412..c5bad45 100644 --- a/Runtime/Scripts/Layout/FlowLayoutGroup.cs +++ b/Runtime/Scripts/Layout/FlowLayoutGroup.cs @@ -166,7 +166,6 @@ namespace UnityEngine.UI.Extensions childSize = LayoutUtility.GetPreferredSize (child, 0); childSize = Mathf.Min (childSize, workingSize); childOtherSize = LayoutUtility.GetPreferredSize (child, 1); - childOtherSize = Mathf.Min (childOtherSize, workingSize); } else if (startAxis == Axis.Vertical) { if (invertOrder) { index = IsRightAlign ? rectChildren.Count - 1 - i : i; @@ -175,7 +174,6 @@ namespace UnityEngine.UI.Extensions childSize = LayoutUtility.GetPreferredSize (child, 1); childSize = Mathf.Min (childSize, workingSize); childOtherSize = LayoutUtility.GetPreferredSize (child, 0); - childOtherSize = Mathf.Min (childOtherSize, workingSize); } // If adding this element would exceed the bounds of the container, From e78a2806eddd875869b92f9416c5d9a0b95ad331 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 13:20:19 +0000 Subject: [PATCH 36/82] Resolved issue whereby the last row in a flow layout group would not size correctly. Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/357 --- Runtime/Scripts/Layout/FlowLayoutGroup.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/Scripts/Layout/FlowLayoutGroup.cs b/Runtime/Scripts/Layout/FlowLayoutGroup.cs index c5bad45..86eeb13 100644 --- a/Runtime/Scripts/Layout/FlowLayoutGroup.cs +++ b/Runtime/Scripts/Layout/FlowLayoutGroup.cs @@ -225,11 +225,11 @@ namespace UnityEngine.UI.Extensions if (startAxis == Axis.Horizontal) { float newOffset = CalculateRowVerticalOffset (groupHeight, offset, currentBarSpace); currentBarSize -= spacingBetweenElements; - LayoutRow (_itemList, currentBarSize, currentBarSpace, workingSize - (ChildForceExpandWidth ? 0 : spacingBetweenElements), padding.left, newOffset, axis); + LayoutRow (_itemList, currentBarSize, currentBarSpace, workingSize, padding.left, newOffset, axis); }else if (startAxis == Axis.Vertical) { float newOffset = CalculateColHorizontalOffset(groupWidth, offset, currentBarSpace); currentBarSize -= spacingBetweenElements; - LayoutCol(_itemList, currentBarSpace, currentBarSize, workingSize - (ChildForceExpandHeight ? 0 : spacingBetweenElements), newOffset, padding.top, axis); + LayoutCol(_itemList, currentBarSpace, currentBarSize, workingSize, newOffset, padding.top, axis); } } From 3ed20ecaed564c371efa79277a4c5ca4c67efe67 Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 13:28:19 +0000 Subject: [PATCH 37/82] Updated all components using "LayoutGroup" to override their OnDisable feature to incorporate this fix: https://gist.github.com/randomize/73ca6d3b6aa7210073692eb5cabd537e Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/178 --- Runtime/Scripts/Layout/CurvedLayout.cs | 7 +++++++ Runtime/Scripts/Layout/FlowLayoutGroup.cs | 10 +++++++++- Runtime/Scripts/Layout/RadialLayout.cs | 7 +++++++ Runtime/Scripts/Layout/TableLayoutGroup.cs | 6 ++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Runtime/Scripts/Layout/CurvedLayout.cs b/Runtime/Scripts/Layout/CurvedLayout.cs index fdc3637..c3fddc2 100644 --- a/Runtime/Scripts/Layout/CurvedLayout.cs +++ b/Runtime/Scripts/Layout/CurvedLayout.cs @@ -29,6 +29,13 @@ namespace UnityEngine.UI.Extensions public float centerpoint = 0.5f; protected override void OnEnable() { base.OnEnable(); CalculateRadial(); } + + protected override void OnDisable() + { + m_Tracker.Clear(); + LayoutRebuilder.MarkLayoutForRebuild(rectTransform); + } + public override void SetLayoutHorizontal() { } public override void SetLayoutVertical() { diff --git a/Runtime/Scripts/Layout/FlowLayoutGroup.cs b/Runtime/Scripts/Layout/FlowLayoutGroup.cs index 86eeb13..1aaccd9 100644 --- a/Runtime/Scripts/Layout/FlowLayoutGroup.cs +++ b/Runtime/Scripts/Layout/FlowLayoutGroup.cs @@ -422,5 +422,13 @@ namespace UnityEngine.UI.Extensions } return max; } - } + + protected override void OnDisable() + { + m_Tracker.Clear(); + LayoutRebuilder.MarkLayoutForRebuild(rectTransform); + } + + + } } \ No newline at end of file diff --git a/Runtime/Scripts/Layout/RadialLayout.cs b/Runtime/Scripts/Layout/RadialLayout.cs index e7b67f8..fb90cb5 100644 --- a/Runtime/Scripts/Layout/RadialLayout.cs +++ b/Runtime/Scripts/Layout/RadialLayout.cs @@ -55,6 +55,13 @@ namespace UnityEngine.UI.Extensions CalculateRadial(); } #endif + + protected override void OnDisable() + { + m_Tracker.Clear(); // key change - do not restore - false + LayoutRebuilder.MarkLayoutForRebuild(rectTransform); + } + void CalculateRadial() { m_Tracker.Clear(); diff --git a/Runtime/Scripts/Layout/TableLayoutGroup.cs b/Runtime/Scripts/Layout/TableLayoutGroup.cs index f5ca4f1..83ade4e 100644 --- a/Runtime/Scripts/Layout/TableLayoutGroup.cs +++ b/Runtime/Scripts/Layout/TableLayoutGroup.cs @@ -284,5 +284,11 @@ namespace UnityEngine.UI.Extensions // Set preferredRowHeights to null to free memory preferredRowHeights = null; } + + protected override void OnDisable() + { + m_Tracker.Clear(); // key change - do not restore - false + LayoutRebuilder.MarkLayoutForRebuild(rectTransform); + } } } \ No newline at end of file From 2848008f63ab1c8c410cf99c1c1ff6eaf084c41b Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Sat, 24 Dec 2022 14:52:49 +0000 Subject: [PATCH 38/82] Checking in new MinMaxSlider TODO - Finish Editor creator --- Editor/MinMaxSliderEditor.cs | 121 +++ Editor/MinMaxSliderEditor.cs.meta | 11 + Editor/UIExtensionsMenuOptions.cs | 105 ++- Editor/UnityUIExtensions.Editor.asmdef | 7 +- Runtime/Scripts/Controls/Sliders.meta | 8 + .../Controls/{ => Sliders}/BoxSlider.cs | 742 +++++++++--------- .../Controls/{ => Sliders}/BoxSlider.cs.meta | 0 .../Scripts/Controls/Sliders/MinMaxSlider.cs | 347 ++++++++ .../Controls/Sliders/MinMaxSlider.cs.meta | 11 + .../Controls/{ => Sliders}/RadialSlider.cs | 2 +- .../{ => Sliders}/RadialSlider.cs.meta | 0 .../Controls/{ => Sliders}/RangeSlider.cs | 2 +- .../{ => Sliders}/RangeSlider.cs.meta | 0 .../Scripts/Controls/{ => Sliders}/Stepper.cs | 2 +- .../Controls/{ => Sliders}/Stepper.cs.meta | 0 .../Controls/{ => Sliders}/StepperSide.cs | 0 .../{ => Sliders}/StepperSide.cs.meta | 0 Runtime/Scripts/Utilities/MinMaxValues.cs | 50 ++ .../Scripts/Utilities/MinMaxValues.cs.meta | 11 + 19 files changed, 1028 insertions(+), 391 deletions(-) create mode 100644 Editor/MinMaxSliderEditor.cs create mode 100644 Editor/MinMaxSliderEditor.cs.meta create mode 100644 Runtime/Scripts/Controls/Sliders.meta rename Runtime/Scripts/Controls/{ => Sliders}/BoxSlider.cs (96%) rename Runtime/Scripts/Controls/{ => Sliders}/BoxSlider.cs.meta (100%) create mode 100644 Runtime/Scripts/Controls/Sliders/MinMaxSlider.cs create mode 100644 Runtime/Scripts/Controls/Sliders/MinMaxSlider.cs.meta rename Runtime/Scripts/Controls/{ => Sliders}/RadialSlider.cs (99%) rename Runtime/Scripts/Controls/{ => Sliders}/RadialSlider.cs.meta (100%) rename Runtime/Scripts/Controls/{ => Sliders}/RangeSlider.cs (99%) rename Runtime/Scripts/Controls/{ => Sliders}/RangeSlider.cs.meta (100%) rename Runtime/Scripts/Controls/{ => Sliders}/Stepper.cs (99%) rename Runtime/Scripts/Controls/{ => Sliders}/Stepper.cs.meta (100%) rename Runtime/Scripts/Controls/{ => Sliders}/StepperSide.cs (100%) rename Runtime/Scripts/Controls/{ => Sliders}/StepperSide.cs.meta (100%) create mode 100644 Runtime/Scripts/Utilities/MinMaxValues.cs create mode 100644 Runtime/Scripts/Utilities/MinMaxValues.cs.meta diff --git a/Editor/MinMaxSliderEditor.cs b/Editor/MinMaxSliderEditor.cs new file mode 100644 index 0000000..19f6457 --- /dev/null +++ b/Editor/MinMaxSliderEditor.cs @@ -0,0 +1,121 @@ +///Credit brogan89 +///Sourced from - https://github.com/brogan89/MinMaxSlider + +using System; +using UnityEditor; +using UnityEditor.UI; + +namespace UnityEngine.UI.Extensions +{ + [CustomEditor(typeof(MinMaxSlider), true)] + [CanEditMultipleObjects] + public class MinMaxSliderEditor : SelectableEditor + { + private SerializedProperty _customCamera; + private SerializedProperty _sliderBounds; + private SerializedProperty _minHandle; + private SerializedProperty _maxHandle; + private SerializedProperty _minText; + private SerializedProperty _maxText; + private SerializedProperty _textFormat; + private SerializedProperty _middleGraphic; + private SerializedProperty _minLimit; + private SerializedProperty _maxLimit; + private SerializedProperty _wholeNumbers; + private SerializedProperty _minValue; + private SerializedProperty _maxValue; + + private SerializedProperty _onValueChanged; + + private readonly GUIContent label = new GUIContent("Min Max Values"); + + protected override void OnEnable() + { + base.OnEnable(); + _customCamera = serializedObject.FindProperty("customCamera"); + _sliderBounds = serializedObject.FindProperty("sliderBounds"); + _minHandle = serializedObject.FindProperty("minHandle"); + _maxHandle = serializedObject.FindProperty("maxHandle"); + _minText = serializedObject.FindProperty("minText"); + _maxText = serializedObject.FindProperty("maxText"); + _textFormat = serializedObject.FindProperty("textFormat"); + _middleGraphic = serializedObject.FindProperty("middleGraphic"); + _minLimit = serializedObject.FindProperty("minLimit"); + _maxLimit = serializedObject.FindProperty("maxLimit"); + _wholeNumbers = serializedObject.FindProperty("wholeNumbers"); + _minValue = serializedObject.FindProperty("minValue"); + _maxValue = serializedObject.FindProperty("maxValue"); + _onValueChanged = serializedObject.FindProperty("onValueChanged"); + } + + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + + serializedObject.Update(); + + float minLimitOld = _minLimit.floatValue; + float maxLimitOld = _maxLimit.floatValue; + float minValueOld = _minValue.floatValue; + float maxValueOld = _maxValue.floatValue; + + EditorGUILayout.PropertyField(_customCamera); + EditorGUILayout.PropertyField(_sliderBounds); + EditorGUILayout.PropertyField(_minHandle); + EditorGUILayout.PropertyField(_maxHandle); + EditorGUILayout.PropertyField(_middleGraphic); + + EditorGUILayout.PropertyField(_minText); + EditorGUILayout.PropertyField(_maxText); + EditorGUILayout.PropertyField(_textFormat); + + EditorGUILayout.PropertyField(_minLimit); + EditorGUILayout.PropertyField(_maxLimit); + + EditorGUILayout.PropertyField(_wholeNumbers); + EditorGUILayout.PropertyField(_minValue); + EditorGUILayout.PropertyField(_maxValue); + + float minValue = Mathf.Clamp(_minValue.floatValue, _minLimit.floatValue, _maxLimit.floatValue); + float maxValue = Mathf.Clamp(_maxValue.floatValue, _minLimit.floatValue, _maxLimit.floatValue); + EditorGUILayout.MinMaxSlider(label, ref minValue, ref maxValue, _minLimit.floatValue, _maxLimit.floatValue); + + bool anyValueChanged = !IsEqualFloat(minValueOld, minValue) + || !IsEqualFloat(maxValueOld, maxValue) + || !IsEqualFloat(minLimitOld, _minLimit.floatValue) + || !IsEqualFloat(maxLimitOld, _maxLimit.floatValue); + + if (anyValueChanged) + { + MinMaxSlider slider = (MinMaxSlider)target; + + // force limits to ints if whole numbers. + // needed to do this here because it wouldn't set in component script for some reason + if (slider.wholeNumbers) + { + _minLimit.floatValue = Mathf.RoundToInt(_minLimit.floatValue); + _maxLimit.floatValue = Mathf.RoundToInt(_maxLimit.floatValue); + } + + // set slider values + slider.SetValues(minValue, maxValue, _minLimit.floatValue, _maxLimit.floatValue); + } + + EditorGUILayout.Space(); + EditorGUILayout.PropertyField(_onValueChanged); + + serializedObject.ApplyModifiedProperties(); + } + + /// + /// Returns true if floating point numbers are within 0.01f (close enough to be considered equal) + /// + /// + /// + /// + private static bool IsEqualFloat(float a, float b) + { + return Math.Abs(a - b) < 0.01f; + } + } +} \ No newline at end of file diff --git a/Editor/MinMaxSliderEditor.cs.meta b/Editor/MinMaxSliderEditor.cs.meta new file mode 100644 index 0000000..6730b44 --- /dev/null +++ b/Editor/MinMaxSliderEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 69352ed1561021b48ac258f81f48a988 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/UIExtensionsMenuOptions.cs b/Editor/UIExtensionsMenuOptions.cs index b445a7b..9c718c8 100644 --- a/Editor/UIExtensionsMenuOptions.cs +++ b/Editor/UIExtensionsMenuOptions.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using TMPro; +using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using UnityEngine.UI.Extensions; @@ -1847,7 +1848,7 @@ namespace UnityEditor.UI #endregion #region Stepper - [MenuItem("GameObject/UI/Extensions/Stepper", false)] + [MenuItem("GameObject/UI/Extensions/Sliders/Stepper", false)] static public void AddStepper(MenuCommand menuCommand) { GameObject go = CreateUIElementRoot("Stepper", menuCommand, new Vector2(kWidth / 2, kThickHeight)); @@ -1891,7 +1892,7 @@ namespace UnityEditor.UI #endregion #region BoxSlider - [MenuItem("GameObject/UI/Extensions/Box Slider", false)] + [MenuItem("GameObject/UI/Extensions/Sliders/Box Slider", false)] static public void AddBoxSlider(MenuCommand menuCommand) { @@ -1946,7 +1947,7 @@ namespace UnityEditor.UI #endregion #region Radial Slider - [MenuItem("GameObject/UI/Extensions/Radial Slider", false)] + [MenuItem("GameObject/UI/Extensions/Sliders/Radial Slider", false)] static public void AddRadialSlider(MenuCommand menuCommand) { GameObject sliderRoot = CreateUIElementRoot("Radial Slider", menuCommand, s_ThickGUIElementSize); @@ -1984,21 +1985,21 @@ namespace UnityEditor.UI #endregion #region RangeSlider - [MenuItem("GameObject/UI/Extensions/Range Slider", false)] + [MenuItem("GameObject/UI/Extensions/Sliders/Range Slider", false)] static public void AddRangeSlider(MenuCommand menuCommand) { - GameObject rangeSliderRoot = CreateUIElementRoot("Range Slider", menuCommand, new Vector2(160, 20)); + GameObject minMaxSliderRoot = CreateUIElementRoot("Range Slider", menuCommand, new Vector2(160, 20)); - GameObject background = CreateUIObject("Background", rangeSliderRoot); + GameObject background = CreateUIObject("Background", minMaxSliderRoot); - GameObject fillArea = CreateUIObject("Fill Area", rangeSliderRoot); + GameObject fillArea = CreateUIObject("Fill Area", minMaxSliderRoot); GameObject fill = CreateUIObject("Fill", fillArea); - GameObject handleSlideArea = CreateUIObject("Handle Slide Area", rangeSliderRoot); - GameObject lowHandle = CreateUIObject("Low Handle", handleSlideArea); + GameObject handleSlideArea = CreateUIObject("Handle Slide Area", minMaxSliderRoot); + GameObject minHandle = CreateUIObject("Low Handle", handleSlideArea); GameObject highHandle = CreateUIObject("High Handle", handleSlideArea); - SetAnchorsAndStretch(rangeSliderRoot); + SetAnchorsAndStretch(minMaxSliderRoot); Image backgroundImage = background.AddComponent(); backgroundImage.sprite = AssetDatabase.GetBuiltinExtraResource(kBackgroundSpriteResourcePath); backgroundImage.type = Image.Type.Sliced; @@ -2029,8 +2030,8 @@ namespace UnityEditor.UI handleSlideRect.offsetMin = new Vector2(10, -10); handleSlideRect.offsetMax = new Vector2(-10, 10); - RectTransform lowHandleRect = SetAnchorsAndStretch(lowHandle); - Image lowHandleImage = lowHandle.AddComponent(); + RectTransform lowHandleRect = SetAnchorsAndStretch(minHandle); + Image lowHandleImage = minHandle.AddComponent(); lowHandleImage.sprite = AssetDatabase.GetBuiltinExtraResource(kKnobPath); lowHandleRect.sizeDelta = new Vector2(20, 0); @@ -2039,7 +2040,7 @@ namespace UnityEditor.UI highHandleImage.sprite = AssetDatabase.GetBuiltinExtraResource(kKnobPath); highHandleRect.sizeDelta = new Vector2(20, 0); - RangeSlider rangeSlider = rangeSliderRoot.AddComponent(); + RangeSlider rangeSlider = minMaxSliderRoot.AddComponent(); rangeSlider.FillRect = fillRect; rangeSlider.LowHandleRect = lowHandleRect; rangeSlider.HighHandleRect = highHandleRect; @@ -2047,7 +2048,7 @@ namespace UnityEditor.UI rangeSlider.HighValue = rangeSlider.MaxValue; rangeSlider.targetGraphic = fillImage; - Selection.activeGameObject = rangeSliderRoot; + Selection.activeGameObject = minMaxSliderRoot; } #endregion @@ -2062,6 +2063,80 @@ namespace UnityEditor.UI } #endregion + #region MinMaxSlider + [MenuItem("GameObject/UI/Extensions/Sliders/MinMax Slider", false)] + static public void AddMinMaxSlider(MenuCommand menuCommand) + { + GameObject minMaxSliderRoot = CreateUIElementRoot("MinMax Slider", menuCommand, new Vector2(390, 60)); + + //GameObject background = CreateUIObject("Background", rangeSliderRoot); + + GameObject sliderBounds = CreateUIObject("Slider Bounds", minMaxSliderRoot); + GameObject middleGraphic = CreateUIObject("Middle Graphic", minMaxSliderRoot); + + GameObject minHandle = CreateUIObject("Min Handle", minMaxSliderRoot); + GameObject minHandleText = CreateUIObject("Min Text", minHandle); + GameObject maxHandle = CreateUIObject("Max Handle", minMaxSliderRoot); + GameObject maxHandleText = CreateUIObject("Max Text", maxHandle); + + SetAnchorsAndStretch(minMaxSliderRoot); + Image backgroundImage = minMaxSliderRoot.AddComponent(); + backgroundImage.sprite = AssetDatabase.GetBuiltinExtraResource(kStandardSpritePath); + backgroundImage.type = Image.Type.Sliced; + backgroundImage.fillCenter = false; + backgroundImage.color = new Color(27, 41, 89); + + RectTransform backgroundRect = backgroundImage.rectTransform; + backgroundRect.anchorMin = new Vector2(0.5f, 0.5f); + backgroundRect.anchorMax = new Vector2(0.5f, 0.5f); + backgroundRect.sizeDelta = Vector2.zero; + + RectTransform sliderBoundsRect = SetAnchorsAndStretch(sliderBounds); + sliderBoundsRect.anchorMin = new Vector2(0, 0); + sliderBoundsRect.anchorMax = new Vector2(1, 1); + + RectTransform middleGraphicRect = SetAnchorsAndStretch(middleGraphic); + Image fillImage = middleGraphic.AddComponent(); + fillImage.sprite = AssetDatabase.GetBuiltinExtraResource(kStandardSpritePath); + fillImage.type = Image.Type.Sliced; + fillImage.fillCenter = true; + fillImage.color = new Color(41, 98, 164); + + RectTransform minHandleRect = SetAnchorsAndStretch(minHandle); + Image lowHandleImage = minHandle.AddComponent(); + lowHandleImage.sprite = AssetDatabase.GetBuiltinExtraResource(kStandardSpritePath); + minHandleRect.sizeDelta = new Vector2(30, 62); + + RectTransform minHandleTextRect = SetAnchorsAndStretch(minHandleText); + TextMeshProUGUI minHandleTextComponent = minHandleText.AddComponent(); + minHandleTextComponent.text = "0"; + minHandleTextComponent.fontSize = 36; + minHandleTextRect.sizeDelta = new Vector2(70, 50); + minHandleTextRect.position = new Vector3(0, -60,0); + + RectTransform maxHandleRect = SetAnchorsAndStretch(maxHandle); + Image maxHandleImage = maxHandle.AddComponent(); + maxHandleImage.sprite = AssetDatabase.GetBuiltinExtraResource(kStandardSpritePath); + maxHandleRect.sizeDelta = new Vector2(20, 0); + + RectTransform maxHandleTextRect = SetAnchorsAndStretch(maxHandleText); + TextMeshProUGUI maxHandleTextComponent = maxHandleText.AddComponent(); + maxHandleTextComponent.text = "0"; + maxHandleTextComponent.fontSize = 36; + maxHandleTextRect.sizeDelta = new Vector2(70, 50); + maxHandleTextRect.position = new Vector3(0, -60, 0); + + MinMaxSlider minMaxSlider = minMaxSliderRoot.AddComponent(); + minMaxSlider.SliderBounds = sliderBoundsRect; + minMaxSlider.MinHandle = minHandleRect; + minMaxSlider.MaxHandle = maxHandleRect; + minMaxSlider.MiddleGraphic = middleGraphicRect; + minMaxSlider.MinText = minHandleTextComponent; + minMaxSlider.MaxText = maxHandleTextComponent; + + Selection.activeGameObject = minMaxSliderRoot; + } + #endregion #endregion diff --git a/Editor/UnityUIExtensions.Editor.asmdef b/Editor/UnityUIExtensions.Editor.asmdef index a6ccce7..568a7e8 100644 --- a/Editor/UnityUIExtensions.Editor.asmdef +++ b/Editor/UnityUIExtensions.Editor.asmdef @@ -1,9 +1,11 @@ { "name": "UnityUIExtensions.editor", + "rootNamespace": "", "references": [ "GUID:343deaaf83e0cee4ca978e7df0b80d21", "GUID:2bafac87e7f4b9b418d9448d219b01ab", - "GUID:cf414061cae3a954baf92763590f3127" + "GUID:cf414061cae3a954baf92763590f3127", + "GUID:6055be8ebefd69e48b49212b09b47b2f" ], "includePlatforms": [ "Editor" @@ -14,5 +16,6 @@ "precompiledReferences": [], "autoReferenced": true, "defineConstraints": [], - "versionDefines": [] + "versionDefines": [], + "noEngineReferences": false } \ No newline at end of file diff --git a/Runtime/Scripts/Controls/Sliders.meta b/Runtime/Scripts/Controls/Sliders.meta new file mode 100644 index 0000000..6ae79ac --- /dev/null +++ b/Runtime/Scripts/Controls/Sliders.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d7bdc7e70331fe24aba2c9549f84c657 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Controls/BoxSlider.cs b/Runtime/Scripts/Controls/Sliders/BoxSlider.cs similarity index 96% rename from Runtime/Scripts/Controls/BoxSlider.cs rename to Runtime/Scripts/Controls/Sliders/BoxSlider.cs index dca4608..9360300 100644 --- a/Runtime/Scripts/Controls/BoxSlider.cs +++ b/Runtime/Scripts/Controls/Sliders/BoxSlider.cs @@ -1,371 +1,371 @@ -///Credit judah4 -///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/ - -using System; -using UnityEngine.Events; -using UnityEngine.EventSystems; - -namespace UnityEngine.UI.Extensions -{ - [RequireComponent(typeof(RectTransform))] - [AddComponentMenu("UI/Extensions/BoxSlider")] - public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement - { - public enum Direction - { - LeftToRight, - RightToLeft, - BottomToTop, - TopToBottom, - } - - [Serializable] - public class BoxSliderEvent : UnityEvent { } - - [SerializeField] - private RectTransform m_HandleRect; - public RectTransform HandleRect { get { return m_HandleRect; } set { if (SetClass(ref m_HandleRect, value)) { UpdateCachedReferences(); UpdateVisuals(); } } } - - [Space(6)] - - [SerializeField] - private float m_MinValue = 0; - public float MinValue { get { return m_MinValue; } set { if (SetStruct(ref m_MinValue, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } } - - [SerializeField] - private float m_MaxValue = 1; - public float MaxValue { get { return m_MaxValue; } set { if (SetStruct(ref m_MaxValue, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } } - - [SerializeField] - private bool m_WholeNumbers = false; - public bool WholeNumbers { get { return m_WholeNumbers; } set { if (SetStruct(ref m_WholeNumbers, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } } - - [SerializeField] - private float m_ValueX = 1f; - public float ValueX - { - get - { - if (WholeNumbers) - return Mathf.Round(m_ValueX); - return m_ValueX; - } - set - { - SetX(value); - } - } - - public float NormalizedValueX - { - get - { - if (Mathf.Approximately(MinValue, MaxValue)) - return 0; - return Mathf.InverseLerp(MinValue, MaxValue, ValueX); - } - set - { - this.ValueX = Mathf.Lerp(MinValue, MaxValue, value); - } - } - - [SerializeField] - private float m_ValueY = 1f; - public float ValueY - { - get - { - if (WholeNumbers) - return Mathf.Round(m_ValueY); - return m_ValueY; - } - set - { - SetY(value); - } - } - - public float NormalizedValueY - { - get - { - if (Mathf.Approximately(MinValue, MaxValue)) - return 0; - return Mathf.InverseLerp(MinValue, MaxValue, ValueY); - } - set - { - this.ValueY = Mathf.Lerp(MinValue, MaxValue, value); - } - } - - [Space(6)] - - // Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers. - [SerializeField] - private BoxSliderEvent m_OnValueChanged = new BoxSliderEvent(); - public BoxSliderEvent OnValueChanged { get { return m_OnValueChanged; } set { m_OnValueChanged = value; } } - - // Private fields - - private Transform m_HandleTransform; - private RectTransform m_HandleContainerRect; - - // The offset from handle position to mouse down position - private Vector2 m_Offset = Vector2.zero; - - private DrivenRectTransformTracker m_Tracker; - - // Size of each step. - float StepSize { get { return WholeNumbers ? 1 : (MaxValue - MinValue) * 0.1f; } } - - protected BoxSlider() - { } - -#if UNITY_EDITOR - protected override void OnValidate() - { - base.OnValidate(); - - if (WholeNumbers) - { - m_MinValue = Mathf.Round(m_MinValue); - m_MaxValue = Mathf.Round(m_MaxValue); - } - UpdateCachedReferences(); - SetX(m_ValueX, false); - SetY(m_ValueY, false); - // Update rects since other things might affect them even if value didn't change. - if(!Application.isPlaying) UpdateVisuals(); - -#if UNITY_2018_3_OR_NEWER - if (!Application.isPlaying) -#else - var prefabType = UnityEditor.PrefabUtility.GetPrefabType(this); - if (prefabType != UnityEditor.PrefabType.Prefab && !Application.isPlaying) -#endif - { - CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this); - } - } - -#endif // if UNITY_EDITOR - - public virtual void Rebuild(CanvasUpdate executing) - { -#if UNITY_EDITOR - if (executing == CanvasUpdate.Prelayout) - OnValueChanged.Invoke(ValueX, ValueY); -#endif - } - - public void LayoutComplete() - { - - } - - public void GraphicUpdateComplete() - { - - } - - public static bool SetClass(ref T currentValue, T newValue) where T : class - { - if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue))) - return false; - - currentValue = newValue; - return true; - } - - public static bool SetStruct(ref T currentValue, T newValue) where T : struct - { - if (currentValue.Equals(newValue)) - return false; - - currentValue = newValue; - return true; - } - - protected override void OnEnable() - { - base.OnEnable(); - UpdateCachedReferences(); - SetX(m_ValueX, false); - SetY(m_ValueY, false); - // Update rects since they need to be initialized correctly. - UpdateVisuals(); - } - - protected override void OnDisable() - { - m_Tracker.Clear(); - base.OnDisable(); - } - - void UpdateCachedReferences() - { - - if (m_HandleRect) - { - m_HandleTransform = m_HandleRect.transform; - if (m_HandleTransform.parent != null) - m_HandleContainerRect = m_HandleTransform.parent.GetComponent(); - } - else - { - m_HandleContainerRect = null; - } - } - - // Set the valueUpdate the visible Image. - void SetX(float input) - { - SetX(input, true); - } - - void SetX(float input, bool sendCallback) - { - // Clamp the input - float newValue = Mathf.Clamp(input, MinValue, MaxValue); - if (WholeNumbers) - newValue = Mathf.Round(newValue); - - // If the stepped value doesn't match the last one, it's time to update - if (m_ValueX == newValue) - return; - - m_ValueX = newValue; - UpdateVisuals(); - if (sendCallback) - m_OnValueChanged.Invoke(newValue, ValueY); - } - - void SetY(float input) - { - SetY(input, true); - } - - void SetY(float input, bool sendCallback) - { - // Clamp the input - float newValue = Mathf.Clamp(input, MinValue, MaxValue); - if (WholeNumbers) - newValue = Mathf.Round(newValue); - - // If the stepped value doesn't match the last one, it's time to update - if (m_ValueY == newValue) - return; - - m_ValueY = newValue; - UpdateVisuals(); - if (sendCallback) - m_OnValueChanged.Invoke(ValueX, newValue); - } - - - protected override void OnRectTransformDimensionsChange() - { - base.OnRectTransformDimensionsChange(); - UpdateVisuals(); - } - - enum Axis - { - Horizontal = 0, - Vertical = 1 - } - - - // Force-update the slider. Useful if you've changed the properties and want it to update visually. - private void UpdateVisuals() - { -#if UNITY_EDITOR - if (!Application.isPlaying) - UpdateCachedReferences(); -#endif - - m_Tracker.Clear(); - - - //to business! - if (m_HandleContainerRect != null) - { - m_Tracker.Add(this, m_HandleRect, DrivenTransformProperties.Anchors); - Vector2 anchorMin = Vector2.zero; - Vector2 anchorMax = Vector2.one; - anchorMin[0] = anchorMax[0] = (NormalizedValueX); - anchorMin[1] = anchorMax[1] = (NormalizedValueY); - - if (Application.isPlaying) - { - m_HandleRect.anchorMin = anchorMin; - m_HandleRect.anchorMax = anchorMax; - } - - } - } - - // Update the slider's position based on the mouse. - void UpdateDrag(PointerEventData eventData, Camera cam) - { - RectTransform clickRect = m_HandleContainerRect; - if (clickRect != null && clickRect.rect.size[0] > 0) - { - Vector2 localCursor; - if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, out localCursor)) - return; - localCursor -= clickRect.rect.position; - - float val = Mathf.Clamp01((localCursor - m_Offset)[0] / clickRect.rect.size[0]); - NormalizedValueX = (val); - - float valY = Mathf.Clamp01((localCursor - m_Offset)[1] / clickRect.rect.size[1]); - NormalizedValueY = (valY); - - } - } - - private bool CanDrag(PointerEventData eventData) - { - return IsActive() && IsInteractable() && eventData.button == PointerEventData.InputButton.Left; - } - - public override void OnPointerDown(PointerEventData eventData) - { - if (!CanDrag(eventData)) - return; - - base.OnPointerDown(eventData); - - m_Offset = Vector2.zero; - if (m_HandleContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, eventData.position, eventData.enterEventCamera)) - { - Vector2 localMousePos; - if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out localMousePos)) - m_Offset = localMousePos; - m_Offset.y = -m_Offset.y; - } - else - { - // Outside the slider handle - jump to this point instead - UpdateDrag(eventData, eventData.pressEventCamera); - } - } - - public virtual void OnDrag(PointerEventData eventData) - { - if (!CanDrag(eventData)) - return; - - UpdateDrag(eventData, eventData.pressEventCamera); - } - - public virtual void OnInitializePotentialDrag(PointerEventData eventData) - { - eventData.useDragThreshold = false; - } - - } -} +///Credit judah4 +///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/ + +using System; +using UnityEngine.Events; +using UnityEngine.EventSystems; + +namespace UnityEngine.UI.Extensions +{ + [RequireComponent(typeof(RectTransform))] + [AddComponentMenu("UI/Extensions/Sliders/BoxSlider")] + public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement + { + public enum Direction + { + LeftToRight, + RightToLeft, + BottomToTop, + TopToBottom, + } + + [Serializable] + public class BoxSliderEvent : UnityEvent { } + + [SerializeField] + private RectTransform m_HandleRect; + public RectTransform HandleRect { get { return m_HandleRect; } set { if (SetClass(ref m_HandleRect, value)) { UpdateCachedReferences(); UpdateVisuals(); } } } + + [Space(6)] + + [SerializeField] + private float m_MinValue = 0; + public float MinValue { get { return m_MinValue; } set { if (SetStruct(ref m_MinValue, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } } + + [SerializeField] + private float m_MaxValue = 1; + public float MaxValue { get { return m_MaxValue; } set { if (SetStruct(ref m_MaxValue, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } } + + [SerializeField] + private bool m_WholeNumbers = false; + public bool WholeNumbers { get { return m_WholeNumbers; } set { if (SetStruct(ref m_WholeNumbers, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } } + + [SerializeField] + private float m_ValueX = 1f; + public float ValueX + { + get + { + if (WholeNumbers) + return Mathf.Round(m_ValueX); + return m_ValueX; + } + set + { + SetX(value); + } + } + + public float NormalizedValueX + { + get + { + if (Mathf.Approximately(MinValue, MaxValue)) + return 0; + return Mathf.InverseLerp(MinValue, MaxValue, ValueX); + } + set + { + this.ValueX = Mathf.Lerp(MinValue, MaxValue, value); + } + } + + [SerializeField] + private float m_ValueY = 1f; + public float ValueY + { + get + { + if (WholeNumbers) + return Mathf.Round(m_ValueY); + return m_ValueY; + } + set + { + SetY(value); + } + } + + public float NormalizedValueY + { + get + { + if (Mathf.Approximately(MinValue, MaxValue)) + return 0; + return Mathf.InverseLerp(MinValue, MaxValue, ValueY); + } + set + { + this.ValueY = Mathf.Lerp(MinValue, MaxValue, value); + } + } + + [Space(6)] + + // Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers. + [SerializeField] + private BoxSliderEvent m_OnValueChanged = new BoxSliderEvent(); + public BoxSliderEvent OnValueChanged { get { return m_OnValueChanged; } set { m_OnValueChanged = value; } } + + // Private fields + + private Transform m_HandleTransform; + private RectTransform m_HandleContainerRect; + + // The offset from handle position to mouse down position + private Vector2 m_Offset = Vector2.zero; + + private DrivenRectTransformTracker m_Tracker; + + // Size of each step. + float StepSize { get { return WholeNumbers ? 1 : (MaxValue - MinValue) * 0.1f; } } + + protected BoxSlider() + { } + +#if UNITY_EDITOR + protected override void OnValidate() + { + base.OnValidate(); + + if (WholeNumbers) + { + m_MinValue = Mathf.Round(m_MinValue); + m_MaxValue = Mathf.Round(m_MaxValue); + } + UpdateCachedReferences(); + SetX(m_ValueX, false); + SetY(m_ValueY, false); + // Update rects since other things might affect them even if value didn't change. + if(!Application.isPlaying) UpdateVisuals(); + +#if UNITY_2018_3_OR_NEWER + if (!Application.isPlaying) +#else + var prefabType = UnityEditor.PrefabUtility.GetPrefabType(this); + if (prefabType != UnityEditor.PrefabType.Prefab && !Application.isPlaying) +#endif + { + CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this); + } + } + +#endif // if UNITY_EDITOR + + public virtual void Rebuild(CanvasUpdate executing) + { +#if UNITY_EDITOR + if (executing == CanvasUpdate.Prelayout) + OnValueChanged.Invoke(ValueX, ValueY); +#endif + } + + public void LayoutComplete() + { + + } + + public void GraphicUpdateComplete() + { + + } + + public static bool SetClass(ref T currentValue, T newValue) where T : class + { + if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue))) + return false; + + currentValue = newValue; + return true; + } + + public static bool SetStruct(ref T currentValue, T newValue) where T : struct + { + if (currentValue.Equals(newValue)) + return false; + + currentValue = newValue; + return true; + } + + protected override void OnEnable() + { + base.OnEnable(); + UpdateCachedReferences(); + SetX(m_ValueX, false); + SetY(m_ValueY, false); + // Update rects since they need to be initialized correctly. + UpdateVisuals(); + } + + protected override void OnDisable() + { + m_Tracker.Clear(); + base.OnDisable(); + } + + void UpdateCachedReferences() + { + + if (m_HandleRect) + { + m_HandleTransform = m_HandleRect.transform; + if (m_HandleTransform.parent != null) + m_HandleContainerRect = m_HandleTransform.parent.GetComponent(); + } + else + { + m_HandleContainerRect = null; + } + } + + // Set the valueUpdate the visible Image. + void SetX(float input) + { + SetX(input, true); + } + + void SetX(float input, bool sendCallback) + { + // Clamp the input + float newValue = Mathf.Clamp(input, MinValue, MaxValue); + if (WholeNumbers) + newValue = Mathf.Round(newValue); + + // If the stepped value doesn't match the last one, it's time to update + if (m_ValueX == newValue) + return; + + m_ValueX = newValue; + UpdateVisuals(); + if (sendCallback) + m_OnValueChanged.Invoke(newValue, ValueY); + } + + void SetY(float input) + { + SetY(input, true); + } + + void SetY(float input, bool sendCallback) + { + // Clamp the input + float newValue = Mathf.Clamp(input, MinValue, MaxValue); + if (WholeNumbers) + newValue = Mathf.Round(newValue); + + // If the stepped value doesn't match the last one, it's time to update + if (m_ValueY == newValue) + return; + + m_ValueY = newValue; + UpdateVisuals(); + if (sendCallback) + m_OnValueChanged.Invoke(ValueX, newValue); + } + + + protected override void OnRectTransformDimensionsChange() + { + base.OnRectTransformDimensionsChange(); + UpdateVisuals(); + } + + enum Axis + { + Horizontal = 0, + Vertical = 1 + } + + + // Force-update the slider. Useful if you've changed the properties and want it to update visually. + private void UpdateVisuals() + { +#if UNITY_EDITOR + if (!Application.isPlaying) + UpdateCachedReferences(); +#endif + + m_Tracker.Clear(); + + + //to business! + if (m_HandleContainerRect != null) + { + m_Tracker.Add(this, m_HandleRect, DrivenTransformProperties.Anchors); + Vector2 anchorMin = Vector2.zero; + Vector2 anchorMax = Vector2.one; + anchorMin[0] = anchorMax[0] = (NormalizedValueX); + anchorMin[1] = anchorMax[1] = (NormalizedValueY); + + if (Application.isPlaying) + { + m_HandleRect.anchorMin = anchorMin; + m_HandleRect.anchorMax = anchorMax; + } + + } + } + + // Update the slider's position based on the mouse. + void UpdateDrag(PointerEventData eventData, Camera cam) + { + RectTransform clickRect = m_HandleContainerRect; + if (clickRect != null && clickRect.rect.size[0] > 0) + { + Vector2 localCursor; + if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, out localCursor)) + return; + localCursor -= clickRect.rect.position; + + float val = Mathf.Clamp01((localCursor - m_Offset)[0] / clickRect.rect.size[0]); + NormalizedValueX = (val); + + float valY = Mathf.Clamp01((localCursor - m_Offset)[1] / clickRect.rect.size[1]); + NormalizedValueY = (valY); + + } + } + + private bool CanDrag(PointerEventData eventData) + { + return IsActive() && IsInteractable() && eventData.button == PointerEventData.InputButton.Left; + } + + public override void OnPointerDown(PointerEventData eventData) + { + if (!CanDrag(eventData)) + return; + + base.OnPointerDown(eventData); + + m_Offset = Vector2.zero; + if (m_HandleContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, eventData.position, eventData.enterEventCamera)) + { + Vector2 localMousePos; + if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out localMousePos)) + m_Offset = localMousePos; + m_Offset.y = -m_Offset.y; + } + else + { + // Outside the slider handle - jump to this point instead + UpdateDrag(eventData, eventData.pressEventCamera); + } + } + + public virtual void OnDrag(PointerEventData eventData) + { + if (!CanDrag(eventData)) + return; + + UpdateDrag(eventData, eventData.pressEventCamera); + } + + public virtual void OnInitializePotentialDrag(PointerEventData eventData) + { + eventData.useDragThreshold = false; + } + + } +} diff --git a/Runtime/Scripts/Controls/BoxSlider.cs.meta b/Runtime/Scripts/Controls/Sliders/BoxSlider.cs.meta similarity index 100% rename from Runtime/Scripts/Controls/BoxSlider.cs.meta rename to Runtime/Scripts/Controls/Sliders/BoxSlider.cs.meta diff --git a/Runtime/Scripts/Controls/Sliders/MinMaxSlider.cs b/Runtime/Scripts/Controls/Sliders/MinMaxSlider.cs new file mode 100644 index 0000000..0550f13 --- /dev/null +++ b/Runtime/Scripts/Controls/Sliders/MinMaxSlider.cs @@ -0,0 +1,347 @@ +///Credit brogan89 +///Sourced from - https://github.com/brogan89/MinMaxSlider + +using System; +using TMPro; +using UnityEngine.Events; +using UnityEngine.EventSystems; + +namespace UnityEngine.UI.Extensions +{ + [RequireComponent(typeof(RectTransform))] + [AddComponentMenu("UI/Extensions/Sliders/MinMax Slider")] + public class MinMaxSlider : Selectable, IBeginDragHandler, IDragHandler, IEndDragHandler + { + private enum DragState + { + Both, + Min, + Max + } + + [Header("UI Controls")] + [SerializeField] private Camera customCamera = null; + [SerializeField] private RectTransform sliderBounds = null; + [SerializeField] private RectTransform minHandle = null; + [SerializeField] private RectTransform maxHandle = null; + [SerializeField] private RectTransform middleGraphic = null; + + // text components (optional) + [Header("Display Text (Optional)")] + [SerializeField] private TextMeshProUGUI minText = null; + [SerializeField] private TextMeshProUGUI maxText = null; + [SerializeField] private string textFormat = "0"; + + // values + [Header("Limits")] + [SerializeField] private float minLimit = 0; + [SerializeField] private float maxLimit = 100; + + [Header("Values")] + public bool wholeNumbers; + [SerializeField] private float minValue = 25; + [SerializeField] private float maxValue = 75; + + public MinMaxValues Values => new MinMaxValues(minValue, maxValue, minLimit, maxLimit); + + public RectTransform SliderBounds { get => sliderBounds; set => sliderBounds = value; } + public RectTransform MinHandle { get => minHandle; set => minHandle = value; } + public RectTransform MaxHandle { get => maxHandle; set => maxHandle = value; } + public RectTransform MiddleGraphic { get => middleGraphic; set => middleGraphic = value; } + public TextMeshProUGUI MinText { get => minText; set => minText = value; } + public TextMeshProUGUI MaxText { get => maxText; set => maxText = value; } + + /// + /// Event invoked when either slider value has changed + /// + /// T0 = min, T1 = max + /// + [Serializable] + public class SliderEvent : UnityEvent { } + + public SliderEvent onValueChanged = new SliderEvent(); + + private Vector2 dragStartPosition; + private float dragStartMinValue01; + private float dragStartMaxValue01; + private DragState dragState; + private bool passDragEvents; // this allows drag events to be passed through to scrollers + + private Camera mainCamera; + private Canvas parentCanvas; + private bool isOverlayCanvas; + + protected override void Start() + { + base.Start(); + + if (!sliderBounds) + { + sliderBounds = transform as RectTransform; + } + + parentCanvas = GetComponentInParent(); + isOverlayCanvas = parentCanvas.renderMode == RenderMode.ScreenSpaceOverlay; + mainCamera = customCamera != null ? customCamera : Camera.main; + } + + public void SetLimits(float minLimit, float maxLimit) + { + this.minLimit = wholeNumbers ? Mathf.RoundToInt(minLimit) : minLimit; + this.maxLimit = wholeNumbers ? Mathf.RoundToInt(maxLimit) : maxLimit; + } + + public void SetValues(MinMaxValues values, bool notify = true) + { + SetValues(values.minValue, values.maxValue, values.minLimit, values.maxLimit, notify); + } + + public void SetValues(float minValue, float maxValue, bool notify = true) + { + SetValues(minValue, maxValue, minLimit, maxLimit, notify); + } + + public void SetValues(float minValue, float maxValue, float minLimit, float maxLimit, bool notify = true) + { + this.minValue = wholeNumbers ? Mathf.RoundToInt(minValue) : minValue; + this.maxValue = wholeNumbers ? Mathf.RoundToInt(maxValue) : maxValue; + SetLimits(minLimit, maxLimit); + + RefreshSliders(); + UpdateText(); + UpdateMiddleGraphic(); + + if (notify) + { + // event + onValueChanged.Invoke(this.minValue, this.maxValue); + } + } + + private void RefreshSliders() + { + SetSliderAnchors(); + + float clampedMin = Mathf.Clamp(minValue, minLimit, maxLimit); + SetMinHandleValue01(minHandle, GetPercentage(minLimit, maxLimit, clampedMin)); + + float clampedMax = Mathf.Clamp(maxValue, minLimit, maxLimit); + SetMaxHandleValue01(maxHandle, GetPercentage(minLimit, maxLimit, clampedMax)); + } + + private void SetSliderAnchors() + { + minHandle.anchorMin = new Vector2(0, 0.5f); + minHandle.anchorMax = new Vector2(0, 0.5f); + minHandle.pivot = new Vector2(0.5f, 0.5f); + + maxHandle.anchorMin = new Vector2(1, 0.5f); + maxHandle.anchorMax = new Vector2(1, 0.5f); + maxHandle.pivot = new Vector2(0.5f, 0.5f); + } + + private void UpdateText() + { + if (minText) + { + minText.SetText(minValue.ToString(textFormat)); + } + + if (maxText) + { + maxText.SetText(maxValue.ToString(textFormat)); + } + } + + private void UpdateMiddleGraphic() + { + if (!middleGraphic) return; + + middleGraphic.anchorMin = Vector2.zero; + middleGraphic.anchorMax = Vector2.one; + middleGraphic.offsetMin = new Vector2(minHandle.anchoredPosition.x, 0); + middleGraphic.offsetMax = new Vector2(maxHandle.anchoredPosition.x, 0); + } + + #region IDragHandler + public void OnBeginDrag(PointerEventData eventData) + { + passDragEvents = Math.Abs(eventData.delta.x) < Math.Abs(eventData.delta.y); + + if (passDragEvents) + { + PassDragEvents(x => x.OnBeginDrag(eventData)); + } + else + { + Camera uiCamera = isOverlayCanvas ? null : mainCamera; + RectTransformUtility.ScreenPointToLocalPointInRectangle(sliderBounds, eventData.position, uiCamera, out dragStartPosition); + + float dragStartValue = GetValueOfPointInSliderBounds01(dragStartPosition); + dragStartMinValue01 = GetMinHandleValue01(minHandle); + dragStartMaxValue01 = GetMaxHandleValue01(maxHandle); + + // set drag state + if (dragStartValue < dragStartMinValue01 || RectTransformUtility.RectangleContainsScreenPoint(minHandle, eventData.position, uiCamera)) + { + dragState = DragState.Min; + minHandle.SetAsLastSibling(); + } + else if (dragStartValue > dragStartMaxValue01 || RectTransformUtility.RectangleContainsScreenPoint(maxHandle, eventData.position, uiCamera)) + { + dragState = DragState.Max; + maxHandle.SetAsLastSibling(); + } + else + { + dragState = DragState.Both; + } + } + } + + public void OnDrag(PointerEventData eventData) + { + if (passDragEvents) + { + PassDragEvents(x => x.OnDrag(eventData)); + } + else if (minHandle && maxHandle) + { + RectTransformUtility.ScreenPointToLocalPointInRectangle(sliderBounds, eventData.position, isOverlayCanvas ? null : mainCamera, out Vector2 clickPosition); + + SetSliderAnchors(); + + if (dragState == DragState.Min || dragState == DragState.Max) + { + float dragPosition01 = GetValueOfPointInSliderBounds01(clickPosition); + float minHandleValue = GetMinHandleValue01(minHandle); + float maxHandleValue = GetMaxHandleValue01(maxHandle); + + if (dragState == DragState.Min) + SetMinHandleValue01(minHandle, Mathf.Clamp(dragPosition01, 0, maxHandleValue)); + else if (dragState == DragState.Max) + SetMaxHandleValue01(maxHandle, Mathf.Clamp(dragPosition01, minHandleValue, 1)); + } + else + { + float distancePercent = (clickPosition.x - dragStartPosition.x) / sliderBounds.rect.width; + SetMinHandleValue01(minHandle, dragStartMinValue01 + distancePercent); + SetMaxHandleValue01(maxHandle, dragStartMaxValue01 + distancePercent); + } + + // set values + float min = Mathf.Lerp(minLimit, maxLimit, GetMinHandleValue01(minHandle)); + float max = Mathf.Lerp(minLimit, maxLimit, GetMaxHandleValue01(maxHandle)); + SetValues(min, max); + + UpdateText(); + UpdateMiddleGraphic(); + } + } + + public void OnEndDrag(PointerEventData eventData) + { + if (passDragEvents) + { + PassDragEvents(x => x.OnEndDrag(eventData)); + } + else + { + float minHandleValue = GetMinHandleValue01(minHandle); + float maxHandleValue = GetMaxHandleValue01(maxHandle); + + // this safe guards a possible situation where the slides can get stuck + if (Math.Abs(minHandleValue) < MinMaxValues.FLOAT_TOL && Math.Abs(maxHandleValue) < MinMaxValues.FLOAT_TOL) + { + maxHandle.SetAsLastSibling(); + } + else if (Math.Abs(minHandleValue - 1) < MinMaxValues.FLOAT_TOL && Math.Abs(maxHandleValue - 1) < MinMaxValues.FLOAT_TOL) + { + minHandle.SetAsLastSibling(); + } + } + } + #endregion IDragHandler + + private void PassDragEvents(Action callback) where T : IEventSystemHandler + { + Transform parent = transform.parent; + + while (parent != null) + { + foreach (var component in parent.GetComponents()) + { + if (!(component is T)) continue; + + callback.Invoke((T)(IEventSystemHandler)component); + return; + } + + parent = parent.parent; + } + } + + /// + /// Sets position of max handle RectTransform + /// + /// + /// Normalized handle position + private void SetMaxHandleValue01(RectTransform handle, float value01) + { + handle.anchoredPosition = new Vector2(value01 * sliderBounds.rect.width - sliderBounds.rect.width + sliderBounds.offsetMax.x, handle.anchoredPosition.y); + } + + /// + /// Sets position of min handle RectTransform + /// + /// + /// Normalized handle position + private void SetMinHandleValue01(RectTransform handle, float value01) + { + handle.anchoredPosition = new Vector2(value01 * sliderBounds.rect.width + sliderBounds.offsetMin.x, handle.anchoredPosition.y); + } + + /// + /// Returns normalized position of max handle RectTransform + /// + /// + /// Normalized position of max handle RectTransform + private float GetMaxHandleValue01(RectTransform handle) + { + return 1 + (handle.anchoredPosition.x - sliderBounds.offsetMax.x) / sliderBounds.rect.width; + } + + /// + /// Returns normalized position of min handle RectTransform + /// + /// + /// Normalized position of min handle RectTransform + private float GetMinHandleValue01(RectTransform handle) + { + return (handle.anchoredPosition.x - sliderBounds.offsetMin.x) / sliderBounds.rect.width; + } + + /// + /// Returns normalized position of a point in a slider bounds rectangle + /// + /// + /// Normalized position of a point in a slider bounds rectangle + private float GetValueOfPointInSliderBounds01(Vector2 position) + { + var width = sliderBounds.rect.width; + return Mathf.Clamp((position.x + width / 2) / width, 0, 1); + } + + /// + /// Returns percentage of input based on min and max values + /// + /// + /// + /// + /// + private static float GetPercentage(float min, float max, float input) + { + return (input - min) / (max - min); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Controls/Sliders/MinMaxSlider.cs.meta b/Runtime/Scripts/Controls/Sliders/MinMaxSlider.cs.meta new file mode 100644 index 0000000..05e3a83 --- /dev/null +++ b/Runtime/Scripts/Controls/Sliders/MinMaxSlider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b9f9954231c8bab419504a7ac5ff133e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/Controls/RadialSlider.cs b/Runtime/Scripts/Controls/Sliders/RadialSlider.cs similarity index 99% rename from Runtime/Scripts/Controls/RadialSlider.cs rename to Runtime/Scripts/Controls/Sliders/RadialSlider.cs index 7bb5672..669c994 100644 --- a/Runtime/Scripts/Controls/RadialSlider.cs +++ b/Runtime/Scripts/Controls/Sliders/RadialSlider.cs @@ -8,8 +8,8 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { - [AddComponentMenu("UI/Extensions/Radial Slider")] [RequireComponent(typeof(Image))] + [AddComponentMenu("UI/Extensions/Sliders/Radial Slider")] public class RadialSlider : MonoBehaviour, IPointerEnterHandler, IPointerDownHandler, IPointerUpHandler, IDragHandler { private bool isPointerDown, isPointerReleased, lerpInProgress; diff --git a/Runtime/Scripts/Controls/RadialSlider.cs.meta b/Runtime/Scripts/Controls/Sliders/RadialSlider.cs.meta similarity index 100% rename from Runtime/Scripts/Controls/RadialSlider.cs.meta rename to Runtime/Scripts/Controls/Sliders/RadialSlider.cs.meta diff --git a/Runtime/Scripts/Controls/RangeSlider.cs b/Runtime/Scripts/Controls/Sliders/RangeSlider.cs similarity index 99% rename from Runtime/Scripts/Controls/RangeSlider.cs rename to Runtime/Scripts/Controls/Sliders/RangeSlider.cs index d21d337..75e4890 100644 --- a/Runtime/Scripts/Controls/RangeSlider.cs +++ b/Runtime/Scripts/Controls/Sliders/RangeSlider.cs @@ -9,9 +9,9 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { - [AddComponentMenu("UI/Extensions/Range Slider", 34)] [ExecuteInEditMode] [RequireComponent(typeof(RectTransform))] + [AddComponentMenu("UI/Extensions/Sliders/Range Slider", 34)] public class RangeSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement { public enum Direction diff --git a/Runtime/Scripts/Controls/RangeSlider.cs.meta b/Runtime/Scripts/Controls/Sliders/RangeSlider.cs.meta similarity index 100% rename from Runtime/Scripts/Controls/RangeSlider.cs.meta rename to Runtime/Scripts/Controls/Sliders/RangeSlider.cs.meta diff --git a/Runtime/Scripts/Controls/Stepper.cs b/Runtime/Scripts/Controls/Sliders/Stepper.cs similarity index 99% rename from Runtime/Scripts/Controls/Stepper.cs rename to Runtime/Scripts/Controls/Sliders/Stepper.cs index 6d920d8..d7720c6 100644 --- a/Runtime/Scripts/Controls/Stepper.cs +++ b/Runtime/Scripts/Controls/Sliders/Stepper.cs @@ -9,8 +9,8 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { // Stepper control - [AddComponentMenu("UI/Extensions/Stepper")] [RequireComponent(typeof(RectTransform))] + [AddComponentMenu("UI/Extensions/Sliders/Stepper")] public class Stepper : UIBehaviour { private Selectable[] _sides; diff --git a/Runtime/Scripts/Controls/Stepper.cs.meta b/Runtime/Scripts/Controls/Sliders/Stepper.cs.meta similarity index 100% rename from Runtime/Scripts/Controls/Stepper.cs.meta rename to Runtime/Scripts/Controls/Sliders/Stepper.cs.meta diff --git a/Runtime/Scripts/Controls/StepperSide.cs b/Runtime/Scripts/Controls/Sliders/StepperSide.cs similarity index 100% rename from Runtime/Scripts/Controls/StepperSide.cs rename to Runtime/Scripts/Controls/Sliders/StepperSide.cs diff --git a/Runtime/Scripts/Controls/StepperSide.cs.meta b/Runtime/Scripts/Controls/Sliders/StepperSide.cs.meta similarity index 100% rename from Runtime/Scripts/Controls/StepperSide.cs.meta rename to Runtime/Scripts/Controls/Sliders/StepperSide.cs.meta diff --git a/Runtime/Scripts/Utilities/MinMaxValues.cs b/Runtime/Scripts/Utilities/MinMaxValues.cs new file mode 100644 index 0000000..48cb616 --- /dev/null +++ b/Runtime/Scripts/Utilities/MinMaxValues.cs @@ -0,0 +1,50 @@ +///Credit brogan89 +///Sourced from - https://github.com/brogan89/MinMaxSlider + +using System; + +namespace UnityEngine.UI.Extensions +{ + [Serializable] + public struct MinMaxValues + { + /// + /// Floating point tolerance + /// + public const float FLOAT_TOL = 0.01f; + + public float minValue, maxValue, minLimit, maxLimit; + public static MinMaxValues DEFUALT = new MinMaxValues(25, 75, 0, 100); + + public MinMaxValues(float minValue, float maxValue, float minLimit, float maxLimit) + { + this.minValue = minValue; + this.maxValue = maxValue; + this.minLimit = minLimit; + this.maxLimit = maxLimit; + } + + /// + /// Constructor for when values equal limits + /// + /// + /// + public MinMaxValues(float minValue, float maxValue) + { + this.minValue = minValue; + this.maxValue = maxValue; + this.minLimit = minValue; + this.maxLimit = maxValue; + } + + public bool IsAtMinAndMax() + { + return Math.Abs(minValue - minLimit) < FLOAT_TOL && Math.Abs(maxValue - maxLimit) < FLOAT_TOL; + } + + public override string ToString() + { + return $"Values(min:{minValue}, max:{maxValue}) | Limits(min:{minLimit}, max:{maxLimit})"; + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/Utilities/MinMaxValues.cs.meta b/Runtime/Scripts/Utilities/MinMaxValues.cs.meta new file mode 100644 index 0000000..3171a39 --- /dev/null +++ b/Runtime/Scripts/Utilities/MinMaxValues.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 44af036687d1cdb4da5686d3431d2c3c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 4ffa6310591715f740b84af43a7cc33a9ffda89f Mon Sep 17 00:00:00 2001 From: Simon Jackson Date: Fri, 30 Dec 2022 17:54:17 +0000 Subject: [PATCH 39/82] Added Editor Menu Option to create a Min/Max slider Resolves: https://github.com/Unity-UI-Extensions/com.unity.uiextensions/issues/270 --- Editor/UIExtensionsMenuOptions.cs | 856 +++++++++++++++--------------- 1 file changed, 433 insertions(+), 423 deletions(-) diff --git a/Editor/UIExtensionsMenuOptions.cs b/Editor/UIExtensionsMenuOptions.cs index 9c718c8..19048fc 100644 --- a/Editor/UIExtensionsMenuOptions.cs +++ b/Editor/UIExtensionsMenuOptions.cs @@ -6,11 +6,11 @@ using UnityEngine.UI.Extensions; namespace UnityEditor.UI { - /// - /// This script adds the Extensions UI menu options to the Unity Editor. - /// + /// + /// This script adds the Extensions UI menu options to the Unity Editor. + /// - static internal class ExtensionMenuOptions + static internal class ExtensionMenuOptions { #region Unity Builder section - Do not change unless UI Source (Editor\MenuOptions) changes #region Unity Builder properties - Do not change unless UI Source (Editor\MenuOptions) changes @@ -467,119 +467,119 @@ namespace UnityEditor.UI { FixedScrollSnapBase(menuCommand, "Scroll Snap Vertical Multiple", ScrollSnap.ScrollDirection.Vertical, 3, 15, new Vector2(100, 100)); } - #endregion + #endregion - #region ContentScrollSnapHorizontal - [MenuItem("GameObject/UI/Extensions/Content Scroll Snap Horizontal", false)] - static public void AddContentScrollSnapHorizontal(MenuCommand menuCommand) - { - GameObject contentScrollSnapRoot = CreateUIElementRoot("Content Scroll Snap Horizontal", menuCommand, s_ThickGUIElementSize); + #region ContentScrollSnapHorizontal + [MenuItem("GameObject/UI/Extensions/Content Scroll Snap Horizontal", false)] + static public void AddContentScrollSnapHorizontal(MenuCommand menuCommand) + { + GameObject contentScrollSnapRoot = CreateUIElementRoot("Content Scroll Snap Horizontal", menuCommand, s_ThickGUIElementSize); - GameObject childContent = CreateUIObject("Content", contentScrollSnapRoot); + GameObject childContent = CreateUIObject("Content", contentScrollSnapRoot); - GameObject childPage01 = CreateUIObject("Position 1", childContent); + GameObject childPage01 = CreateUIObject("Position 1", childContent); - GameObject childPage02 = CreateUIObject("Position 2", childContent); + GameObject childPage02 = CreateUIObject("Position 2", childContent); - GameObject childPage03 = CreateUIObject("Position 3", childContent); + GameObject childPage03 = CreateUIObject("Position 3", childContent); - GameObject childPage04 = CreateUIObject("Position 4", childContent); + GameObject childPage04 = CreateUIObject("Position 4", childContent); - GameObject childPage05 = CreateUIObject("Position 5", childContent); + GameObject childPage05 = CreateUIObject("Position 5", childContent); - //setup root - RectTransform contentScrollSnapRectTransform = ((RectTransform)contentScrollSnapRoot.transform); - contentScrollSnapRectTransform.anchorMin = new Vector2(0.5f, 0.5f); - contentScrollSnapRectTransform.anchorMax = new Vector2(0.5f, 0.5f); - contentScrollSnapRectTransform.anchoredPosition = Vector2.zero; - contentScrollSnapRectTransform.sizeDelta = new Vector2(100, 200); + //setup root + RectTransform contentScrollSnapRectTransform = ((RectTransform)contentScrollSnapRoot.transform); + contentScrollSnapRectTransform.anchorMin = new Vector2(0.5f, 0.5f); + contentScrollSnapRectTransform.anchorMax = new Vector2(0.5f, 0.5f); + contentScrollSnapRectTransform.anchoredPosition = Vector2.zero; + contentScrollSnapRectTransform.sizeDelta = new Vector2(100, 200); - Image image = contentScrollSnapRoot.AddComponent(); - image.sprite = null; - image.color = new Color(1, 0, 0, .5f); + Image image = contentScrollSnapRoot.AddComponent(); + image.sprite = null; + image.color = new Color(1, 0, 0, .5f); - ScrollRect sr = contentScrollSnapRoot.AddComponent(); - sr.vertical = false; - sr.horizontal = true; + ScrollRect sr = contentScrollSnapRoot.AddComponent(); + sr.vertical = false; + sr.horizontal = true; - //setup content container - RectTransform contentTransform = ((RectTransform)childContent.transform); - contentTransform.anchorMin = new Vector2(.5f, .5f); - contentTransform.anchorMax = new Vector2(.5f, .5f); - contentTransform.pivot = new Vector2(.5f, .5f); - contentTransform.sizeDelta = new Vector2(200, 300); + //setup content container + RectTransform contentTransform = ((RectTransform)childContent.transform); + contentTransform.anchorMin = new Vector2(.5f, .5f); + contentTransform.anchorMax = new Vector2(.5f, .5f); + contentTransform.pivot = new Vector2(.5f, .5f); + contentTransform.sizeDelta = new Vector2(200, 300); - Image contentImage = childContent.AddComponent(); - contentImage.sprite = null; - contentImage.color = new Color(0, 0, 1, .5f); + Image contentImage = childContent.AddComponent(); + contentImage.sprite = null; + contentImage.color = new Color(0, 0, 1, .5f); - sr.content = contentTransform; + sr.content = contentTransform; - //setup child 1 - RectTransform childPage01Transform = (RectTransform)childPage01.transform; - childPage01Transform.anchorMin = new Vector2(0, 1); - childPage01Transform.anchorMax = new Vector2(0, 1); - childPage01Transform.pivot = new Vector2(0, 1); - childPage01Transform.anchoredPosition = new Vector2(0, -125); + //setup child 1 + RectTransform childPage01Transform = (RectTransform)childPage01.transform; + childPage01Transform.anchorMin = new Vector2(0, 1); + childPage01Transform.anchorMax = new Vector2(0, 1); + childPage01Transform.pivot = new Vector2(0, 1); + childPage01Transform.anchoredPosition = new Vector2(0, -125); - Image childPage01Image = childPage01.AddComponent(); - childPage01Image.sprite = null; - childPage01Image.color = Color.white; + Image childPage01Image = childPage01.AddComponent(); + childPage01Image.sprite = null; + childPage01Image.color = Color.white; - //setup child 2 - RectTransform childPage02Transform = (RectTransform)childPage02.transform; - childPage02Transform.anchorMin = new Vector2(0, 1); - childPage02Transform.anchorMax = new Vector2(0, 1); - childPage02Transform.pivot = new Vector2(0, 1); - childPage02Transform.anchoredPosition = new Vector2(175, -150); + //setup child 2 + RectTransform childPage02Transform = (RectTransform)childPage02.transform; + childPage02Transform.anchorMin = new Vector2(0, 1); + childPage02Transform.anchorMax = new Vector2(0, 1); + childPage02Transform.pivot = new Vector2(0, 1); + childPage02Transform.anchoredPosition = new Vector2(175, -150); - Image childPage02Image = childPage02.AddComponent(); - childPage02Image.sprite = null; - childPage02Image.color = Color.white; + Image childPage02Image = childPage02.AddComponent(); + childPage02Image.sprite = null; + childPage02Image.color = Color.white; - //setup child 3 - RectTransform childPage03Transform = (RectTransform)childPage03.transform; - childPage03Transform.anchorMin = new Vector2(0, 1); - childPage03Transform.anchorMax = new Vector2(0, 1); - childPage03Transform.pivot = new Vector2(0, 1); - childPage03Transform.anchoredPosition = new Vector2(315, -125); - childPage03Transform.sizeDelta = new Vector2(50, 100); + //setup child 3 + RectTransform childPage03Transform = (RectTransform)childPage03.transform; + childPage03Transform.anchorMin = new Vector2(0, 1); + childPage03Transform.anchorMax = new Vector2(0, 1); + childPage03Transform.pivot = new Vector2(0, 1); + childPage03Transform.anchoredPosition = new Vector2(315, -125); + childPage03Transform.sizeDelta = new Vector2(50, 100); - Image childPage03Image = childPage03.AddComponent(); - childPage03Image.sprite = null; - childPage03Image.color = Color.white; + Image childPage03Image = childPage03.AddComponent(); + childPage03Image.sprite = null; + childPage03Image.color = Color.white; - //setup child 4 - RectTransform childPage04Transform = (RectTransform)childPage04.transform; - childPage04Transform.anchorMin = new Vector2(0, 1); - childPage04Transform.anchorMax = new Vector2(0, 1); - childPage04Transform.pivot = new Vector2(0, 1); - childPage04Transform.anchoredPosition = new Vector2(490, -110); + //setup child 4 + RectTransform childPage04Transform = (RectTransform)childPage04.transform; + childPage04Transform.anchorMin = new Vector2(0, 1); + childPage04Transform.anchorMax = new Vector2(0, 1); + childPage04Transform.pivot = new Vector2(0, 1); + childPage04Transform.anchoredPosition = new Vector2(490, -110); - Image childPage04Image = childPage04.AddComponent(); - childPage04Image.sprite = null; - childPage04Image.color = Color.white; + Image childPage04Image = childPage04.AddComponent(); + childPage04Image.sprite = null; + childPage04Image.color = Color.white; - //setup child 5 - RectTransform childPage05Transform = (RectTransform)childPage05.transform; - childPage05Transform.anchorMin = new Vector2(0, 1); - childPage05Transform.anchorMax = new Vector2(0, 1); - childPage05Transform.pivot = new Vector2(0, 1); - childPage05Transform.anchoredPosition = new Vector2(630, -180); + //setup child 5 + RectTransform childPage05Transform = (RectTransform)childPage05.transform; + childPage05Transform.anchorMin = new Vector2(0, 1); + childPage05Transform.anchorMax = new Vector2(0, 1); + childPage05Transform.pivot = new Vector2(0, 1); + childPage05Transform.anchoredPosition = new Vector2(630, -180); - Image childPage05Image = childPage05.AddComponent(); - childPage05Image.sprite = null; - childPage05Image.color = Color.white; + Image childPage05Image = childPage05.AddComponent(); + childPage05Image.sprite = null; + childPage05Image.color = Color.white; - //add scroll snap after we've added the content & items - contentScrollSnapRoot.AddComponent(); - } - #endregion + //add scroll snap after we've added the content & items + contentScrollSnapRoot.AddComponent(); + } + #endregion - #endregion + #endregion - #region UIVertical Scroller - [MenuItem("GameObject/UI/Extensions/UI Vertical Scroller", false)] + #region UIVertical Scroller + [MenuItem("GameObject/UI/Extensions/UI Vertical Scroller", false)] static public void AddUIVerticallScroller(MenuCommand menuCommand) { GameObject uiVerticalScrollerRoot = CreateUIElementRoot("UI Vertical Scroller", menuCommand, s_ThickGUIElementSize); @@ -657,10 +657,10 @@ namespace UnityEditor.UI Selection.activeGameObject = uiVerticalScrollerRoot; } - #endregion + #endregion - #region UI Button - [MenuItem("GameObject/UI/Extensions/UI Button", false)] + #region UI Button + [MenuItem("GameObject/UI/Extensions/UI Button", false)] static public void AddUIButton(MenuCommand menuCommand) { GameObject uiButtonRoot = CreateUIElementRoot("UI Button", menuCommand, s_ThickGUIElementSize); @@ -687,10 +687,10 @@ namespace UnityEditor.UI Selection.activeGameObject = uiButtonRoot; } - #endregion + #endregion - #region UI Flippable - [MenuItem("GameObject/UI/Extensions/UI Flippable", false)] + #region UI Flippable + [MenuItem("GameObject/UI/Extensions/UI Flippable", false)] static public void AddUIFlippableImage(MenuCommand menuCommand) { GameObject go = CreateUIElementRoot("UI Flippable", menuCommand, s_ImageGUIElementSize); @@ -698,10 +698,10 @@ namespace UnityEditor.UI go.AddComponent(); Selection.activeGameObject = go; } - #endregion + #endregion - #region UI WindowBase - [MenuItem("GameObject/UI/Extensions/UI Window Base", false)] + #region UI WindowBase + [MenuItem("GameObject/UI/Extensions/UI Window Base", false)] static public void AddUIWindowBase(MenuCommand menuCommand) { GameObject go = CreateUIElementRoot("UI Window Base", menuCommand, s_ThickGUIElementSize); @@ -717,8 +717,8 @@ namespace UnityEditor.UI { GameObject go = CreateUIElementRoot("Accordion Group", menuCommand, s_ThickGUIElementSize); CreateAccordionGroup(go); - for (int i = 0; i < 3; i++) - { + for (int i = 0; i < 3; i++) + { GameObject child = CreateUIObject($"Accordion Element {i}", go); CreateAccordionElement(child); } @@ -727,60 +727,60 @@ namespace UnityEditor.UI [MenuItem("GameObject/UI/Extensions/Accordion/Accordion Group", false)] static public void AddAccordionGroup(MenuCommand menuCommand) - { - GameObject go = CreateUIElementRoot("Accordion Group", menuCommand, s_ThickGUIElementSize); - CreateAccordionGroup(go); - Selection.activeGameObject = go; - } + { + GameObject go = CreateUIElementRoot("Accordion Group", menuCommand, s_ThickGUIElementSize); + CreateAccordionGroup(go); + Selection.activeGameObject = go; + } - private static void CreateAccordionGroup(GameObject go) - { - var vlg = go.AddComponent(); - vlg.childControlHeight = true; - vlg.childControlWidth = true; - vlg.childForceExpandHeight = false; - vlg.childForceExpandHeight = true; - var csf = go.AddComponent(); - csf.verticalFit = ContentSizeFitter.FitMode.PreferredSize; - go.AddComponent(); - go.AddComponent(); - } + private static void CreateAccordionGroup(GameObject go) + { + var vlg = go.AddComponent(); + vlg.childControlHeight = true; + vlg.childControlWidth = true; + vlg.childForceExpandHeight = false; + vlg.childForceExpandHeight = true; + var csf = go.AddComponent(); + csf.verticalFit = ContentSizeFitter.FitMode.PreferredSize; + go.AddComponent(); + go.AddComponent(); + } - [MenuItem("GameObject/UI/Extensions/Accordion/Accordion Element", false)] + [MenuItem("GameObject/UI/Extensions/Accordion/Accordion Element", false)] static public void AddAccordionElement(MenuCommand menuCommand) - { - GameObject go = CreateUIElementRoot("Accordion Element", menuCommand, s_ThickGUIElementSize); - CreateAccordionElement(go); + { + GameObject go = CreateUIElementRoot("Accordion Element", menuCommand, s_ThickGUIElementSize); + CreateAccordionElement(go); - Selection.activeGameObject = go; - } + Selection.activeGameObject = go; + } - private static void CreateAccordionElement(GameObject go) - { - var vlg = go.AddComponent(); - vlg.childControlHeight = true; - vlg.childControlWidth = true; - vlg.childForceExpandHeight = false; - vlg.childForceExpandHeight = true; - go.AddComponent(); - var accordionElement = go.AddComponent(); + private static void CreateAccordionElement(GameObject go) + { + var vlg = go.AddComponent(); + vlg.childControlHeight = true; + vlg.childControlWidth = true; + vlg.childForceExpandHeight = false; + vlg.childForceExpandHeight = true; + go.AddComponent(); + var accordionElement = go.AddComponent(); - // Header - GameObject headergo = CreateUIObject("Header", go); - var headerLayout = headergo.AddComponent(); - headerLayout.minHeight = accordionElement.MinHeight; - var headerText = headergo.AddComponent(); - headerText.text = "This is an Accordion header"; + // Header + GameObject headergo = CreateUIObject("Header", go); + var headerLayout = headergo.AddComponent(); + headerLayout.minHeight = accordionElement.MinHeight; + var headerText = headergo.AddComponent(); + headerText.text = "This is an Accordion header"; - // Text - GameObject textgo = CreateUIObject("Text", go); - var textText = textgo.AddComponent(); - textText.text = "This is an example of text in an accordion element\nLots of information can be put here for selection\nIf you like"; - } - #endregion + // Text + GameObject textgo = CreateUIObject("Text", go); + var textText = textgo.AddComponent(); + textText.text = "This is an example of text in an accordion element\nLots of information can be put here for selection\nIf you like"; + } + #endregion - #region Drop Down controls - [MenuItem("GameObject/UI/Extensions/AutoComplete ComboBox", false)] + #region Drop Down controls + [MenuItem("GameObject/UI/Extensions/AutoComplete ComboBox", false)] static public void AddAutoCompleteComboBox(MenuCommand menuCommand) { GameObject autoCompleteComboBoxRoot = CreateUIElementRoot("AutoCompleteComboBox", menuCommand, s_ThickGUIElementSize); @@ -807,7 +807,7 @@ namespace UnityEditor.UI //Setup Template itemTemplate.name = "ItemTemplate"; var itemTemplateRT = itemTemplate.GetComponent(); - itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10,0); + itemTemplateRT.sizeDelta = cbbRT.sizeDelta - new Vector2(10, 0); itemTemplateRT.anchoredPosition = new Vector2(-5, 0); var itemTemplateButton = itemTemplate.GetComponent public List AvailableOptions; - //private bool isInitialized = false; private bool _isPanelActive = false; private bool _hasDrawnOnce = false; private InputField _mainInput; private RectTransform _inputRT; - //private Button _arrow_Button; - private RectTransform _rectTransform; private RectTransform _overlayRT; @@ -52,11 +49,14 @@ namespace UnityEngine.UI.Extensions private List _prunedPanelItems; //items that used to show in the drop-down private Dictionary panelObjects; - + private GameObject itemTemplate; public string Text { get; private set; } + [SerializeField] + private float dropdownOffset; + [SerializeField] private float _scrollBarWidth = 20.0f; public float ScrollBarWidth @@ -69,9 +69,6 @@ namespace UnityEngine.UI.Extensions } } - // private int scrollOffset; //offset of the selected item - // private int _selectedIndex = 0; - [SerializeField] private int _itemsToDisplay; public int ItemsToDisplay @@ -84,28 +81,29 @@ namespace UnityEngine.UI.Extensions } } - public bool SelectFirstItemOnStart = false; + public bool SelectFirstItemOnStart = false; - [SerializeField] + [SerializeField] [Tooltip("Change input text color based on matching items")] private bool _ChangeInputTextColorBasedOnMatchingItems = false; - public bool InputColorMatching{ - get { return _ChangeInputTextColorBasedOnMatchingItems; } - set - { - _ChangeInputTextColorBasedOnMatchingItems = value; - if (_ChangeInputTextColorBasedOnMatchingItems) { - SetInputTextColor (); - } - } - } + public bool InputColorMatching + { + get { return _ChangeInputTextColorBasedOnMatchingItems; } + set + { + _ChangeInputTextColorBasedOnMatchingItems = value; + if (_ChangeInputTextColorBasedOnMatchingItems) + { + SetInputTextColor(); + } + } + } public float DropdownOffset = 10f; - //TODO design as foldout for Inspector public Color ValidSelectionTextColor = Color.green; - public Color MatchingItemsRemainingTextColor = Color.black; - public Color NoItemsRemainingTextColor = Color.red; + public Color MatchingItemsRemainingTextColor = Color.black; + public Color NoItemsRemainingTextColor = Color.red; public AutoCompleteSearchType autocompleteSearchType = AutoCompleteSearchType.Linq; @@ -114,36 +112,34 @@ namespace UnityEngine.UI.Extensions private bool _selectionIsValid = false; - [System.Serializable] - public class SelectionChangedEvent : UnityEngine.Events.UnityEvent { - } + [System.Serializable] + public class SelectionChangedEvent : Events.UnityEvent { } [System.Serializable] - public class SelectionTextChangedEvent : UnityEngine.Events.UnityEvent { - } + public class SelectionTextChangedEvent : Events.UnityEvent { } - [System.Serializable] - public class SelectionValidityChangedEvent : UnityEngine.Events.UnityEvent { - } + [System.Serializable] + public class SelectionValidityChangedEvent : Events.UnityEvent { } - // fires when input text is changed; - public SelectionTextChangedEvent OnSelectionTextChanged; - // fires when an Item gets selected / deselected (including when items are added/removed once this is possible) - public SelectionValidityChangedEvent OnSelectionValidityChanged; - // fires in both cases - public SelectionChangedEvent OnSelectionChanged; + // fires when input text is changed; + public SelectionTextChangedEvent OnSelectionTextChanged; + // fires when an Item gets selected / deselected (including when items are added/removed once this is possible) + public SelectionValidityChangedEvent OnSelectionValidityChanged; + // fires in both cases + public SelectionChangedEvent OnSelectionChanged; public void Awake() { Initialize(); } - public void Start() - { - if (SelectFirstItemOnStart && AvailableOptions.Count > 0) { - ToggleDropdownPanel (false); - OnItemClicked (AvailableOptions [0]); - } + public void Start() + { + if (SelectFirstItemOnStart && AvailableOptions.Count > 0) + { + ToggleDropdownPanel(false); + OnItemClicked(AvailableOptions[0]); + } RedrawPanel(); } @@ -156,8 +152,6 @@ namespace UnityEngine.UI.Extensions _inputRT = _rectTransform.Find("InputField").GetComponent(); _mainInput = _inputRT.GetComponent(); - //_arrow_Button = _rectTransform.FindChild ("ArrowBtn").GetComponent