From ed98029a88cd89702980ac7c40b711afddc5aeb2 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期四, 20 十一月 2025 14:44:59 +0800
Subject: [PATCH] Merge branch 'master' of http://mobile.secondworld.net.cn:10010/r/Project_SG_scripts
---
Main/Component/UI/Common/SmoothMask.cs | 106 +++++++++++++++++++++++++++++++++++-----------------
1 files changed, 71 insertions(+), 35 deletions(-)
diff --git a/Main/Component/UI/Common/SmoothMask.cs b/Main/Component/UI/Common/SmoothMask.cs
index 3907fcf..592a7aa 100644
--- a/Main/Component/UI/Common/SmoothMask.cs
+++ b/Main/Component/UI/Common/SmoothMask.cs
@@ -56,41 +56,29 @@
}
private void SetChildrenImageMaterial(Transform _transform) {
- Image image;
- Transform transform;
- for(int i = 0;i < _transform.childCount;i++) {
- transform = _transform.GetChild(i);
- image = transform.GetComponent<Image>();
- if(image != null) {
- image.material = imageMaterials.Length > 0 ? imageMaterials[0] : null;
- }
- else
- {
- var imageex = transform.GetComponent<ImageEx>();
- if (imageex != null)
- {
- imageex.material = imageMaterials.Length > 0 ? imageMaterials[0] : null;
- }
- }
+ Image[] images = _transform.GetComponentsInChildren<Image>(true);
+ ImageEx[] imageexs = _transform.GetComponentsInChildren<ImageEx>(true);
- if(transform.childCount > 0) {
- SetChildrenImageMaterial(transform);
+ if (null != images)
+ {
+ for(int i = 0;i < images.Length;i++) {
+ images[i].material = imageMaterials.Length > 0? imageMaterials[0] : null;
+ }
+ }
+
+ if (null!= imageexs)
+ {
+ for(int i = 0;i < imageexs.Length;i++) {
+ imageexs[i].material = imageMaterials.Length > 0? imageMaterials[0] : null;
}
}
}
private void SetChildrenTextMaterial(Transform _parent) {
- Text text;
- Transform transform;
- for(int i = 0;i < _parent.childCount;i++) {
- transform = _parent.GetChild(i);
- text = transform.GetComponent<Text>();
- if(text != null) {
- text.material = textMaterials.Length > 0 ? textMaterials[0] : null;
- }
-
- if(transform.childCount > 0) {
- SetChildrenTextMaterial(transform);
+ Text[] texts = _parent.GetComponentsInChildren<Text>(true);
+ if(texts!= null) {
+ for(int i = 0;i < texts.Length;i++) {
+ texts[i].material = textMaterials.Length > 0? textMaterials[0] : null;
}
}
}
@@ -99,8 +87,11 @@
var scaleX = canvasScaler.transform.localScale.x;
var scaleY = canvasScaler.transform.localScale.y;
- leftBottom = scaleX == 0f ? Vector2.zero : rectTransform.GetMinWorldPosition() / scaleX;
- rightTop = scaleY == 0f ? Vector2.zero : rectTransform.GetMaxWorldPosition() / scaleY;
+ Vector3[] corners = new Vector3[4];
+ rectTransform.GetWorldCorners(corners);
+
+ leftBottom = new Vector2(corners[0].x, corners[0].y);
+ rightTop = new Vector2(corners[2].x, corners[2].y);
if(imageMaterials != null) {
for(int i = 0;i < imageMaterials.Length;i++) {
@@ -115,10 +106,55 @@
}
}
- static void SetSmoothMask(Material material,Vector2 leftBottom,Vector2 rightTop,Vector2 smoothRect) {
- material.SetVector("_LeftBottom",leftBottom);
- material.SetVector("_RightTop",rightTop);
- material.SetVector("_SmoothRect",smoothRect);
+#if UNITY_EDITOR
+ void OnDrawGizmos() {
+ Vector3[] corners = new Vector3[4];
+ rectTransform.GetWorldCorners(corners);
+
+ Gizmos.color = Color.red; // 璁剧疆绾挎棰滆壊
+ // 缁樺埗鐭╁舰杈圭晫
+ Gizmos.DrawLine(corners[0], corners[1]); // 宸︿笅鈫掑乏涓�
+ Gizmos.DrawLine(corners[1], corners[2]); // 宸︿笂鈫掑彸涓�
+ Gizmos.DrawLine(corners[2], corners[3]); // 鍙充笂鈫掑彸涓�
+ Gizmos.DrawLine(corners[3], corners[0]); // 鍙充笅鈫掑乏涓�
+ }
+#endif
+
+ void SetSmoothMask(Material material,Vector2 leftBottom,Vector2 rightTop,Vector2 smoothRect) {
+
+ Image[] images = GetComponentsInChildren<Image>(true);
+ ImageEx[] imageexs = GetComponentsInChildren<ImageEx>(true);
+ Text[] texts = GetComponentsInChildren<Text>(true);
+
+ if (null != images)
+ {
+ foreach (var graphic in images)
+ {
+ graphic.material.SetVector("_LeftBottom",leftBottom);
+ graphic.material.SetVector("_RightTop",rightTop);
+ graphic.material.SetVector("_SmoothRect",smoothRect);
+ }
+ }
+
+ if (null != imageexs)
+ {
+ foreach (var graphic in imageexs)
+ {
+ graphic.material.SetVector("_LeftBottom",leftBottom);
+ graphic.material.SetVector("_RightTop",rightTop);
+ graphic.material.SetVector("_SmoothRect",smoothRect);
+ }
+ }
+
+ if (null != texts)
+ {
+ foreach (var graphic in texts)
+ {
+ graphic.material.SetVector("_LeftBottom",leftBottom);
+ graphic.material.SetVector("_RightTop",rightTop);
+ graphic.material.SetVector("_SmoothRect",smoothRect);
+ }
+ }
}
}
--
Gitblit v1.8.0