1
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -10,4 +8,21 @@ public class SeccionItem : MonoBehaviour
|
||||
public Button btn_SelectGameRoom;
|
||||
public TextMeshProUGUI txt_VenueInfo; // 场地信息:初级场/中级场/高级场
|
||||
public TextMeshProUGUI txt_EntryCondition; // 入场条件文字
|
||||
|
||||
[Header("快速进入按钮按下缩放")]
|
||||
public float pressScale = 0.95f; // 按下时卡片缩放比例
|
||||
public float pressDuration = 0.1f; // 缩放动画时长
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (btn_JoinGame == null) return;
|
||||
|
||||
// 「快速进入」按钮:按下缩小卡片,抬起还原
|
||||
// 用只处理按下/抬起、不含拖动接口的 UIPressScale,避免抢走所在 ScrollRect 的滑动
|
||||
var effect = btn_JoinGame.gameObject.GetComponent<UIPressScale>();
|
||||
if (effect == null) effect = btn_JoinGame.gameObject.AddComponent<UIPressScale>();
|
||||
effect.target = transform; // 缩放整个 SeccionItem 卡片
|
||||
effect.pressScale = pressScale;
|
||||
effect.duration = pressDuration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
/// <summary>
|
||||
/// 按下缩小、抬起还原。
|
||||
/// 只实现 IPointerDownHandler / IPointerUpHandler,不实现 IDragHandler 等拖动接口,
|
||||
/// 所以挂在 ScrollRect 内的按钮上不会抢走 ScrollRect 的滑动。
|
||||
/// </summary>
|
||||
public class UIPressScale : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
||||
{
|
||||
[Tooltip("缩放目标,留空则缩放自身")]
|
||||
public Transform target;
|
||||
public float pressScale = 0.95f; // 按下时缩放比例
|
||||
public float duration = 0.1f; // 缩放动画时长
|
||||
|
||||
private Vector3 _standardScale;
|
||||
private bool _captured;
|
||||
private bool _isPressing;
|
||||
|
||||
private Transform Target => target != null ? target : transform;
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) => SetPressing(true);
|
||||
public void OnPointerUp(PointerEventData eventData) => SetPressing(false);
|
||||
|
||||
private void SetPressing(bool pressing)
|
||||
{
|
||||
if (_isPressing == pressing) return;
|
||||
_isPressing = pressing;
|
||||
|
||||
var t = Target;
|
||||
if (!_captured)
|
||||
{
|
||||
_standardScale = t.localScale; // 首次使用时记录原缩放
|
||||
_captured = true;
|
||||
}
|
||||
t.DOKill();
|
||||
t.DOScale(pressing ? _standardScale * pressScale : _standardScale, duration)
|
||||
.SetEase(Ease.OutQuad);
|
||||
}
|
||||
|
||||
// 被隐藏时立即还原,避免按下瞬间目标被关掉而停在缩小状态
|
||||
private void OnDisable()
|
||||
{
|
||||
_isPressing = false;
|
||||
if (!_captured) return;
|
||||
Target.DOKill();
|
||||
Target.localScale = _standardScale;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1435cae0f5e87f24c9f0c3581b81f36a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user