fix(ShaderBake): 修正离屏视图矩阵与侧栏数值不可见

- 投影矩阵是 OpenGL 约定(相机朝 -Z),而 TRS.inverse 给的是 Unity 的 +Z 朝前,
  两者拼起来几何全被裁剪,表现是"渲染成功但画面全透明";视图矩阵补上 Z 镜像
- 侧栏半宽/三分之一宽的字段按内容定基宽,标题又占 ~120px,输入框被挤出可视区;
  改成 flex-basis:0 + 收窄标题 + 输入区 min-width:0,并缩短过长标签
- 数值绑定改用 INotifyValueChanged<T> 按名字绑定,不再依赖跨版本会换命名空间的具体字段类型
This commit is contained in:
2026-11-05 19:17:57 +08:00
parent bede1f8a8b
commit 7c0f35fdcb
4 changed files with 81 additions and 32 deletions
+38 -24
View File
@@ -633,8 +633,8 @@ namespace XericUI.ShaderBake.Editor
private void SetFaceFieldsEnabled(bool enabled)
{
IntegerField x = rootVisualElement.Q<IntegerField>("face-uv-x");
IntegerField y = rootVisualElement.Q<IntegerField>("face-uv-y");
VisualElement x = rootVisualElement.Q<VisualElement>("face-uv-x");
VisualElement y = rootVisualElement.Q<VisualElement>("face-uv-y");
if (x != null) x.SetEnabled(enabled);
if (y != null) y.SetEnabled(enabled);
}
@@ -856,18 +856,27 @@ namespace XericUI.ShaderBake.Editor
// ── 通用绑定 ────────────────────────────────────────────
/*
* 一律按名字取元素、再按 INotifyValueChanged<T> 绑定,而不是 Q<FloatField> 之类。
* 同名的数字输入框在 2021.3 / 2022.1 分属 UnityEditor.UIElements 与 UnityEngine.UIElements,
* 按具体类型 Q 一旦落在另一侧就取不到:表现是数值永远空白,而且当时不一定有显眼报错。
*/
private void BindFloat(string name, Func<float> get, Action<float> set)
{
FloatField field = rootVisualElement.Q<FloatField>(name);
if (field == null)
VisualElement field = rootVisualElement.Q<VisualElement>(name);
var target = field as INotifyValueChanged<float>;
if (target == null)
{
Debug.LogError("[ShaderBake] UXML 里缺控件 " + name);
Debug.LogError("[ShaderBake] UXML 里缺数值控件 " + name);
return;
}
// 延迟提交:一边打字一边回写会把光标和"0."这类中间输入搅乱,等回车/失焦再收
field.isDelayed = true;
m_Syncers.Add(() => field.SetValueWithoutNotify(get()));
field.RegisterValueChangedCallback(evt =>
var delayedTarget = field as TextInputBaseField<float>;
if (delayedTarget != null)
delayedTarget.isDelayed = true;
m_Syncers.Add(() => target.SetValueWithoutNotify(get()));
field.RegisterCallback<ChangeEvent<float>>(evt =>
{
set(evt.newValue);
Commit();
@@ -876,15 +885,18 @@ namespace XericUI.ShaderBake.Editor
private void BindInt(string name, Func<int> get, Action<int> set)
{
IntegerField field = rootVisualElement.Q<IntegerField>(name);
if (field == null)
VisualElement field = rootVisualElement.Q<VisualElement>(name);
var target = field as INotifyValueChanged<int>;
if (target == null)
{
Debug.LogError("[ShaderBake] UXML 里缺控件 " + name);
Debug.LogError("[ShaderBake] UXML 里缺整数控件 " + name);
return;
}
field.isDelayed = true;
m_Syncers.Add(() => field.SetValueWithoutNotify(get()));
field.RegisterValueChangedCallback(evt =>
var delayedTarget = field as TextInputBaseField<int>;
if (delayedTarget != null)
delayedTarget.isDelayed = true;
m_Syncers.Add(() => target.SetValueWithoutNotify(get()));
field.RegisterCallback<ChangeEvent<int>>(evt =>
{
set(evt.newValue);
Commit();
@@ -893,14 +905,15 @@ namespace XericUI.ShaderBake.Editor
private void BindBool(string name, Func<bool> get, Action<bool> set)
{
Toggle field = rootVisualElement.Q<Toggle>(name);
if (field == null)
VisualElement field = rootVisualElement.Q<VisualElement>(name);
var target = field as INotifyValueChanged<bool>;
if (target == null)
{
Debug.LogError("[ShaderBake] UXML 里缺控件 " + name);
Debug.LogError("[ShaderBake] UXML 里缺开关 " + name);
return;
}
m_Syncers.Add(() => field.SetValueWithoutNotify(get()));
field.RegisterValueChangedCallback(evt =>
m_Syncers.Add(() => target.SetValueWithoutNotify(get()));
field.RegisterCallback<ChangeEvent<bool>>(evt =>
{
set(evt.newValue);
Commit();
@@ -909,14 +922,15 @@ namespace XericUI.ShaderBake.Editor
private void BindColor(string name, Func<Color> get, Action<Color> set)
{
ColorField field = rootVisualElement.Q<ColorField>(name);
if (field == null)
VisualElement field = rootVisualElement.Q<VisualElement>(name);
var target = field as INotifyValueChanged<Color>;
if (target == null)
{
Debug.LogError("[ShaderBake] UXML 里缺控件 " + name);
Debug.LogError("[ShaderBake] UXML 里缺颜色控件 " + name);
return;
}
m_Syncers.Add(() => field.SetValueWithoutNotify(get()));
field.RegisterValueChangedCallback(evt =>
m_Syncers.Add(() => target.SetValueWithoutNotify(get()));
field.RegisterCallback<ChangeEvent<Color>>(evt =>
{
set(evt.newValue);
Commit();