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();
+24
View File
@@ -127,6 +127,7 @@
}
.detail-pane > .unity-scroll-view__content-container {
width: 100%;
flex-shrink: 0;
}
@@ -167,9 +168,14 @@
min-width: 0;
}
/*
* flex-basis: 0 是关键:默认 auto 会按内容宽度(标题 + 输入框)定基宽,
* 一行两栏/三栏加起来必然超过侧栏宽度,输入框被挤到可视区外——表现就是"数值文本不显示"。
*/
.field-half {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
min-width: 0;
margin-right: 4px;
}
@@ -177,6 +183,7 @@
.field-third {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
min-width: 0;
margin-right: 4px;
}
@@ -184,11 +191,28 @@
.field-quarter {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
min-width: 0;
margin-right: 3px;
font-size: 10px;
}
/* 2021.3 的字段标题默认吃 120px 左右,窄栏里会把输入区压没;侧栏内统一收窄 */
.detail-content .unity-base-field__label,
.detail-content .unity-text-field__label,
.detail-content .unity-base-text-field__label {
min-width: 30px;
flex-shrink: 1;
overflow: hidden;
}
.detail-content .unity-base-field__input,
.detail-content .unity-text-field__input,
.detail-content .unity-base-text-field__input {
flex-shrink: 1;
min-width: 0;
}
/* ── 浏览图里的选中面片高亮 ── */
.face-overlay {
position: absolute;
+6 -6
View File
@@ -86,9 +86,9 @@
</ui:VisualElement>
<xer:IntegerField name="out-pass" label="Pass 下标" class="field-full" />
<x:ColorField name="out-clear" label="背景色" class="field-full" />
<ui:Toggle name="out-hdr" label="HDR(浮点目标)" class="field-toggle" />
<ui:Toggle name="out-hdr" label="HDR" class="field-toggle" />
<ui:Toggle name="out-srgb" label="sRGB 存储" class="field-toggle" />
<ui:Toggle name="out-flip" label="上下翻转(读回方向不对时开)" class="field-toggle" />
<ui:Toggle name="out-flip" label="翻转 Y" class="field-toggle" />
</ui:VisualElement>
</ui:VisualElement>
@@ -102,8 +102,8 @@
<xer:FloatField name="surf-size-y" label="高" class="field-half" />
</ui:VisualElement>
<ui:VisualElement class="field-row">
<xer:IntegerField name="surf-seg-x" label="面内细分列" class="field-half" />
<xer:IntegerField name="surf-seg-y" label="面内细分行" class="field-half" />
<xer:IntegerField name="surf-seg-x" label="细分X" class="field-half" />
<xer:IntegerField name="surf-seg-y" label="细分Y" class="field-half" />
</ui:VisualElement>
<ui:Label class="field-note" text="面片网格(一格一张 UV 区域,向左/下扩展编号递减)" />
@@ -152,8 +152,8 @@
<ui:Label class="field-note" text="外部网格" />
<x:ObjectField name="surf-mesh" label="网格" class="field-full" />
<xer:IntegerField name="surf-submesh" label="SubMesh" class="field-full" />
<ui:Toggle name="surf-normalize" label="缩放到面片尺寸" class="field-toggle" />
<ui:Toggle name="surf-uv-st" label="UV 再写进 _MainTex_ST" class="field-toggle" />
<ui:Toggle name="surf-normalize" label="适配尺寸" class="field-toggle" />
<ui:Toggle name="surf-uv-st" label="写 _MainTex_ST" class="field-toggle" />
<ui:VisualElement class="field-row">
<ui:Button name="surf-reset" text="面片归位" class="field-half" />
<ui:Button name="surf-pick-scene" text="取选中物体" class="field-half" />