From b2d7bb59dc37c7b350786b076ee2f344b7c8911f Mon Sep 17 00:00:00 2001 From: yyl <yyl> Date: 星期一, 11 八月 2025 17:26:47 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.1.20:10010/r/Project_SG_scripts --- Main/Component/UI/Common/LayoutElementSizeClamp.cs | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Main/Component/UI/Common/LayoutElementSizeClamp.cs b/Main/Component/UI/Common/LayoutElementSizeClamp.cs index d41452b..b0b17c3 100644 --- a/Main/Component/UI/Common/LayoutElementSizeClamp.cs +++ b/Main/Component/UI/Common/LayoutElementSizeClamp.cs @@ -1,9 +1,8 @@ -锘縰sing System.Collections; -using System.Collections.Generic; +锘縰sing Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.UI; -using UnityEngine.EventSystems; +//鎺у埗鐩爣鐨勬渶澶ф渶灏忓昂瀵� [ExecuteAlways] public class LayoutElementSizeClamp : LayoutElement { @@ -15,21 +14,34 @@ [SerializeField] RectTransform m_Target; - Vector2 targetSizeRef = Vector2.zero; - private void LateUpdate() + protected override void OnEnable() { + base.OnEnable(); if (clampEnable && m_Target != null) { - if (targetSizeRef != m_Target.sizeDelta) - { - preferredHeight = Mathf.Clamp(m_Target.rect.height, m_Clamp.minY, m_Clamp.maxY); - preferredWidth = Mathf.Clamp(m_Target.rect.width, m_Clamp.minX, m_Clamp.maxX); - targetSizeRef = new Vector2(preferredWidth, preferredHeight); - } + UpdateRect().Forget(); } + } + async UniTask UpdateRect() + { + await UniTask.DelayFrame(1); + preferredHeight = -1; + preferredWidth = -1; + //棰戠箒璋冪敤ForceRebuildLayoutImmediate鐨勫師鍥犳槸 + // 濡俆ext瑕佽嚜閫傚簲瀹介珮鍙堣闄愬埗瀹介珮, 鍏堣澶勭悊瀹藉害鍒锋柊鍚庢墠鑳借绠楁崲琛� + // 寮哄埗閲嶆柊璁$畻甯冨眬 + LayoutRebuilder.ForceRebuildLayoutImmediate(transform.parent as RectTransform); + preferredWidth = Mathf.Clamp(m_Target.rect.width, m_Clamp.minX, m_Clamp.maxX); + // 寮哄埗閲嶆柊璁$畻甯冨眬 + LayoutRebuilder.ForceRebuildLayoutImmediate(transform.parent as RectTransform); + preferredHeight = Mathf.Clamp(m_Target.rect.height, m_Clamp.minY, m_Clamp.maxY); + + } + + [System.Serializable] public struct Clamp { -- Gitblit v1.8.0