From ce687b60da94eb3d7ed1bbcc22792fa60748d235 Mon Sep 17 00:00:00 2001 From: MpakobecEx Date: Sun, 1 Nov 2026 19:20:51 +0500 Subject: [PATCH] =?UTF-8?q?client:=20=D0=BF=D0=BB=D0=B0=D0=B2=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=81=D0=BA=D1=80=D0=BE=D0=BB=D0=BB=20=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5=D1=81=D0=BE=20=D0=BD=D0=B0=D0=B4=20=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SmoothScrollRect (UiKit): колесо задаёт целевую позицию, контент плавно подъезжает; протяжка работает как раньше. Подключён ко всем прокруткам. - Правый клик по карте заменён с EventTrigger на RightClickRelay (только IPointerClickHandler), из-за чего EventTrigger раньше съедал колесо и скролл работал только между картами. - Проверки: EditMode 69/69, standalone собран. --- .../Vanguard/Runtime/UI/DeckBuilderView.cs | 16 +---- .../Vanguard/Runtime/UI/RightClickRelay.cs | 21 ++++++ .../Runtime/UI/RightClickRelay.cs.meta | 2 + .../Vanguard/Runtime/UI/SmoothScrollRect.cs | 65 +++++++++++++++++++ .../Runtime/UI/SmoothScrollRect.cs.meta | 2 + client/Assets/Vanguard/Runtime/UI/UiKit.cs | 2 +- 6 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 client/Assets/Vanguard/Runtime/UI/RightClickRelay.cs create mode 100644 client/Assets/Vanguard/Runtime/UI/RightClickRelay.cs.meta create mode 100644 client/Assets/Vanguard/Runtime/UI/SmoothScrollRect.cs create mode 100644 client/Assets/Vanguard/Runtime/UI/SmoothScrollRect.cs.meta 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);