【发布时间】:2022-12-14 23:42:28
【问题描述】:
我正在尝试更改 URP 中后处理堆栈的颜色查找模块的纹理和贡献。
最初我尝试像这样简单地修改值:
private void SetTheme(int index)
{
if (index > 0 && ThemeColorLookups.Length > index)
{
if (_globalVolume.profile.TryGet(out ColorLookup cl))
{
cl.texture = new TextureParameter(ThemeColorLookups[index], true);
}
}
else
{
if (_globalVolume.profile.TryGet(out ColorLookup cl))
{
cl.texture = new TextureParameter(null, true);
}
}
}
private void SetThemeIntensity(int value)
{
if (_globalVolume.profile.TryGet(out ColorLookup cl))
{
cl.contribution = new ClampedFloatParameter(value / 100f, 0, 1, true);
}
}
这确实在编辑器中检查音量时更改了值,但是在游戏或场景视图中没有反映任何更改。
我还尝试用一个新实例完全交换 Color Lookup 实例,这或多或少导致了与前一种方法相同的行为。
private int _currentThemeIndex;
private float _currentThemeIntensity;
private void SetTheme(int index)
{
if (index > 0 && ThemeColorLookups.Length > index)
{
_globalVolume.profile.Remove<ColorLookup>();
var cl = _globalVolume.profile.Add<ColorLookup>();
cl.contribution = new ClampedFloatParameter(_currentThemeIntensity, 0, 1, true);
cl.texture = new TextureParameter(ThemeColorLookups[index], true);
_currentThemeIndex = index;
}
else
{
_currentThemeIndex = 0;
_globalVolume.profile.Remove<ColorLookup>();
}
}
private void SetThemeIntensity(int value)
{
_currentThemeIntensity = value / 100f;
if (_currentThemeIndex == 0) { return; }
_globalVolume.profile.Remove<ColorLookup>();
var cl = _globalVolume.profile.Add<ColorLookup>();
cl.contribution = new ClampedFloatParameter(value/100f, 0, 1, true);
cl.texture = new TextureParameter(ThemeColorLookups[_currentThemeIndex], true);
}
为什么变化没有反映在时间上?如果我在运行时手动修改值,则会显示正确的纹理和贡献,但是对代码执行“相同”只会产生编辑器更改。
值得注意的是,在执行这段代码后,每当您拖动 UI 滑块时都会发生这种情况,即使我尝试通过编辑器手动修改值,也没有任何反应(显然检查器更新除外)。所以在我重放场景之前,它基本上会变砖。此时我可以再次手动修改这些值,但在我的情况下这是不可取的。我想通过代码完全控制 2 个暴露的属性。
Unity 版本 - 2021.2.19f1 使用 URP
【问题讨论】:
标签: c# unity3d graphics post-processing urp