From 15bf34edaf7bd52c2e6649aea9246d1d613ee5c7 Mon Sep 17 00:00:00 2001 From: LiRuoChen <571244399@qq.com> Date: Thu, 9 Jul 2026 11:40:43 +0800 Subject: [PATCH] =?UTF-8?q?ui=E5=9F=BA=E7=B1=BB=E6=B7=BB=E5=8A=A0=E6=98=BE?= =?UTF-8?q?=E5=BD=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Core/Base/XericUIBehaciour.cs | 46 +++++++++++++++++++-------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/Runtime/Core/Base/XericUIBehaciour.cs b/Runtime/Core/Base/XericUIBehaciour.cs index 84cc67a..f68fc0e 100644 --- a/Runtime/Core/Base/XericUIBehaciour.cs +++ b/Runtime/Core/Base/XericUIBehaciour.cs @@ -1,4 +1,5 @@ using System; +using Deconstruction.Runtime; #if ODIN_INSPECTOR using Sirenix.OdinInspector; #endif @@ -36,11 +37,9 @@ namespace XericUI.Core.Base { get { - if (_canvas == null) - _canvas = GetComponentInParent(); + if (!_canvas) _canvas = GetComponentInParent(); #if UNITY_EDITOR - if (_canvas == null) - Debug.LogError($"{name} 无法找到布局组件,接下来的流程可能会引发错误", this); + if (!_canvas) Debug.LogError($"{name} 无法找到布局组件,接下来的流程可能会引发错误", this); #endif return _canvas; } @@ -53,11 +52,9 @@ namespace XericUI.Core.Base { get { - if (_canvasScaler == null) - _canvasScaler = GetComponentInParent(); + if (!_canvasScaler) _canvasScaler = GetComponentInParent(); #if UNITY_EDITOR - if (_canvas == null) - Debug.LogError($"{name} 无法找到布局缩放组件,接下来的流程可能会引发错误", this); + if (_canvas == null) Debug.LogError($"{name} 无法找到布局缩放组件,接下来的流程可能会引发错误", this); #endif return _canvasScaler; } @@ -70,11 +67,9 @@ namespace XericUI.Core.Base { get { - if (_graphicRaycaster == null) - _graphicRaycaster = GetComponentInParent(); + if (!_graphicRaycaster) _graphicRaycaster = GetComponentInParent(); #if UNITY_EDITOR - if (_canvas == null) - Debug.LogError($"{name} 无法找到布局射线检测,接下来的流程可能会引发错误", this); + if (_canvas == null) Debug.LogError($"{name} 无法找到布局射线检测,接下来的流程可能会引发错误", this); #endif return _graphicRaycaster; } @@ -87,8 +82,7 @@ namespace XericUI.Core.Base { get { - if (_rect == null) - _rect = GetComponent(); + if (!_rect) _rect = GetComponent(); return _rect; } } @@ -135,6 +129,7 @@ namespace XericUI.Core.Base /// public void SetHierarchyDirty() { + rectTransform.SetLayoutDirty(); _canvas = null; _canvasScaler = null; _graphicRaycaster = null; @@ -147,6 +142,29 @@ namespace XericUI.Core.Base public void ResetHierarchyDirty() { _hierarchyDirty = false; + rectTransform.SetLayoutDirty(); + } + + #endregion + + #region 显影 + + public virtual void Show() + { + gameObject.SetActive(true); + } + + public void Show(bool isShow) + { + if (isShow) + Show(); + else + Hide(); + } + + public virtual void Hide() + { + gameObject.SetActive(false); } #endregion