| | |
| | | private Image m_MaskImage; |
| | | private RectTransform m_RectTransform; |
| | | private List<Graphic> m_MaskedChildren = new List<Graphic>(); |
| | | // 缓存GetComponentsInChildren结果,避免每次OnEnable分配数组 |
| | | private static List<Graphic> _graphicCacheList = new List<Graphic>(); |
| | | |
| | | public Vector2 EllipseCenter |
| | | { |
| | |
| | | // 清除之前的列表 |
| | | m_MaskedChildren.Clear(); |
| | | |
| | | // 获取所有子对象的Graphic组件 |
| | | Graphic[] childrenGraphics = GetComponentsInChildren<Graphic>(); |
| | | foreach (var graphic in childrenGraphics) |
| | | // 使用静态缓存列表避免每次分配数组 |
| | | _graphicCacheList.Clear(); |
| | | GetComponentsInChildren(false, _graphicCacheList); |
| | | for (int i = 0; i < _graphicCacheList.Count; i++) |
| | | { |
| | | var graphic = _graphicCacheList[i]; |
| | | // 跳过遮罩本身 |
| | | if (graphic.gameObject == this.gameObject) |
| | | continue; |
| | |
| | | CreateChildMaskMaterial(graphic); |
| | | m_MaskedChildren.Add(graphic); |
| | | } |
| | | _graphicCacheList.Clear(); |
| | | } |
| | | |
| | | /// <summary> |