diff --git a/client/Assets/Vanguard/Runtime/UI/DeckBuilderView.cs b/client/Assets/Vanguard/Runtime/UI/DeckBuilderView.cs index 2374514..ab8239c 100644 --- a/client/Assets/Vanguard/Runtime/UI/DeckBuilderView.cs +++ b/client/Assets/Vanguard/Runtime/UI/DeckBuilderView.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using UnityEngine; -using UnityEngine.EventSystems; using UnityEngine.UI; using Vanguard.Api; using Vanguard.Api.Contracts; @@ -1442,18 +1441,9 @@ namespace Vanguard.UI private void AddRightClick(GameObject target, string printingId, CardCatalogItemDto meta) { - var trigger = target.GetComponent() - ?? target.AddComponent(); - var entry = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick }; - entry.callback.AddListener(data => - { - if (data is PointerEventData pointer - && pointer.button == PointerEventData.InputButton.Right) - { - ShowCardOverlay(printingId, meta); - } - }); - trigger.triggers.Add(entry); + var relay = target.GetComponent() + ?? target.AddComponent(); + relay.Clicked = _ => ShowCardOverlay(printingId, meta); } private void ShowCardOverlay(string printingId, CardCatalogItemDto meta) diff --git a/client/Assets/Vanguard/Runtime/UI/RightClickRelay.cs b/client/Assets/Vanguard/Runtime/UI/RightClickRelay.cs new file mode 100644 index 0000000..599e5ab --- /dev/null +++ b/client/Assets/Vanguard/Runtime/UI/RightClickRelay.cs @@ -0,0 +1,21 @@ +using System; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace Vanguard.UI +{ + /// + /// Правый клик по объекту. В отличие от EventTrigger реализует только + /// IPointerClickHandler, поэтому колесо мыши проходит к ScrollRect. + /// + public sealed class RightClickRelay : MonoBehaviour, IPointerClickHandler + { + public Action Clicked; + + public void OnPointerClick(PointerEventData eventData) + { + if (eventData != null && eventData.button == PointerEventData.InputButton.Right) + Clicked?.Invoke(eventData); + } + } +} diff --git a/client/Assets/Vanguard/Runtime/UI/RightClickRelay.cs.meta b/client/Assets/Vanguard/Runtime/UI/RightClickRelay.cs.meta new file mode 100644 index 0000000..589ae5b --- /dev/null +++ b/client/Assets/Vanguard/Runtime/UI/RightClickRelay.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: a549a5f7e2587444caecfdb1d3abbc0a \ No newline at end of file diff --git a/client/Assets/Vanguard/Runtime/UI/SmoothScrollRect.cs b/client/Assets/Vanguard/Runtime/UI/SmoothScrollRect.cs new file mode 100644 index 0000000..7d3bc1e --- /dev/null +++ b/client/Assets/Vanguard/Runtime/UI/SmoothScrollRect.cs @@ -0,0 +1,65 @@ +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace Vanguard.UI +{ + /// + /// ScrollRect с плавным колесом: колесо задаёт целевую позицию, а контент + /// подъезжает к ней за несколько кадров. Перетаскивание работает как обычно. + /// + public sealed class SmoothScrollRect : ScrollRect + { + public float WheelStep = 140f; + public float Smoothing = 0.06f; + + private float _target; + private bool _smooth; + + public override void OnScroll(PointerEventData eventData) + { + if (!vertical || content == null || viewport == null) + { + base.OnScroll(eventData); + return; + } + + if (!_smooth) + _target = content.anchoredPosition.y; + + var max = Mathf.Max(0f, content.rect.height - viewport.rect.height); + _target = Mathf.Clamp(_target + eventData.scrollDelta.y * WheelStep, -max, 0f); + velocity = Vector2.zero; + _smooth = true; + } + + public override void OnBeginDrag(PointerEventData eventData) + { + _smooth = false; + base.OnBeginDrag(eventData); + } + + protected override void LateUpdate() + { + if (!_smooth || content == null || viewport == null) + { + base.LateUpdate(); + return; + } + + var position = content.anchoredPosition; + var max = Mathf.Max(0f, content.rect.height - viewport.rect.height); + _target = Mathf.Clamp(_target, -max, 0f); + + var t = 1f - Mathf.Exp(-Time.unscaledDeltaTime / Mathf.Max(0.01f, Smoothing)); + var next = Mathf.Lerp(position.y, _target, t); + if (Mathf.Abs(next - _target) < 0.5f) + { + next = _target; + _smooth = false; + } + + content.anchoredPosition = new Vector2(position.x, next); + } + } +} diff --git a/client/Assets/Vanguard/Runtime/UI/SmoothScrollRect.cs.meta b/client/Assets/Vanguard/Runtime/UI/SmoothScrollRect.cs.meta new file mode 100644 index 0000000..96e36fd --- /dev/null +++ b/client/Assets/Vanguard/Runtime/UI/SmoothScrollRect.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: baf08a955c0310444bf2c36f2ffa644c \ No newline at end of file diff --git a/client/Assets/Vanguard/Runtime/UI/UiKit.cs b/client/Assets/Vanguard/Runtime/UI/UiKit.cs index 8931746..0cd066d 100644 --- a/client/Assets/Vanguard/Runtime/UI/UiKit.cs +++ b/client/Assets/Vanguard/Runtime/UI/UiKit.cs @@ -370,7 +370,7 @@ namespace Vanguard.UI name, typeof(RectTransform), typeof(Image), - typeof(ScrollRect)); + typeof(SmoothScrollRect)); var rect = (RectTransform)root.transform; rect.SetParent(parent, false); Stretch(rect);