Files
MinFt/Client/LocalPackages/SoftMaskForUGUI-3.5.0/Runtime/Utilities/TmpProxy.cs
Liubing\LB 3d8d4d18f3 first commit
先修复一下,错误的场景

删除不必要的钓场资产

修复into场景

update:更新meta文件,修复报错

update:修复资源

修复第一章节建造

修复建造第三章

update:删除多余内容

update:更新README.md

update:还原图标

update:更新README

update:更新配置
2026-04-28 02:17:22 +08:00

102 lines
2.9 KiB
C#

#if TMP_ENABLE
using Coffee.UISoftMaskInternal;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace Coffee.UISoftMask
{
internal sealed class TmpProxy : GraphicProxy
{
/// <summary>
/// Check if the graphic is valid for this proxy.
/// </summary>
protected override bool IsValid(Graphic graphic)
{
if (!graphic) return false;
if (graphic is TextMeshProUGUI || graphic is TMP_SubMeshUI) return true;
return false;
}
public override void SetMaterialDirty(Graphic graphic)
{
graphic.SetMaterialDirty();
UpdateMeshUI(graphic);
}
public override Texture GetMainTexture(Graphic graphic)
{
var cr = graphic.canvasRenderer;
if (!cr || cr.materialCount == 0) return null;
var mat = cr.GetMaterial(0);
if (!mat) return null;
return mat.mainTexture;
}
public override float GetAlpha(Graphic graphic)
{
if (graphic is TMP_SubMeshUI sub)
{
return sub.textComponent.color.a;
}
return graphic.color.a;
}
private static void UpdateSubMeshUI(TextMeshProUGUI text, ISoftMasking parent)
{
var subMeshes = InternalListPool<TMP_SubMeshUI>.Rent();
text.GetComponentsInChildren(subMeshes, 1);
for (var i = 0; i < subMeshes.Count; i++)
{
var maskingShape = subMeshes[i].GetOrAddComponent<MaskingShape>();
maskingShape.hideFlags = HideFlags.NotEditable;
maskingShape.enabled = parent.enabled;
maskingShape.parent = parent;
#pragma warning disable CS0618
(maskingShape as IMeshModifier).ModifyMesh(subMeshes[i].mesh);
#pragma warning restore CS0618
}
InternalListPool<TMP_SubMeshUI>.Return(ref subMeshes);
}
private static void UpdateMeshUI(Object obj)
{
if (!(obj is TextMeshProUGUI text)) return;
if (text.TryGetComponent<SoftMask>(out var sm))
{
#pragma warning disable CS0618
(sm as IMeshModifier).ModifyMesh(text.mesh);
#pragma warning restore CS0618
UpdateSubMeshUI(text, sm);
}
else if (text.TryGetComponent<MaskingShape>(out var ms))
{
#pragma warning disable CS0618
(ms as IMeshModifier).ModifyMesh(text.mesh);
#pragma warning restore CS0618
UpdateSubMeshUI(text, ms);
}
}
#if UNITY_EDITOR
[InitializeOnLoadMethod]
#else
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
#endif
private static void InitializeOnLoad()
{
Register(new TmpProxy());
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(UpdateMeshUI);
}
}
}
#endif