Unity 代码修改ProjectSettings
最近在学习URP
想在测试项目换一下管线,但是之前写了一些效果了,我也不想改。
于是就想加个切换URP的功能,实际上就是ProjectSettings修改管线
ProjectSettings其实有好几个文件,对应修改项对应处理即可。
public class SwitchURP
{[MenuItem("Tools/切换URP")]public static void SwitchURPMethod(){const string GraphicsSettingsAssetPath = "ProjectSettings/GraphicsSettings.asset";SerializedObject graphicsManager = new SerializedObject(UnityEditor.AssetDatabase.LoadAllAssetsAtPath(GraphicsSettingsAssetPath)[0]);SerializedProperty m_CustomRenderPipeline = graphicsManager.FindProperty("m_CustomRenderPipeline");if (m_CustomRenderPipeline.objectReferenceValue != null){m_CustomRenderPipeline.objectReferenceValue = null;}else{var asset = AssetDatabase.LoadAssetAtPath("Assets/Practice/URPTest/URPTest.asset");m_CustomRenderPipeline.objectReferenceValue = asset;}graphicsManager.ApplyModifiedProperties();}}
更新:
哎呀,菜了菜了。
GraphicsSettings.renderPipelineAsset就可以直接设置,其他Settings也差不多。不行再用上面的方法。
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
