重构反射构建组件,添加材质反射组件
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XericUI.ReflectionUIGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 纹理值组件 — 处理 Texture 类型的预览显示
|
||||
/// 通过 RawImage.texture 展示当前纹理
|
||||
/// </summary>
|
||||
[AddComponentMenu("Xeric Library/UI Action Vessel/Values/XUIAvrgMDTextureValue")]
|
||||
public class XUIAvrgMDTextureValue : XUIAvrgMDValue
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("用于展示纹理的 RawImage 组件(未设置则自动查找)")]
|
||||
private RawImage _textureDisplay;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("纹理名称标签(可选,用于显示纹理资源名)")]
|
||||
private TMPro.TMP_Text _nameLabel;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_textureDisplay == null) _textureDisplay = GetComponent<RawImage>();
|
||||
}
|
||||
|
||||
public override void BindToAccessor(
|
||||
IAvrgValueAccessor accessor,
|
||||
AvrgMvvmBinding binding,
|
||||
AvrgMvvmScheduler scheduler)
|
||||
{
|
||||
CurrentAccessor = accessor;
|
||||
CurrentBinding = binding;
|
||||
|
||||
if (binding == null || accessor == null) return;
|
||||
|
||||
// 数据 → UI
|
||||
binding.OnUIDataChanged += value =>
|
||||
{
|
||||
if (value is Texture tex && _textureDisplay != null)
|
||||
{
|
||||
_textureDisplay.texture = tex;
|
||||
}
|
||||
|
||||
if (_nameLabel != null)
|
||||
{
|
||||
_nameLabel.text = value is Texture t && t != null ? t.name : "None";
|
||||
}
|
||||
};
|
||||
|
||||
// 首次同步
|
||||
var initialValue = accessor.GetValue();
|
||||
if (initialValue is Texture initTex && _textureDisplay != null)
|
||||
{
|
||||
_textureDisplay.texture = initTex;
|
||||
}
|
||||
|
||||
if (_nameLabel != null)
|
||||
{
|
||||
_nameLabel.text = initialValue is Texture t && t != null ? t.name : "None";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user