当前位置:网站首页>Adding rendererdata of URP with script
Adding rendererdata of URP with script
2022-06-10 18:06:00 【Edward. W】
I have encountered some strange problems recently .
stay Unity In the rendering pipeline of , Need to give URP Of RenderPipeline Asset Add a little more RenderererData, This is also custom Render Feature And the way of rendering . The specific implementation method is also very simple , Get ready RendererData after , Just... Again Unity Of UI Click the plus sign on the . As shown in the figure below :

But in fact, there are always such needs . This time, you need to dynamically add this... Through scripts Renderer List. We go through URP You can see , This variable is not accessible , There is no corresponding method .

It makes sense that such an interface should be provided by URP Expose yourself , But it's not . But since it is a serializable variable , Probability can be operated in a legal way , But I'm not going to let you visit , So we can only add it by reflection .
Go straight to the code :
var proInfo = typeof(UniversalRenderPipelineAsset).GetField("m_RendererDataList",
BindingFlags.NonPublic | BindingFlags.Instance);
if (proInfo != null)
{
rendererDataList = (ScriptableRendererData[])proInfo.GetValue(UniversalRenderPipeline.asset);
var newList = new ScriptableRendererData[rendererDataList.Length+1];
for (int i = 0; i < rendererDataList.Length; i++)
{
newList[i] = rendererDataList[i];
newList[rendererDataList.Length] = newRendererData;
}
proInfo.SetValue(GraphicsSettings.currentRenderPipeline, newList);
}First, get the corresponding through reflection Field, Then force the conversion to the corresponding rendererDataList, At this point, you can get the whole list .
But there's a problem , If we directly modify List, In fact, it will not take effect , Because the rendererDataList Just one of our variables , The location pointed to is the real list , If we go straight :
rendererDataList = new ScriptableRendererData[10];
In this case, it is equivalent to a new new A variable , It can't be changed PipeLine Asset The list inside . therefore , Here you also need to use SetValue Method to put the new value back into effect .
therefore , The method in the code is new One ScriptableRendererData Array , First, insert the contents of the obtained list , And then put the customized RendererData To the end . Reuse SetValue Method to update the corresponding asset.
Measured at Editor and Runtime Can take effect .
边栏推荐
猜你喜欢

Flutter在数字生活的发展与天翼云盘落地实践

Abbexa 1,3-二棕榈素 CLIA 试剂盒解决方案

2022 version of idea graphical interface GUI garbled code solution super detailed simple version

Swin_Transformer源码解读

掌握高性能计算前,我们先了解一下它的历史

红色垂直左侧边菜单导航代码

There is an urgent need to enrich the smart home product line. Can fluorite be crowded on the sweeping robot track?

ZigBee模块无线传输星形拓扑组网结构简介

PCA principal component analysis tutorial (origin analysis & drawing, without R language)

Numpy - record
随机推荐
Can the "no password era" that apple is looking forward to really come true?
美学心得(第二百三十七集) 罗国正
Abbexa CDAN1 siRNA使用说明书
The short ticket hypothesis: finding sparse, trainable neural networks
Open source project PM how to design official website
LeetCode 255. 验证前序遍历序列二叉搜索树*
Mapbox GL development tutorial (11): loading line layers
企鹅电竞停步,虎牙也难行
CUDA编程(一):实现两个数组相加
Swin_Transformer源码解读
Noise line h5js effect realized by canvas
protoc-gen-go-grpc‘不是内部或外部命令,也不是可运行的程序 或批处理文件
Record of cmake and GCC installation
The relationship between trees, forests and binary trees
PMP考生,深圳2022年6月PMP考试地点有这些
well! One new star, please look over | elder martial brother and elder martial sister say
系统需要把所有文件扫描一遍,并尝试识别视频的封面
The latest good article | interpretable confrontation defense based on causal inference
图像搜索是什么
Solve the problem that vs2022 slowly loads a pile of symbols when debugging the program