Files
XericUIActionVessel/Runtime/OverrideUI/AvrgValues/XUIAvrgMDTextureValue.cs
T
lrss3 4e760d59d1 refactor(注册路径): 调用点收进 XericRegistrationPaths,46 个文件只动注册属性行
10-27 那笔把表的根定成 XericLibrary,但 58 处 AddComponentMenu、4 处 CreateAssetMenu
和若干 MenuItem/ContextMenu 还各自写着 "Xeric UI Vessel/…"、"Xeric/XChart/…" 三套
旧字面量;那批转换一直停在工程里没提交。本笔只收这 46 个"除注册属性外没有别的改动"
的文件,路径出处从此只在表里一处。

工作区里另外 3 个文件(XericImage 的角偏移、IVisibility 接口、XericInfiniteVesselBase
的 region/注释)混着功能改动,不在本笔;Editor/OverrideUI/XericImageEditor.cs 与
Runtime/OverrideUI/XericImageDeform.cs 两个未入库新文件也不在。
2026-10-30 12:34:34 +08:00

62 lines
1.8 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using XericUI.Core;
namespace XericUI.ReflectionUIGenerator
{
/// <summary>
/// Texture 值组件 — 通过 RawImage 显示纹理
/// </summary>
[AddComponentMenu(XericRegistrationPaths.UI + "/Values/XUIAvrgMDTextureValue")]
public class XUIAvrgMDTextureValue : XUIAvrgMDValue
{
[SerializeField, Tooltip("关联的 RawImage 组件(未设置则自动查找)")]
private RawImage _rawImage;
#if dUI_TextMeshPro
[SerializeField, Tooltip("纹理名称标签(可选)")]
private TMPro.TMP_Text _nameLabel;
#endif
private void Awake()
{
if (_rawImage == null) _rawImage = GetComponent<RawImage>();
}
public override void BindToAccessor(
IAvrgValueAccessor accessor,
AvrgMvvmBinding binding,
AvrgMvvmScheduler scheduler)
{
CurrentAccessor = accessor;
CurrentBinding = binding;
if (binding == null || accessor == null) return;
binding.OnUIDataChanged += (value, state) =>
{
UpdateValueDisplay(value, state);
};
binding.OnValidationStateChanged += OnValidationStateChanged;
var initialValue = accessor.GetValue();
UpdateValueDisplay(initialValue, ValidationState.Normal);
}
protected override void UpdateValueDisplay(object value, ValidationState state)
{
// 值显示:刷新 RawImage.texture
if (_rawImage != null && value is Texture tex)
{
_rawImage.texture = tex;
#if dUI_TextMeshPro
if (_nameLabel != null)
_nameLabel.text = tex?.name ?? "";
#endif
}
base.UpdateValueDisplay(value, state);
}
}
}